优化代码

This commit is contained in:
2026-01-04 15:01:16 +08:00
parent e0ff5ccdc7
commit b764c708ce
10 changed files with 2885 additions and 465 deletions

View File

@@ -202,6 +202,34 @@ if (!function_exists('dump')) {
}
}
if (!function_exists('dd')) {
/**
* 浏览器友好的变量输出
* @param mixed $vars 要输出的变量
* @return void
*/
function dd(...$vars)
{
ob_start();
var_dump(...$vars);
$output = ob_get_clean();
$output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output);
if (PHP_SAPI == 'cli') {
$output = PHP_EOL . $output . PHP_EOL;
} else {
if (!extension_loaded('xdebug')) {
$output = htmlspecialchars($output, ENT_SUBSTITUTE);
}
$output = '<pre>' . $output . '</pre>';
}
echo $output;
die;
}
}
if (!function_exists('env')) {
/**
* 获取环境变量值
@@ -661,3 +689,18 @@ if (!function_exists('root_path')) {
return app()->getRootPath() . ($path ? $path . DIRECTORY_SEPARATOR : $path);
}
}
if (!function_exists('is_dev')) {
function is_dev()
{
$env = env('APP_ENV', '');
$env = strtolower($env);
if (in_array($env, ['dev', 'development', 'local', 'test'], true)) {
return true;
}
if (app()->environment('dev') || app()->environment('local') || app()->environment('test')) {
return true;
}
return false;
}
}