File tree Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ public static function getUserHomeDir(bool $refresh = false): string
5454 return self ::$ homeDir ;
5555 }
5656
57- if (!$ home = self ::getEnvVal ('HOME ' )) {
57+ if (!$ home = self ::getEnvStrVal ('HOME ' )) {
5858 $ isWin = self ::isWindows ();
5959
6060 // home on windows
@@ -235,15 +235,26 @@ public static function getTempDir(): string
235235 return $ tmp ;
236236 }
237237
238+ /**
239+ * @param string $key
240+ * @param string|mixed $default
241+ *
242+ * @return mixed
243+ */
244+ public static function getEnvVal (string $ key , string $ default = '' )
245+ {
246+ return getenv ($ key ) ?: ($ _SERVER [$ key ] ?? $ default );
247+ }
248+
238249 /**
239250 * @param string $key
240251 * @param string $default
241252 *
242253 * @return string
243254 */
244- public static function getEnvVal (string $ key , string $ default = '' ): string
255+ public static function getEnvStrVal (string $ key , string $ default = '' ): string
245256 {
246- return getenv ( $ key ) ?: ( string )( $ _SERVER [ $ key] ?? $ default );
257+ return ( string ) self :: getEnvVal ( $ key, $ default );
247258 }
248259
249260 /**
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ class PhpDotEnv
5656 *
5757 * @return static
5858 */
59- public static function load (string $ fileDir , string $ fileName = '.env ' )
59+ public static function load (string $ fileDir , string $ fileName = '.env ' ): self
6060 {
6161 return new self ($ fileDir , $ fileName );
6262 }
Original file line number Diff line number Diff line change @@ -113,3 +113,16 @@ function eprints(...$vars): void
113113 echo Toolkit \Stdlib \Php::exportVar (...$ vars ), PHP_EOL ;
114114 }
115115}
116+
117+ if (!function_exists ('env ' )) {
118+ /**
119+ * @param string $key
120+ * @param string $default
121+ *
122+ * @return string
123+ */
124+ function env (string $ key , string $ default = '' ): string
125+ {
126+ return Toolkit \Stdlib \OS ::getEnvStrVal ($ key , $ default );
127+ }
128+ }
You can’t perform that action at this time.
0 commit comments