@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function loadFromModule(Manager $manager) |
52 | 52 | { |
53 | - $groups = $this->applicaton->getConfig()->get('app.active', ['default']); |
|
53 | + $groups = $this->applicaton->getConfig()->get('app.active', ['default']); |
|
54 | 54 | foreach ($groups as $group) { |
55 | 55 | $manager->loadRoute($group, $this); |
56 | 56 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @param Request $request |
79 | 79 | * @return MatchResult|null |
80 | 80 | */ |
81 | - public function match(Request $request):?MatchResult |
|
81 | + public function match(Request $request): ?MatchResult |
|
82 | 82 | { |
83 | 83 | foreach ($this->routes as $group => $routes) { |
84 | 84 | if (($result = $routes->match($request)) !== null) { |
@@ -4,15 +4,15 @@ |
||
4 | 4 | use nebula\application\Loader; |
5 | 5 | use nebula\application\Request; |
6 | 6 | |
7 | -require_once __DIR__ .'/loader.php'; |
|
7 | +require_once __DIR__.'/loader.php'; |
|
8 | 8 | |
9 | 9 | |
10 | 10 | |
11 | 11 | // 初始化系统加载器 |
12 | 12 | $loader = new Loader; |
13 | 13 | $loader->register(); |
14 | -$loader->addIncludePath(NEBULA_SYSTEM .'/src', 'nebula'); |
|
15 | -$loader->import(NEBULA_SYSTEM .'/src/functions.php'); |
|
14 | +$loader->addIncludePath(NEBULA_SYSTEM.'/src', 'nebula'); |
|
15 | +$loader->import(NEBULA_SYSTEM.'/src/functions.php'); |
|
16 | 16 | // 初始化请求 |
17 | 17 | $request = Request::buildFromServer(); |
18 | 18 | $request->apply(true); |
@@ -8,5 +8,5 @@ |
||
8 | 8 | */ |
9 | 9 | abstract class Response extends BaseResponse |
10 | 10 | { |
11 | - public abstract function onRequest(Request $request, Response $response); |
|
11 | + public abstract function onRequest(Request $request, Response $response); |
|
12 | 12 | } |
@@ -46,12 +46,12 @@ discard block |
||
46 | 46 | * @throws FileLoggerException |
47 | 47 | * @param array $config |
48 | 48 | */ |
49 | - public function __construct(array $config=[]) |
|
49 | + public function __construct(array $config = []) |
|
50 | 50 | { |
51 | 51 | $this->applyConfig($config); |
52 | 52 | $temp = tmpfile(); |
53 | 53 | if ($temp === false) { |
54 | - $this->tempname = $this->getConfig('save-path').'/log-'. microtime(true).'.tmp'; |
|
54 | + $this->tempname = $this->getConfig('save-path').'/log-'.microtime(true).'.tmp'; |
|
55 | 55 | $temp = fopen($this->tempname, 'w+'); |
56 | 56 | } |
57 | 57 | if ($temp !== false) { |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | throw new FileLoggerException(__CLASS__.':'.sprintf('cannot create log file')); |
61 | 61 | } |
62 | 62 | $this->latest = $this->getConfig('save-path').'/'.$this->getConfig('file-name'); |
63 | - \register_shutdown_function([$this,'save']); |
|
63 | + \register_shutdown_function([$this, 'save']); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | public function getDefaultConfig():array |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | |
79 | 79 | protected function packLogFile() |
80 | 80 | { |
81 | - $logFile= $this->latest; |
|
82 | - $path=preg_replace('/[\\\\]+/', '/', $this->getConfig('save-zip-path') .'/'.date('Y-m-d').'.zip'); |
|
81 | + $logFile = $this->latest; |
|
82 | + $path = preg_replace('/[\\\\]+/', '/', $this->getConfig('save-zip-path').'/'.date('Y-m-d').'.zip'); |
|
83 | 83 | $zip = new ZipArchive; |
84 | 84 | $res = $zip->open($path, ZipArchive::CREATE); |
85 | 85 | if ($res === true) { |
86 | - if ($zip->addFile($logFile, date('Y-m-d'). '-'. $zip->numFiles .'.log')) { |
|
86 | + if ($zip->addFile($logFile, date('Y-m-d').'-'.$zip->numFiles.'.log')) { |
|
87 | 87 | array_push($this->removeFiles, $logFile); |
88 | 88 | } |
89 | 89 | if (\is_dir($this->getConfig('save-pack-path'))) { |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | $zip->close(); |
98 | 98 | } else { |
99 | 99 | if (is_file($logFile) && file_exists($logFile)) { |
100 | - rename($logFile, $this->getConfig('save-path') . '/' . date('Y-m-d'). '-'. substr(md5_file($logFile), 0, 8).'.log'); |
|
100 | + rename($logFile, $this->getConfig('save-path').'/'.date('Y-m-d').'-'.substr(md5_file($logFile), 0, 8).'.log'); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | protected function checkSize():bool |
111 | 111 | { |
112 | - $logFile= $this->latest; |
|
112 | + $logFile = $this->latest; |
|
113 | 113 | if (file_exists($logFile)) { |
114 | 114 | if (filesize($logFile) > $this->getConfig('max-file-size')) { |
115 | 115 | return true; |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | |
122 | 122 | public function log($level, string $message, array $context = []) |
123 | 123 | { |
124 | - if (LogLevel::compare($level, $this->getConfig('log-level')) >=0) { |
|
124 | + if (LogLevel::compare($level, $this->getConfig('log-level')) >= 0) { |
|
125 | 125 | $replace = []; |
126 | 126 | $message = $this->interpolate($message, $context); |
127 | 127 | $replace['%level%'] = $level; |
@@ -134,10 +134,10 @@ discard block |
||
134 | 134 | protected function rollLatest() |
135 | 135 | { |
136 | 136 | if (isset($this->latest)) { |
137 | - $size=ftell($this->temp); |
|
137 | + $size = ftell($this->temp); |
|
138 | 138 | fseek($this->temp, 0); |
139 | 139 | if ($size > 0) { |
140 | - $body=fread($this->temp, $size); |
|
140 | + $body = fread($this->temp, $size); |
|
141 | 141 | file_put_contents($this->latest, $body, FILE_APPEND); |
142 | 142 | } |
143 | 143 | fclose($this->temp); |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | } elseif (is_null($val)) { |
175 | 175 | $val = 'null'; |
176 | 176 | } |
177 | - $replace['{' . $key . '}'] = $val; |
|
177 | + $replace['{'.$key.'}'] = $val; |
|
178 | 178 | } |
179 | 179 | return strtr($message, $replace); |
180 | 180 | } |
@@ -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); |
@@ -14,12 +14,12 @@ discard block |
||
14 | 14 | * @param string $path 目标路径 |
15 | 15 | * @return string|null 返回格式化结果,如果路径不存在则返回NULL |
16 | 16 | */ |
17 | - public static function format(string $path):?string |
|
17 | + public static function format(string $path): ?string |
|
18 | 18 | { |
19 | - return static::existCharset($path, ['GBK','GB2312','BIG5']); |
|
19 | + return static::existCharset($path, ['GBK', 'GB2312', 'BIG5']); |
|
20 | 20 | } |
21 | 21 | |
22 | - public static function existCharset(string $path, array $charset):?string |
|
22 | + public static function existCharset(string $path, array $charset): ?string |
|
23 | 23 | { |
24 | 24 | $abspath = static::toAbsolutePath($path); |
25 | 25 | if (static::existCase($abspath)) { |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @return boolean |
71 | 71 | */ |
72 | 72 | public static function isRelativePath(string $path):bool { |
73 | - $path = \str_replace('\\','/', $path); |
|
73 | + $path = \str_replace('\\', '/', $path); |
|
74 | 74 | return !(strpos($path, ':/') > 0 || strpos($path, '/') === 0); |
75 | 75 | } |
76 | 76 | } |
@@ -181,7 +181,7 @@ |
||
181 | 181 | $object = $class->getMethod('instance')->invoke(null); |
182 | 182 | $context->setResponse($object); |
183 | 183 | $class->getMethod('proccess')->invokeArgs($object, [ |
184 | - new Runnable([$object,'onRequest']), |
|
184 | + new Runnable([$object, 'onRequest']), |
|
185 | 185 | $this->getRequest($context), |
186 | 186 | $this->matcher->getAttribute('buffer', true), |
187 | 187 | $context->isDebug(), |
@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | protected $matcher; |
40 | 40 | |
41 | 41 | |
42 | - public function __construct(array $methods, string $uri, array $attribute=[]) |
|
42 | + public function __construct(array $methods, string $uri, array $attribute = []) |
|
43 | 43 | { |
44 | - array_walk($methods, function ($value) { |
|
44 | + array_walk($methods, function($value) { |
|
45 | 45 | return strtoupper($value); |
46 | 46 | }); |
47 | 47 | $this->methods = $methods; |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @param RequestInterface $request |
158 | 158 | * @return array|null |
159 | 159 | */ |
160 | - public function match(RequestInterface $request):?array |
|
160 | + public function match(RequestInterface $request): ?array |
|
161 | 161 | { |
162 | 162 | if (count($this->methods) > 0 && !\in_array($request->getMethod(), $this->methods)) { |
163 | 163 | return null; |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | public static $statusTexts = [ |
10 | 10 | 100 => 'Continue', |
11 | 11 | 101 => 'Switching Protocols', |
12 | - 102 => 'Processing', // RFC2518 |
|
12 | + 102 => 'Processing', // RFC2518 |
|
13 | 13 | 103 => 'Early Hints', |
14 | 14 | 200 => 'OK', |
15 | 15 | 201 => 'Created', |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | 204 => 'No Content', |
19 | 19 | 205 => 'Reset Content', |
20 | 20 | 206 => 'Partial Content', |
21 | - 207 => 'Multi-Status', // RFC4918 |
|
22 | - 208 => 'Already Reported', // RFC5842 |
|
23 | - 226 => 'IM Used', // RFC3229 |
|
21 | + 207 => 'Multi-Status', // RFC4918 |
|
22 | + 208 => 'Already Reported', // RFC5842 |
|
23 | + 226 => 'IM Used', // RFC3229 |
|
24 | 24 | 300 => 'Multiple Choices', |
25 | 25 | 301 => 'Moved Permanently', |
26 | 26 | 302 => 'Found', |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | 304 => 'Not Modified', |
29 | 29 | 305 => 'Use Proxy', |
30 | 30 | 307 => 'Temporary Redirect', |
31 | - 308 => 'Permanent Redirect', // RFC7238 |
|
31 | + 308 => 'Permanent Redirect', // RFC7238 |
|
32 | 32 | 400 => 'Bad Request', |
33 | 33 | 401 => 'Unauthorized', |
34 | 34 | 402 => 'Payment Required', |
@@ -47,34 +47,34 @@ discard block |
||
47 | 47 | 415 => 'Unsupported Media Type', |
48 | 48 | 416 => 'Range Not Satisfiable', |
49 | 49 | 417 => 'Expectation Failed', |
50 | - 418 => 'I\'m a teapot', // RFC2324 |
|
51 | - 421 => 'Misdirected Request', // RFC7540 |
|
52 | - 422 => 'Unprocessable Entity', // RFC4918 |
|
53 | - 423 => 'Locked', // RFC4918 |
|
54 | - 424 => 'Failed Dependency', // RFC4918 |
|
55 | - 425 => 'Too Early', // RFC-ietf-httpbis-replay-04 |
|
56 | - 426 => 'Upgrade Required', // RFC2817 |
|
57 | - 428 => 'Precondition Required', // RFC6585 |
|
58 | - 429 => 'Too Many Requests', // RFC6585 |
|
59 | - 431 => 'Request Header Fields Too Large', // RFC6585 |
|
60 | - 451 => 'Unavailable For Legal Reasons', // RFC7725 |
|
50 | + 418 => 'I\'m a teapot', // RFC2324 |
|
51 | + 421 => 'Misdirected Request', // RFC7540 |
|
52 | + 422 => 'Unprocessable Entity', // RFC4918 |
|
53 | + 423 => 'Locked', // RFC4918 |
|
54 | + 424 => 'Failed Dependency', // RFC4918 |
|
55 | + 425 => 'Too Early', // RFC-ietf-httpbis-replay-04 |
|
56 | + 426 => 'Upgrade Required', // RFC2817 |
|
57 | + 428 => 'Precondition Required', // RFC6585 |
|
58 | + 429 => 'Too Many Requests', // RFC6585 |
|
59 | + 431 => 'Request Header Fields Too Large', // RFC6585 |
|
60 | + 451 => 'Unavailable For Legal Reasons', // RFC7725 |
|
61 | 61 | 500 => 'Internal Server Error', |
62 | 62 | 501 => 'Not Implemented', |
63 | 63 | 502 => 'Bad Gateway', |
64 | 64 | 503 => 'Service Unavailable', |
65 | 65 | 504 => 'Gateway Timeout', |
66 | 66 | 505 => 'HTTP Version Not Supported', |
67 | - 506 => 'Variant Also Negotiates', // RFC2295 |
|
68 | - 507 => 'Insufficient Storage', // RFC4918 |
|
69 | - 508 => 'Loop Detected', // RFC5842 |
|
70 | - 510 => 'Not Extended', // RFC2774 |
|
71 | - 511 => 'Network Authentication Required', // RFC6585 |
|
67 | + 506 => 'Variant Also Negotiates', // RFC2295 |
|
68 | + 507 => 'Insufficient Storage', // RFC4918 |
|
69 | + 508 => 'Loop Detected', // RFC5842 |
|
70 | + 510 => 'Not Extended', // RFC2774 |
|
71 | + 511 => 'Network Authentication Required', // RFC6585 |
|
72 | 72 | ]; |
73 | 73 | |
74 | 74 | const HTTP_CONTINUE = 100; |
75 | 75 | const HTTP_SWITCHING_PROTOCOLS = 101; |
76 | - const HTTP_PROCESSING = 102; // RFC2518 |
|
77 | - const HTTP_EARLY_HINTS = 103; // RFC8297 |
|
76 | + const HTTP_PROCESSING = 102; // RFC2518 |
|
77 | + const HTTP_EARLY_HINTS = 103; // RFC8297 |
|
78 | 78 | const HTTP_OK = 200; |
79 | 79 | const HTTP_CREATED = 201; |
80 | 80 | const HTTP_ACCEPTED = 202; |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | const HTTP_NO_CONTENT = 204; |
83 | 83 | const HTTP_RESET_CONTENT = 205; |
84 | 84 | const HTTP_PARTIAL_CONTENT = 206; |
85 | - const HTTP_MULTI_STATUS = 207; // RFC4918 |
|
86 | - const HTTP_ALREADY_REPORTED = 208; // RFC5842 |
|
87 | - const HTTP_IM_USED = 226; // RFC3229 |
|
85 | + const HTTP_MULTI_STATUS = 207; // RFC4918 |
|
86 | + const HTTP_ALREADY_REPORTED = 208; // RFC5842 |
|
87 | + const HTTP_IM_USED = 226; // RFC3229 |
|
88 | 88 | const HTTP_MULTIPLE_CHOICES = 300; |
89 | 89 | const HTTP_MOVED_PERMANENTLY = 301; |
90 | 90 | const HTTP_FOUND = 302; |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | const HTTP_USE_PROXY = 305; |
94 | 94 | const HTTP_RESERVED = 306; |
95 | 95 | const HTTP_TEMPORARY_REDIRECT = 307; |
96 | - const HTTP_PERMANENTLY_REDIRECT = 308; // RFC7238 |
|
96 | + const HTTP_PERMANENTLY_REDIRECT = 308; // RFC7238 |
|
97 | 97 | const HTTP_BAD_REQUEST = 400; |
98 | 98 | const HTTP_UNAUTHORIZED = 401; |
99 | 99 | const HTTP_PAYMENT_REQUIRED = 402; |
@@ -112,21 +112,21 @@ discard block |
||
112 | 112 | const HTTP_UNSUPPORTED_MEDIA_TYPE = 415; |
113 | 113 | const HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416; |
114 | 114 | const HTTP_EXPECTATION_FAILED = 417; |
115 | - const HTTP_I_AM_A_TEAPOT = 418; // RFC2324 |
|
116 | - const HTTP_MISDIRECTED_REQUEST = 421; // RFC7540 |
|
117 | - const HTTP_UNPROCESSABLE_ENTITY = 422; // RFC4918 |
|
118 | - const HTTP_LOCKED = 423; // RFC4918 |
|
119 | - const HTTP_FAILED_DEPENDENCY = 424; // RFC4918 |
|
115 | + const HTTP_I_AM_A_TEAPOT = 418; // RFC2324 |
|
116 | + const HTTP_MISDIRECTED_REQUEST = 421; // RFC7540 |
|
117 | + const HTTP_UNPROCESSABLE_ENTITY = 422; // RFC4918 |
|
118 | + const HTTP_LOCKED = 423; // RFC4918 |
|
119 | + const HTTP_FAILED_DEPENDENCY = 424; // RFC4918 |
|
120 | 120 | |
121 | 121 | /** |
122 | 122 | * @deprecated |
123 | 123 | */ |
124 | - const HTTP_RESERVED_FOR_WEBDAV_ADVANCED_COLLECTIONS_EXPIRED_PROPOSAL = 425; // RFC2817 |
|
125 | - const HTTP_TOO_EARLY = 425; // RFC-ietf-httpbis-replay-04 |
|
126 | - const HTTP_UPGRADE_REQUIRED = 426; // RFC2817 |
|
127 | - const HTTP_PRECONDITION_REQUIRED = 428; // RFC6585 |
|
128 | - const HTTP_TOO_MANY_REQUESTS = 429; // RFC6585 |
|
129 | - const HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431; // RFC6585 |
|
124 | + const HTTP_RESERVED_FOR_WEBDAV_ADVANCED_COLLECTIONS_EXPIRED_PROPOSAL = 425; // RFC2817 |
|
125 | + const HTTP_TOO_EARLY = 425; // RFC-ietf-httpbis-replay-04 |
|
126 | + const HTTP_UPGRADE_REQUIRED = 426; // RFC2817 |
|
127 | + const HTTP_PRECONDITION_REQUIRED = 428; // RFC6585 |
|
128 | + const HTTP_TOO_MANY_REQUESTS = 429; // RFC6585 |
|
129 | + const HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431; // RFC6585 |
|
130 | 130 | const HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451; |
131 | 131 | const HTTP_INTERNAL_SERVER_ERROR = 500; |
132 | 132 | const HTTP_NOT_IMPLEMENTED = 501; |
@@ -134,10 +134,10 @@ discard block |
||
134 | 134 | const HTTP_SERVICE_UNAVAILABLE = 503; |
135 | 135 | const HTTP_GATEWAY_TIMEOUT = 504; |
136 | 136 | const HTTP_VERSION_NOT_SUPPORTED = 505; |
137 | - const HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL = 506; // RFC2295 |
|
138 | - const HTTP_INSUFFICIENT_STORAGE = 507; // RFC4918 |
|
139 | - const HTTP_LOOP_DETECTED = 508; // RFC5842 |
|
140 | - const HTTP_NOT_EXTENDED = 510; // RFC2774 |
|
137 | + const HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL = 506; // RFC2295 |
|
138 | + const HTTP_INSUFFICIENT_STORAGE = 507; // RFC4918 |
|
139 | + const HTTP_LOOP_DETECTED = 508; // RFC5842 |
|
140 | + const HTTP_NOT_EXTENDED = 510; // RFC2774 |
|
141 | 141 | const HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511; |
142 | 142 | |
143 | 143 | /** |