@@ -40,11 +40,11 @@ |
||
| 40 | 40 | $exstr = ''; |
| 41 | 41 | foreach ($array as $key => $value) { |
| 42 | 42 | $line = ''; |
| 43 | - $current=$arrname."['".addslashes($key)."']"; |
|
| 43 | + $current = $arrname."['".addslashes($key)."']"; |
|
| 44 | 44 | if (is_array($value)) { |
| 45 | 45 | $line .= self::parserArraySub($current, $value); |
| 46 | 46 | } else { |
| 47 | - $line = $current; |
|
| 47 | + $line = $current; |
|
| 48 | 48 | if (is_string($value)) { |
| 49 | 49 | $line .= "='".addslashes($value).'\';'.PHP_EOL; |
| 50 | 50 | } elseif (is_bool($value)) { |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @param mixed $def |
| 88 | 88 | * @return array 设置后的数组 |
| 89 | 89 | */ |
| 90 | - public static function set(array &$array, string $name, $value, $def=null):array |
|
| 90 | + public static function set(array &$array, string $name, $value, $def = null):array |
|
| 91 | 91 | { |
| 92 | 92 | $path = explode('.', $name); |
| 93 | 93 | $root = &$array; |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | $array[$key] = []; |
| 99 | 99 | } |
| 100 | 100 | } else { |
| 101 | - $array=[]; |
|
| 101 | + $array = []; |
|
| 102 | 102 | } |
| 103 | 103 | $array = &$array[$key]; |
| 104 | 104 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | $array[$key] = []; |
| 122 | 122 | } |
| 123 | 123 | } else { |
| 124 | - $array=[]; |
|
| 124 | + $array = []; |
|
| 125 | 125 | } |
| 126 | 126 | $array = &$array[$key]; |
| 127 | 127 | } |
@@ -45,13 +45,13 @@ |
||
| 45 | 45 | |
| 46 | 46 | protected static function parseValue(string $content, array $extra = []):string |
| 47 | 47 | { |
| 48 | - return preg_replace_callback('/\$\{(.+?)\}/', function ($matchs) use ($extra) { |
|
| 48 | + return preg_replace_callback('/\$\{(.+?)\}/', function($matchs) use ($extra) { |
|
| 49 | 49 | $name = $matchs[1]; |
| 50 | 50 | if (($value = ArrayDotAccess::get($extra, $name, null)) !== null) { |
| 51 | 51 | } elseif (defined($name)) { |
| 52 | 52 | $value = constant($name); |
| 53 | 53 | } |
| 54 | - return is_string($value)?trim(json_encode($value), '"'):$value; |
|
| 54 | + return is_string($value) ?trim(json_encode($value), '"') : $value; |
|
| 55 | 55 | }, $content); |
| 56 | 56 | } |
| 57 | 57 | } |
@@ -7,17 +7,17 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | class PathResolver |
| 9 | 9 | { |
| 10 | - public static function resolve(string $path):?string |
|
| 10 | + public static function resolve(string $path): ?string |
|
| 11 | 11 | { |
| 12 | 12 | if (file_exists($path)) { |
| 13 | 13 | return $path; |
| 14 | 14 | } |
| 15 | 15 | $basepath = dirname($path).'/'.pathinfo($path, PATHINFO_FILENAME); |
| 16 | 16 | |
| 17 | - return static::resolveYaml($basepath) ?? static::resolveExtensions($basepath, ['json','php','ini']); |
|
| 17 | + return static::resolveYaml($basepath) ?? static::resolveExtensions($basepath, ['json', 'php', 'ini']); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - protected static function resolveYaml(string $basepath):?string |
|
| 20 | + protected static function resolveYaml(string $basepath): ?string |
|
| 21 | 21 | { |
| 22 | 22 | if (file_exists($conf = $basepath.'.yml') || file_exists($conf = $basepath.'.yaml')) { |
| 23 | 23 | if (function_exists('yaml_parse') || class_exists('Spyc')) { |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | return null; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - protected static function resolveExtensions(string $basepath, array $extensions):?string |
|
| 30 | + protected static function resolveExtensions(string $basepath, array $extensions): ?string |
|
| 31 | 31 | { |
| 32 | 32 | foreach ($extensions as $ext) { |
| 33 | 33 | if (file_exists($conf = $basepath.'.'.$ext)) { |
@@ -88,14 +88,14 @@ |
||
| 88 | 88 | return ArrayDotAccess::exist($this->config, $name); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - public function loadConfig(string $path, array $extra = []):?array |
|
| 91 | + public function loadConfig(string $path, array $extra = []): ?array |
|
| 92 | 92 | { |
| 93 | 93 | if (!file_exists($path)) { |
| 94 | 94 | $path = PathResolver::resolve($path); |
| 95 | 95 | } |
| 96 | 96 | if ($path) { |
| 97 | 97 | $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION)); |
| 98 | - if (in_array($ext, ['yaml','yml','json','php','ini'])) { |
|
| 98 | + if (in_array($ext, ['yaml', 'yml', 'json', 'php', 'ini'])) { |
|
| 99 | 99 | return ContentLoader::{'load'.ucfirst($ext)}($path, $extra); |
| 100 | 100 | } |
| 101 | 101 | return ContentLoader::loadJson($path, $extra); |