@@ -20,9 +20,9 @@ |
||
20 | 20 | } |
21 | 21 | } |
22 | 22 | |
23 | -require_once NEBULA_SYSTEM .'/src/component/loader/Path.php'; |
|
24 | -require_once NEBULA_SYSTEM .'/src/component/loader/PathTrait.php'; |
|
25 | -require_once NEBULA_SYSTEM .'/src/component/loader/PathInterface.php'; |
|
26 | -require_once NEBULA_SYSTEM .'/src/component/loader/IncludeManager.php'; |
|
27 | -require_once NEBULA_SYSTEM .'/src/component/loader/Loader.php'; |
|
28 | -require_once NEBULA_SYSTEM .'/src/application/Loader.php'; |
|
23 | +require_once NEBULA_SYSTEM.'/src/component/loader/Path.php'; |
|
24 | +require_once NEBULA_SYSTEM.'/src/component/loader/PathTrait.php'; |
|
25 | +require_once NEBULA_SYSTEM.'/src/component/loader/PathInterface.php'; |
|
26 | +require_once NEBULA_SYSTEM.'/src/component/loader/IncludeManager.php'; |
|
27 | +require_once NEBULA_SYSTEM.'/src/component/loader/Loader.php'; |
|
28 | +require_once NEBULA_SYSTEM.'/src/application/Loader.php'; |
@@ -32,19 +32,19 @@ discard block |
||
32 | 32 | * @param int $expire 过期时间 |
33 | 33 | * @return bool |
34 | 34 | */ |
35 | - public function set(string $name, $value, int $expire=null):bool |
|
35 | + public function set(string $name, $value, int $expire = null):bool |
|
36 | 36 | { |
37 | 37 | if ($this->disable()) { |
38 | 38 | return false; |
39 | 39 | } |
40 | - $path=$this->getPath($name); |
|
41 | - $this->value[$name]=$value; |
|
40 | + $path = $this->getPath($name); |
|
41 | + $this->value[$name] = $value; |
|
42 | 42 | FileSystem::makes(dirname($path)); |
43 | - $value=serialize($value); |
|
43 | + $value = serialize($value); |
|
44 | 44 | if (is_null($expire)) { |
45 | - $expire=time() + $this->defaultLiveTime; |
|
45 | + $expire = time() + $this->defaultLiveTime; |
|
46 | 46 | } |
47 | - return file_put_contents($path, $expire.'|'.$value)!==false; |
|
47 | + return file_put_contents($path, $expire.'|'.$value) !== false; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -52,19 +52,19 @@ discard block |
||
52 | 52 | * @param string $name 名 |
53 | 53 | * @return mixed|null |
54 | 54 | */ |
55 | - public function get(string $name, $defalut=null) |
|
55 | + public function get(string $name, $defalut = null) |
|
56 | 56 | { |
57 | 57 | // 有值就获取值 |
58 | 58 | if (array_key_exists($name, $this->value)) { |
59 | - $value=$this->value[$name]; |
|
59 | + $value = $this->value[$name]; |
|
60 | 60 | return $value; |
61 | 61 | } |
62 | 62 | // 没值就在cache文件中查找 |
63 | - $path=$this->getPath($name); |
|
63 | + $path = $this->getPath($name); |
|
64 | 64 | if (FileSystem::exist($path)) { |
65 | - $value=FileSystem::get($path); |
|
66 | - list($time, $value)=explode('|', $value, 2); |
|
67 | - if (time()<intval($time)) { |
|
65 | + $value = FileSystem::get($path); |
|
66 | + list($time, $value) = explode('|', $value, 2); |
|
67 | + if (time() < intval($time)) { |
|
68 | 68 | // 未过期则返回 |
69 | 69 | return unserialize($value); |
70 | 70 | } else { |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function has(string $name):bool |
97 | 97 | { |
98 | - return $this->get($name)!==null; |
|
98 | + return $this->get($name) !== null; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function gc() |
105 | 105 | { |
106 | - $files=FileSystem::readFiles($this->path, true); |
|
106 | + $files = FileSystem::readFiles($this->path, true); |
|
107 | 107 | foreach ($files as $file) { |
108 | - $value=FileSystem::get($file); |
|
109 | - list($time, $value)=explode('|', $value, 2); |
|
110 | - if (time()>intval($time)) { |
|
108 | + $value = FileSystem::get($file); |
|
109 | + list($time, $value) = explode('|', $value, 2); |
|
110 | + if (time() > intval($time)) { |
|
111 | 111 | FileSystem::delete($file); |
112 | 112 | } |
113 | 113 | } |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | private function getPath(string $name) |
132 | 132 | { |
133 | 133 | if (strpos($name, '.')) { |
134 | - list($main, $sub)=explode('.', $name, 2); |
|
134 | + list($main, $sub) = explode('.', $name, 2); |
|
135 | 135 | } else { |
136 | - $main=$name; |
|
137 | - $sub=$name; |
|
136 | + $main = $name; |
|
137 | + $sub = $name; |
|
138 | 138 | } |
139 | - $fname= $this->path.'/'.$main.'/'.substr(md5($sub), 0, 4).'.cache'; |
|
139 | + $fname = $this->path.'/'.$main.'/'.substr(md5($sub), 0, 4).'.cache'; |
|
140 | 140 | return $fname; |
141 | 141 | } |
142 | 142 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param RouteMatcher[] $collection |
25 | 25 | */ |
26 | - public function __construct(array $collection=[]) |
|
26 | + public function __construct(array $collection = []) |
|
27 | 27 | { |
28 | 28 | $this->mergeArray($collection); |
29 | 29 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @param array $collection |
35 | 35 | * @return void |
36 | 36 | */ |
37 | - public function mergeArray(array $collection=[]) |
|
37 | + public function mergeArray(array $collection = []) |
|
38 | 38 | { |
39 | 39 | $this->collection = array_merge($this->collection, $collection); |
40 | 40 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @param string $name |
69 | 69 | * @return RouteMatcher|null |
70 | 70 | */ |
71 | - public function get(string $name):?RouteMatcher |
|
71 | + public function get(string $name): ?RouteMatcher |
|
72 | 72 | { |
73 | 73 | return $this->collection[$name] ?? null; |
74 | 74 | } |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | $rpos = \strrpos($name, ':'); |
56 | 56 | if ($rpos > 0) { |
57 | 57 | $module = substr($name, 0, $rpos); |
58 | - $name = \substr($name, $rpos+1); |
|
59 | - $moduleFull = $this->getFullName($module); |
|
58 | + $name = \substr($name, $rpos + 1); |
|
59 | + $moduleFull = $this->getFullName($module); |
|
60 | 60 | return [$moduleFull, $name]; |
61 | 61 | } |
62 | 62 | if ($rpos === 0) { |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | if (\array_key_exists($version, $this->knownsFullName[$name])) { |
78 | 78 | return $this->knownsFullName[$name][$version]; |
79 | 79 | } |
80 | - return $hasVersion?$name.':'.$version:end($this->knownsFullName[$name]); |
|
80 | + return $hasVersion ? $name.':'.$version : end($this->knownsFullName[$name]); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | protected function getLikeName(string $name):string |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | $this->config = $config; |
21 | 21 | } |
22 | 22 | |
23 | - public function load(string $path, array $extra =[]) |
|
23 | + public function load(string $path, array $extra = []) |
|
24 | 24 | { |
25 | 25 | $data = $this->loadConfig($path, $extra); |
26 | 26 | if ($data) { |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | |
36 | 36 | public function assign(array $config) |
37 | 37 | { |
38 | - return $this->config=array_merge($this->config, $config); |
|
38 | + return $this->config = array_merge($this->config, $config); |
|
39 | 39 | } |
40 | 40 | |
41 | - public function get(string $name=null, $default=null) |
|
41 | + public function get(string $name = null, $default = null) |
|
42 | 42 | { |
43 | 43 | if (is_null($name)) { |
44 | 44 | return $this->config; |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | return ArrayDotAccess::get($this->config, $name, $default); |
47 | 47 | } |
48 | 48 | |
49 | - public function set(string $name, $value, $combine=null) |
|
49 | + public function set(string $name, $value, $combine = null) |
|
50 | 50 | { |
51 | 51 | return ArrayDotAccess::set($this->config, $name, $value, $combine); |
52 | 52 | } |
@@ -56,17 +56,17 @@ discard block |
||
56 | 56 | return ArrayDotAccess::exist($this->config, $name); |
57 | 57 | } |
58 | 58 | |
59 | - public function parseValue(string $content, array $extra =[]):string |
|
59 | + public function parseValue(string $content, array $extra = []):string |
|
60 | 60 | { |
61 | - return preg_replace_callback('/\$\{(.+?)\}/', function ($matchs) use ($extra) { |
|
61 | + return preg_replace_callback('/\$\{(.+?)\}/', function($matchs) use ($extra) { |
|
62 | 62 | $name = $matchs[1]; |
63 | - if (($value = ArrayDotAccess::get($extra, $name, null))!==null) { |
|
63 | + if (($value = ArrayDotAccess::get($extra, $name, null)) !== null) { |
|
64 | 64 | } elseif (defined($name)) { |
65 | 65 | $value = constant($name); |
66 | 66 | } else { |
67 | 67 | $value = $this->get($name, $matchs[0]); |
68 | 68 | } |
69 | - return is_string($value)?trim(json_encode($value), '"'):$value; |
|
69 | + return is_string($value) ?trim(json_encode($value), '"') : $value; |
|
70 | 70 | }, $content); |
71 | 71 | } |
72 | 72 | } |
@@ -9,9 +9,9 @@ discard block |
||
9 | 9 | */ |
10 | 10 | abstract class ConfigLoader |
11 | 11 | { |
12 | - public function loadConfig(string $path, array $extra =[]):?array |
|
12 | + public function loadConfig(string $path, array $extra = []): ?array |
|
13 | 13 | { |
14 | - $data=null; |
|
14 | + $data = null; |
|
15 | 15 | if (!file_exists($path)) { |
16 | 16 | $path = static::resolve($path); |
17 | 17 | } |
@@ -27,25 +27,25 @@ discard block |
||
27 | 27 | return $data; |
28 | 28 | } |
29 | 29 | |
30 | - protected function loadJson(string $path, array $extra =[]):array |
|
30 | + protected function loadJson(string $path, array $extra = []):array |
|
31 | 31 | { |
32 | 32 | $content = file_get_contents($path); |
33 | - $content =$this->parseValue($content, $extra); |
|
33 | + $content = $this->parseValue($content, $extra); |
|
34 | 34 | $data = json_decode($content, true); |
35 | - if (json_last_error()!==JSON_ERROR_NONE) { |
|
35 | + if (json_last_error() !== JSON_ERROR_NONE) { |
|
36 | 36 | throw new JSONException(json_last_error()); |
37 | 37 | } |
38 | 38 | return $data; |
39 | 39 | } |
40 | 40 | |
41 | - protected function loadIni(string $path, array $extra =[]):array |
|
41 | + protected function loadIni(string $path, array $extra = []):array |
|
42 | 42 | { |
43 | 43 | $content = file_get_contents($path); |
44 | - $content =$this->parseValue($content, $extra); |
|
44 | + $content = $this->parseValue($content, $extra); |
|
45 | 45 | return \parse_ini_string($content, true) ?: []; |
46 | 46 | } |
47 | 47 | |
48 | - protected function loadYaml(string $path, array $extra =[]):array |
|
48 | + protected function loadYaml(string $path, array $extra = []):array |
|
49 | 49 | { |
50 | 50 | if (function_exists('yaml_parse')) { |
51 | 51 | $name = 'yaml_parse'; |
@@ -55,25 +55,25 @@ discard block |
||
55 | 55 | throw new YamlException("parse yaml config error : missing yaml extension or spyc", 1); |
56 | 56 | } |
57 | 57 | $content = file_get_contents($path); |
58 | - $content =$this->parseValue($content, $extra); |
|
58 | + $content = $this->parseValue($content, $extra); |
|
59 | 59 | return \call_user_func_array($name, [$content]); |
60 | 60 | } |
61 | 61 | |
62 | - abstract public function parseValue(string $content, array $extra =[]):string; |
|
62 | + abstract public function parseValue(string $content, array $extra = []):string; |
|
63 | 63 | |
64 | - public static function resolve(string $path):?string |
|
64 | + public static function resolve(string $path): ?string |
|
65 | 65 | { |
66 | 66 | if (file_exists($path)) { |
67 | 67 | return $path; |
68 | 68 | } |
69 | 69 | $basepath = dirname($path).'/'.pathinfo($path, PATHINFO_FILENAME); |
70 | - if (file_exists($conf = $basepath.'.yml') || file_exists($conf = $basepath.'.yaml')) { |
|
70 | + if (file_exists($conf = $basepath.'.yml') || file_exists($conf = $basepath.'.yaml')) { |
|
71 | 71 | if (function_exists('yaml_parse') || class_exists('Spyc')) { |
72 | 72 | return $conf; |
73 | 73 | } |
74 | 74 | } |
75 | - foreach (['.json','.php','.ini'] as $ext) { |
|
76 | - if (file_exists($conf=$basepath.$ext)) { |
|
75 | + foreach (['.json', '.php', '.ini'] as $ext) { |
|
76 | + if (file_exists($conf = $basepath.$ext)) { |
|
77 | 77 | return $conf; |
78 | 78 | } |
79 | 79 | } |
@@ -42,9 +42,9 @@ |
||
42 | 42 | $extension !== 'module') { |
43 | 43 | return null; |
44 | 44 | } |
45 | - $zip=new ZipArchive; |
|
45 | + $zip = new ZipArchive; |
|
46 | 46 | if ($zip->open($path, ZipArchive::CHECKCONS)) { |
47 | - $unzipPath = $unpackPath.'/'. pathinfo($path, PATHINFO_FILENAME) .'-'.substr(md5_file($path), 0, 8); |
|
47 | + $unzipPath = $unpackPath.'/'.pathinfo($path, PATHINFO_FILENAME).'-'.substr(md5_file($path), 0, 8); |
|
48 | 48 | $zip->extractTo($unzipPath); |
49 | 49 | $zip->close(); |
50 | 50 | return Config::resolve($unzipPath.'/module'); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function add(?string $module = null, string $name, RouteMatcher $router) |
57 | 57 | { |
58 | - $module = $module ?: $this->default; |
|
58 | + $module = $module ?: $this->default; |
|
59 | 59 | if (\array_key_exists($module, $this->routes)) { |
60 | 60 | $this->routes[$module]->add($name, $router); |
61 | 61 | } else { |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | * @param string $name |
89 | 89 | * @return RouteMatcher|null |
90 | 90 | */ |
91 | - public function find(?string $module = null, string $name):?RouteMatcher |
|
91 | + public function find(?string $module = null, string $name): ?RouteMatcher |
|
92 | 92 | { |
93 | - $module = $module ?: $this->default; |
|
93 | + $module = $module ?: $this->default; |
|
94 | 94 | if (\array_key_exists($module, $this->routes)) { |
95 | 95 | return $this->routes[$module]->get($name); |
96 | 96 | } |
@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | * |
12 | 12 | * @var array |
13 | 13 | */ |
14 | - protected $attribute=[]; |
|
14 | + protected $attribute = []; |
|
15 | 15 | |
16 | - public function addAttribute(string $name , $value) |
|
16 | + public function addAttribute(string $name, $value) |
|
17 | 17 | { |
18 | 18 | $this->attribute[$name] = $value; |
19 | 19 | } |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | protected function analyse(array $context) |
22 | 22 | { |
23 | 23 | $replace = []; |
24 | - $attach =[] ; |
|
24 | + $attach = []; |
|
25 | 25 | foreach ($context as $key => $val) { |
26 | - if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString')) && ! $val instanceof \Exception) { |
|
27 | - $replace['{' . $key . '}'] = $val; |
|
26 | + if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString')) && !$val instanceof \Exception) { |
|
27 | + $replace['{'.$key.'}'] = $val; |
|
28 | 28 | } else { |
29 | 29 | $attach[$key] = $val; |
30 | 30 | } |
@@ -34,19 +34,19 @@ discard block |
||
34 | 34 | |
35 | 35 | public function interpolate(string $message, array $context, array $attribute) |
36 | 36 | { |
37 | - list($attach, $replace) = $this->analyse($context); |
|
37 | + list($attach, $replace) = $this->analyse($context); |
|
38 | 38 | $attribute = array_merge($this->attribute, $attribute); |
39 | 39 | foreach ($attribute as $key => $val) { |
40 | - $replace['%' . $key . '%'] = $val; |
|
40 | + $replace['%'.$key.'%'] = $val; |
|
41 | 41 | } |
42 | 42 | $message = strtr($message, $replace); |
43 | 43 | $attachInfo = ''; |
44 | 44 | foreach ($attach as $name => $value) { |
45 | 45 | $attachInfo = $name.' = '; |
46 | 46 | if ($value instanceof AttachValueInterface) { |
47 | - $attachInfo.= $value->getLogAttach().PHP_EOL; |
|
47 | + $attachInfo .= $value->getLogAttach().PHP_EOL; |
|
48 | 48 | } else { |
49 | - $attachInfo.= DumpTrait::parameterToString($value).PHP_EOL; |
|
49 | + $attachInfo .= DumpTrait::parameterToString($value).PHP_EOL; |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | if (strlen($attachInfo) > 0) { |