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

原始数据

按行查看

历史

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值