调整env函数位置

master
李春波 2 years ago
parent 16bdeab15b
commit 7308f155ce
  1. 31
      app/functions.php
  2. 3
      composer.json
  3. 32
      support/initialization.php

@ -3,37 +3,6 @@
* Here is your custom functions.
*/
/**
* @param string $key
* @param $default
* @return array|bool|mixed|string|null
*/
function env(string $key, $default = null)
{
$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 null;
}
if (($valueLength = strlen($value)) > 1 && $value[0] === '"' && $value[$valueLength - 1] === '"') {
return substr($value, 1, -1);
}
return $value;
}
function success($data = [], $code = 0, $msg = '操作成功', $is_array = false)
{
if ($is_array) {

@ -47,7 +47,8 @@
"app\\View\\Components\\": "./app/view/components"
},
"files": [
"./support/helpers.php"
"./support/helpers.php",
"./support/initialization.php"
]
},
"scripts": {

@ -0,0 +1,32 @@
<?php
/**
* @param string $key
* @param $default
* @return array|bool|mixed|string|null
*/
function env(string $key, $default = null)
{
$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 null;
}
if (($valueLength = strlen($value)) > 1 && $value[0] === '"' && $value[$valueLength - 1] === '"') {
return substr($value, 1, -1);
}
return $value;
}
Loading…
Cancel
Save