@@ -18,11 +18,11 @@ discard block |
||
| 18 | 18 | * @param string $filepath The path of the PHP config file |
| 19 | 19 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
| 20 | 20 | */ |
| 21 | - public static function loadPHP($filepath,$prefix_path=null){ |
|
| 21 | + public static function loadPHP($filepath, $prefix_path = null) { |
|
| 22 | 22 | ob_start(); |
| 23 | 23 | $results = include($filepath); |
| 24 | 24 | ob_end_clean(); |
| 25 | - if($results) static::loadArray($results,$prefix_path); |
|
| 25 | + if ($results) static::loadArray($results, $prefix_path); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -30,9 +30,9 @@ discard block |
||
| 30 | 30 | * @param string $filepath The path of the INI config file |
| 31 | 31 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
| 32 | 32 | */ |
| 33 | - public static function loadINI($filepath,$prefix_path=null){ |
|
| 34 | - $results = parse_ini_file($filepath,true); |
|
| 35 | - if($results) static::loadArray($results,$prefix_path); |
|
| 33 | + public static function loadINI($filepath, $prefix_path = null) { |
|
| 34 | + $results = parse_ini_file($filepath, true); |
|
| 35 | + if ($results) static::loadArray($results, $prefix_path); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -40,10 +40,10 @@ discard block |
||
| 40 | 40 | * @param string $filepath The path of the JSON config file |
| 41 | 41 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
| 42 | 42 | */ |
| 43 | - public static function loadJSON($filepath,$prefix_path=null){ |
|
| 43 | + public static function loadJSON($filepath, $prefix_path = null) { |
|
| 44 | 44 | $data = file_get_contents($filepath); |
| 45 | - $results = $data?json_decode($data,true):[]; |
|
| 46 | - if($results) static::loadArray($results,$prefix_path); |
|
| 45 | + $results = $data ? json_decode($data, true) : []; |
|
| 46 | + if ($results) static::loadArray($results, $prefix_path); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -51,10 +51,10 @@ discard block |
||
| 51 | 51 | * @param array $array The array to load |
| 52 | 52 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
| 53 | 53 | */ |
| 54 | - public static function loadArray(array $array,$prefix_path=null){ |
|
| 54 | + public static function loadArray(array $array, $prefix_path = null) { |
|
| 55 | 55 | if (is_array($array)) { |
| 56 | - if ($prefix_path){ |
|
| 57 | - static::set($prefix_path,$array); |
|
| 56 | + if ($prefix_path) { |
|
| 57 | + static::set($prefix_path, $array); |
|
| 58 | 58 | } else { |
| 59 | 59 | static::merge($array); |
| 60 | 60 | } |
@@ -67,22 +67,22 @@ discard block |
||
| 67 | 67 | * @param string $envname The filename for the ENV file (Default to `.env`) |
| 68 | 68 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
| 69 | 69 | */ |
| 70 | - public static function loadENV($dir,$envname='.env',$prefix_path=null){ |
|
| 71 | - $dir = rtrim($dir,'/'); |
|
| 70 | + public static function loadENV($dir, $envname = '.env', $prefix_path = null) { |
|
| 71 | + $dir = rtrim($dir, '/'); |
|
| 72 | 72 | $results = []; |
| 73 | - foreach(file("$dir/$envname", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line){ |
|
| 73 | + foreach (file("$dir/$envname", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) { |
|
| 74 | 74 | $line = trim($line); |
| 75 | - if ($line[0]=='#' || strpos($line,'=')===false) continue; |
|
| 76 | - list($key,$value) = explode('=',$line,2); |
|
| 75 | + if ($line[0] == '#' || strpos($line, '=') === false) continue; |
|
| 76 | + list($key, $value) = explode('=', $line, 2); |
|
| 77 | 77 | $key = trim(str_replace(['export ', "'", '"'], '', $key)); |
| 78 | - $value = stripslashes(trim($value,'"')); |
|
| 79 | - $results[$key] = preg_replace_callback('/\${([a-zA-Z0-9_]+)}/',function($m) use (&$results){ |
|
| 78 | + $value = stripslashes(trim($value, '"')); |
|
| 79 | + $results[$key] = preg_replace_callback('/\${([a-zA-Z0-9_]+)}/', function($m) use (&$results){ |
|
| 80 | 80 | return isset($results[$m[1]]) ? $results[$m[1]] : ''; |
| 81 | 81 | },$value); |
| 82 | 82 | putenv("$key={$results[$key]}"); |
| 83 | 83 | $_ENV[$key] = $results[$key]; |
| 84 | 84 | } |
| 85 | - if($results) static::loadArray($results,$prefix_path); |
|
| 85 | + if ($results) static::loadArray($results, $prefix_path); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | } |
@@ -18,11 +18,13 @@ discard block |
||
| 18 | 18 | * @param string $filepath The path of the PHP config file |
| 19 | 19 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
| 20 | 20 | */ |
| 21 | - public static function loadPHP($filepath,$prefix_path=null){ |
|
| 21 | + public static function loadPHP($filepath,$prefix_path=null) { |
|
| 22 | 22 | ob_start(); |
| 23 | 23 | $results = include($filepath); |
| 24 | 24 | ob_end_clean(); |
| 25 | - if($results) static::loadArray($results,$prefix_path); |
|
| 25 | + if($results) { |
|
| 26 | + static::loadArray($results,$prefix_path); |
|
| 27 | + } |
|
| 26 | 28 | } |
| 27 | 29 | |
| 28 | 30 | /** |
@@ -30,9 +32,11 @@ discard block |
||
| 30 | 32 | * @param string $filepath The path of the INI config file |
| 31 | 33 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
| 32 | 34 | */ |
| 33 | - public static function loadINI($filepath,$prefix_path=null){ |
|
| 35 | + public static function loadINI($filepath,$prefix_path=null) { |
|
| 34 | 36 | $results = parse_ini_file($filepath,true); |
| 35 | - if($results) static::loadArray($results,$prefix_path); |
|
| 37 | + if($results) { |
|
| 38 | + static::loadArray($results,$prefix_path); |
|
| 39 | + } |
|
| 36 | 40 | } |
| 37 | 41 | |
| 38 | 42 | /** |
@@ -40,10 +44,12 @@ discard block |
||
| 40 | 44 | * @param string $filepath The path of the JSON config file |
| 41 | 45 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
| 42 | 46 | */ |
| 43 | - public static function loadJSON($filepath,$prefix_path=null){ |
|
| 47 | + public static function loadJSON($filepath,$prefix_path=null) { |
|
| 44 | 48 | $data = file_get_contents($filepath); |
| 45 | 49 | $results = $data?json_decode($data,true):[]; |
| 46 | - if($results) static::loadArray($results,$prefix_path); |
|
| 50 | + if($results) { |
|
| 51 | + static::loadArray($results,$prefix_path); |
|
| 52 | + } |
|
| 47 | 53 | } |
| 48 | 54 | |
| 49 | 55 | /** |
@@ -51,9 +57,9 @@ discard block |
||
| 51 | 57 | * @param array $array The array to load |
| 52 | 58 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
| 53 | 59 | */ |
| 54 | - public static function loadArray(array $array,$prefix_path=null){ |
|
| 60 | + public static function loadArray(array $array,$prefix_path=null) { |
|
| 55 | 61 | if (is_array($array)) { |
| 56 | - if ($prefix_path){ |
|
| 62 | + if ($prefix_path) { |
|
| 57 | 63 | static::set($prefix_path,$array); |
| 58 | 64 | } else { |
| 59 | 65 | static::merge($array); |
@@ -67,22 +73,26 @@ discard block |
||
| 67 | 73 | * @param string $envname The filename for the ENV file (Default to `.env`) |
| 68 | 74 | * @param string $prefix_path You can insert/update the loaded array to a specific key path, if omitted it will be merged with the whole dictionary |
| 69 | 75 | */ |
| 70 | - public static function loadENV($dir,$envname='.env',$prefix_path=null){ |
|
| 76 | + public static function loadENV($dir,$envname='.env',$prefix_path=null) { |
|
| 71 | 77 | $dir = rtrim($dir,'/'); |
| 72 | 78 | $results = []; |
| 73 | - foreach(file("$dir/$envname", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line){ |
|
| 79 | + foreach(file("$dir/$envname", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) { |
|
| 74 | 80 | $line = trim($line); |
| 75 | - if ($line[0]=='#' || strpos($line,'=')===false) continue; |
|
| 81 | + if ($line[0]=='#' || strpos($line,'=')===false) { |
|
| 82 | + continue; |
|
| 83 | + } |
|
| 76 | 84 | list($key,$value) = explode('=',$line,2); |
| 77 | 85 | $key = trim(str_replace(['export ', "'", '"'], '', $key)); |
| 78 | 86 | $value = stripslashes(trim($value,'"')); |
| 79 | - $results[$key] = preg_replace_callback('/\${([a-zA-Z0-9_]+)}/',function($m) use (&$results){ |
|
| 87 | + $results[$key] = preg_replace_callback('/\${([a-zA-Z0-9_]+)}/',function($m) use (&$results) { |
|
| 80 | 88 | return isset($results[$m[1]]) ? $results[$m[1]] : ''; |
| 81 | 89 | },$value); |
| 82 | 90 | putenv("$key={$results[$key]}"); |
| 83 | 91 | $_ENV[$key] = $results[$key]; |
| 84 | 92 | } |
| 85 | - if($results) static::loadArray($results,$prefix_path); |
|
| 93 | + if($results) { |
|
| 94 | + static::loadArray($results,$prefix_path); |
|
| 95 | + } |
|
| 86 | 96 | } |
| 87 | 97 | |
| 88 | 98 | } |