From 229cee91efc7a146e52016c6e7d01c81dc9f631b Mon Sep 17 00:00:00 2001 From: youfeed <11247005@qq.com> Date: Wed, 28 Feb 2024 03:41:20 +0800 Subject: [PATCH 1/2] add .env read --- support/helpers.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/support/helpers.php b/support/helpers.php index 7853f9f..8ed8ce5 100644 --- a/support/helpers.php +++ b/support/helpers.php @@ -545,3 +545,22 @@ function input(string $param = null, string $default = null) { return is_null($param) ? request()->all() : request()->input($param, $default); } +/** + * Globally available read .env configuration file returns configuration items/groups + * @param string|null $param path name + * @param void $default default value + * @return void + */ +function ini(string $param = null, string $default = null) +{ + static $config = []; + if (!$config) { + $config = @parse_ini_file(base_path().'/.env',true) ?? []; + } + if($param === null){ + return $config; + } + @[$one,$two] = explode('.', $param); + @[$one=>$item] = $config; + return ($two === null ? $item : $item[$two]) ?? $default; +} From e14592b8996a757258aa1230d4da6a00c69220e1 Mon Sep 17 00:00:00 2001 From: youfeed <11247005@qq.com> Date: Wed, 28 Feb 2024 18:03:46 +0800 Subject: [PATCH 2/2] fix bug --- support/helpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/helpers.php b/support/helpers.php index 8ed8ce5..297395a 100644 --- a/support/helpers.php +++ b/support/helpers.php @@ -562,5 +562,5 @@ function ini(string $param = null, string $default = null) } @[$one,$two] = explode('.', $param); @[$one=>$item] = $config; - return ($two === null ? $item : $item[$two]) ?? $default; + return $two === null ? ($item ?? $default) : ($item[$two] ?? $default); }