当前位置: 首页 > news >正文

helpers.php,helpers.php

/**

* 强调:此处不要出现 use 语句!

*/

if (!function_exists('env')) {

/**

* Gets the value of an environment variable.

*

* @param string $key

* @param mixed $default

* @param string $delimiter

* @return mixed

*/

function env($key, $default = null, $delimiter = '')

{

$value = getenv($key);

if ($value === false) {

return value($default);

}

switch (strtolower($value)) {

case 'true':

case '(true)':

return true;

case 'false':

case '(false)':

return false;

case 'empty':

case '(empty)':

return '';

case 'null':

case '(null)':

return;

}

if (strlen($value) > 1 && str_starts_with($value, '"') && str_ends_with($value, '"')) {

$value = substr($value, 1, -1);

}

if (strlen($delimiter) > 0) {

if(strlen($value) == 0) {

$value = $default;

} else {

$value = explode($delimiter, $value);

}

}

return $value;

}

}

if (!function_exists('value')) {

/**

* Return the default value of the given value.

*

* @param mixed $value

* @return mixed

*/

function value($value)

{

return $value instanceof Closure ? $value() : $value;

}

}

if (!function_exists('str_starts_with')) {

/**

* Determine if a given string starts with a given substring.

*

* @param string $haystack

* @param string|array $needles

* @return bool

*/

function str_starts_with($haystack, $needles)

{

foreach ((array) $needles as $needle) {

if ($needle !== '' && substr($haystack, 0, strlen($needle)) === (string) $needle) {

return true;

}

}

return false;

}

}

if (!function_exists('str_ends_with')) {

/**

* Determine if a given string ends with a given substring.

*

* @param string $haystack

* @param string|array $needles

* @return bool

*/

function str_ends_with($haystack, $needles)

{

foreach ((array) $needles as $needle) {

if (substr($haystack, -strlen($needle)) === (string) $needle) {

return true;

}

}

return false;

}

}

if (!function_exists('define_once')) {

/**

* Define a const if not exists.

*

* @param string $name

* @param mixed $value

* @return bool

*/

function define_once($name, $value = true)

{

return defined($name) or define($name, $value);

}

}

if (!function_exists('dd')) {

/**

* Dump the passed variable and end the script.

*

* @param mixed $arg

* @return void

*/

function dd($arg)

{

echo "

";

// http_response_code(500);

\yii\helpers\VarDumper::dump($arg);

die(1);

}

}

function hj_core_version()

{

static $version = null;

if ($version) {

return $version;

}

$file = __DIR__ . '/version.json';

if (!file_exists($file)) {

throw new Exception('Version not found');

}

$res = json_decode(file_get_contents($file), true);

if (!is_array($res)) {

throw new Exception('Version cannot be decoded');

}

return $version = $res['version'];

}

function hj_pdo_run($sql)

{

try {

pdo_query($sql);

return true;

} catch (Exception $e) {

return false;

}

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

相关文章:

  • python下载package失败,pip安装packag失败
  • php ieee754,在 Go 中探索 IEEE-754 标准
  • oracle+数据结构+字典,ORACLE 数据字典
  • liunx php libiconv-1.14 扩展库地址,编译安装php之安装libiconv-1.14.tar.gz出错解决方法...
  • Oracle标量子查询执行计划,性能为王:SQL标量子查询的优化案例分析
  • oracle insert和update,INSERTUPDATE和MERGE (转)
  • 有关oracle的论文,Oracle数据库研究论文有关Oracle数据库的论文
  • linux rocketmq 命令,Linux下安装RocketMQ(单Master)
  • linux 查看 文件夹代销,速达常见问题集
  • 斑马打印机linux驱动安装教程,热敏打印机安装驱动教程
  • linux串口设置1843200波特率,串口通信程序设计
  • linux安装sw软件,Linux 下安装python软件包(pip、nose、virtualenv、distribute )
  • linux绕过时间检测,使用linux的clockdiff命令检测两台linux主机的时间差
  • linux思源黑体乱码,deepin终端使用思源黑体做中文字体
  • linux保存python,python中import this 编程之禅的结果我想用一个变量保存,如何做
  • 【剑指offer】让抽象问题具体化
  • 4. 路由到控制器 - Laravel从零开始教程
  • Docker容器管理
  • echarts的各种常用效果展示
  • Eureka 2.0 开源流产,真的对你影响很大吗?
  • Github访问慢解决办法
  • Java IO学习笔记一
  • js如何打印object对象
  • Promise初体验
  • ReactNative开发常用的三方模块
  • Vue学习第二天
  • 不上全站https的网站你们就等着被恶心死吧
  • 从0到1:PostCSS 插件开发最佳实践
  • 分布式事物理论与实践
  • 快速构建spring-cloud+sleuth+rabbit+ zipkin+es+kibana+grafana日志跟踪平台
  • 利用jquery编写加法运算验证码
  • 猫头鹰的深夜翻译:JDK9 NotNullOrElse方法
  • 浅析微信支付:申请退款、退款回调接口、查询退款
  • 使用docker-compose进行多节点部署
  • 探索 JS 中的模块化
  • 职业生涯 一个六年开发经验的女程序员的心声。
  • raise 与 raise ... from 的区别
  • 东超科技获得千万级Pre-A轮融资,投资方为中科创星 ...
  • 资深实践篇 | 基于Kubernetes 1.61的Kubernetes Scheduler 调度详解 ...
  • ​ssh免密码登录设置及问题总结
  • ‌U盘闪一下就没了?‌如何有效恢复数据
  • #APPINVENTOR学习记录
  • #VERDI# 关于如何查看FSM状态机的方法
  • #我与Java虚拟机的故事#连载04:一本让自己没面子的书
  • (20050108)又读《平凡的世界》
  • (二)pulsar安装在独立的docker中,python测试
  • (一) storm的集群安装与配置
  • (转)EXC_BREAKPOINT僵尸错误
  • (转)拼包函数及网络封包的异常处理(含代码)
  • . ./ bash dash source 这五种执行shell脚本方式 区别
  • ./include/caffe/util/cudnn.hpp: In function ‘const char* cudnnGetErrorString(cudnnStatus_t)’: ./incl
  • .DFS.
  • .Net CoreRabbitMQ消息存储可靠机制
  • .net core使用RPC方式进行高效的HTTP服务访问
  • .NET/C# 将一个命令行参数字符串转换为命令行参数数组 args