@@ -10,13 +10,13 @@ |
||
10 | 10 | { |
11 | 11 | public function log($level, string $message, array $context = []) |
12 | 12 | { |
13 | - print date('Y-m-d H:i:s') .' ' . $this->interpolate($message, $context) . PHP_EOL; |
|
13 | + print date('Y-m-d H:i:s').' '.$this->interpolate($message, $context).PHP_EOL; |
|
14 | 14 | } |
15 | 15 | public function interpolate(string $message, array $context) |
16 | 16 | { |
17 | 17 | $replace = []; |
18 | 18 | foreach ($context as $key => $val) { |
19 | - $replace['{' . $key . '}'] = $val; |
|
19 | + $replace['{'.$key.'}'] = $val; |
|
20 | 20 | } |
21 | 21 | return strtr($message, $replace); |
22 | 22 | } |
@@ -9,13 +9,13 @@ |
||
9 | 9 | protected $ignorePath = [__FILE__]; |
10 | 10 | protected $backtrace; |
11 | 11 | |
12 | - public function __construct(array $backtrace, array $ignorePath =[]) |
|
12 | + public function __construct(array $backtrace, array $ignorePath = []) |
|
13 | 13 | { |
14 | 14 | $this->ignorePath = \array_merge($this->ignorePath, $ignorePath); |
15 | 15 | $this->backtrace = $backtrace; |
16 | 16 | } |
17 | 17 | |
18 | - public function getCallerTrace():?array |
|
18 | + public function getCallerTrace(): ?array |
|
19 | 19 | { |
20 | 20 | foreach ($this->backtrace as $trace) { |
21 | 21 | if (array_key_exists('file', $trace)) { |
@@ -15,14 +15,14 @@ |
||
15 | 15 | * @param int $expire 过期时间 |
16 | 16 | * @return bool |
17 | 17 | */ |
18 | - public function set(string $name, $value, int $expire=null):bool; |
|
18 | + public function set(string $name, $value, int $expire = null):bool; |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * 获取值 |
22 | 22 | * @param string $name 名 |
23 | 23 | * @return mixed|null |
24 | 24 | */ |
25 | - public function get(string $name, $defalut=null); |
|
25 | + public function get(string $name, $defalut = null); |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * 删除值 |
@@ -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 | } |
@@ -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 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | { |
29 | 29 | $path = $source; |
30 | 30 | if (Path::isRelativePath($source)) { |
31 | - $path = $relative.'/'.$path; |
|
31 | + $path = $relative.'/'.$path; |
|
32 | 32 | } |
33 | 33 | return Path::toAbsolutePath($path); |
34 | 34 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param string $path |
54 | 54 | * @return string|null |
55 | 55 | */ |
56 | - public function getResourcePath(string $path):?string |
|
56 | + public function getResourcePath(string $path): ?string |
|
57 | 57 | { |
58 | 58 | foreach ($this->resource as $root) { |
59 | 59 | $target = $root.'/'.$path; |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | * @param string $path |
71 | 71 | * @return string|null |
72 | 72 | */ |
73 | - public function getConfigResourcePath(string $path):?string |
|
73 | + public function getConfigResourcePath(string $path): ?string |
|
74 | 74 | { |
75 | 75 | foreach ($this->resource as $root) { |
76 | - if ( $target = Config::resolve($root.'/'.$path)) { |
|
76 | + if ($target = Config::resolve($root.'/'.$path)) { |
|
77 | 77 | return $target; |
78 | 78 | } |
79 | 79 | } |
@@ -162,8 +162,8 @@ |
||
162 | 162 | */ |
163 | 163 | protected function registerModuleManager() |
164 | 164 | { |
165 | - $this->manager = new Manager($this->getContext()); |
|
166 | - $this->manager->registerModule(); |
|
165 | + $this->manager = new Manager($this->getContext()); |
|
166 | + $this->manager->registerModule(); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function setStatus(int $code) |
86 | 86 | { |
87 | - $this->header->sendHeaderRaw('HTTP/1.1 '.$code.' '. Status::toText($code)); |
|
88 | - $this->header->sendHeader('Status', $code.' '. Status::toText($code)); |
|
87 | + $this->header->sendHeaderRaw('HTTP/1.1 '.$code.' '.Status::toText($code)); |
|
88 | + $this->header->sendHeader('Status', $code.' '.Status::toText($code)); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | public function render($value, string $echo = '', bool $allowEcho = true) |
141 | 141 | { |
142 | 142 | $this->header->send(); |
143 | - $wantEcho = strlen($echo) > 0 ; |
|
143 | + $wantEcho = strlen($echo) > 0; |
|
144 | 144 | $noReturn = $wantEcho && is_null($value); |
145 | 145 | if ($noReturn && $wantEcho) { |
146 | 146 | $this->send($echo); |