@@ -14,10 +14,10 @@ |
||
14 | 14 | { |
15 | 15 | public function __construct(Throwable $exception) |
16 | 16 | { |
17 | - $this->path = SUDA_RESOURCE. '/error.php'; |
|
17 | + $this->path = SUDA_RESOURCE.'/error.php'; |
|
18 | 18 | $type = get_class($exception); |
19 | 19 | $this->value = [ |
20 | - 'error_type' => $type , |
|
20 | + 'error_type' => $type, |
|
21 | 21 | 'error_sort_type' => strpos($type, '\\') === false ? $type : substr($type, strrpos($type, '\\') + 1), |
22 | 22 | 'error_code' => $exception->getCode(), |
23 | 23 | 'error_message' => $exception->getMessage(), |
@@ -41,17 +41,17 @@ discard block |
||
41 | 41 | $this->debug->info('==============================='); |
42 | 42 | $this->debug->time('loading application'); |
43 | 43 | $appLoader->load(); |
44 | - $this->event->exec('application:load-config', [ $this->config ,$this]); |
|
44 | + $this->event->exec('application:load-config', [$this->config, $this]); |
|
45 | 45 | $this->debug->timeEnd('loading application'); |
46 | 46 | $this->debug->time('loading datasource'); |
47 | 47 | $appLoader->loadDataSource(); |
48 | 48 | Table::load($this); |
49 | 49 | DataAccess::load($this); |
50 | - $this->event->exec('application:load-environment', [ $this->config ,$this]); |
|
50 | + $this->event->exec('application:load-environment', [$this->config, $this]); |
|
51 | 51 | $this->debug->timeEnd('loading datasource'); |
52 | 52 | $this->debug->time('loading route'); |
53 | 53 | $appLoader->loadRoute(); |
54 | - $this->event->exec('application:load-route', [$this->route , $this]); |
|
54 | + $this->event->exec('application:load-route', [$this->route, $this]); |
|
55 | 55 | $this->debug->timeEnd('loading route'); |
56 | 56 | $this->debug->info('-------------------------------'); |
57 | 57 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | if (!$response->isSended()) { |
104 | 104 | $response->end(); |
105 | 105 | } |
106 | - $this->debug->info('resposned with code '. $response->getStatus()); |
|
106 | + $this->debug->info('resposned with code '.$response->getStatus()); |
|
107 | 107 | $this->debug->timeEnd('sending response'); |
108 | 108 | } catch (Throwable $e) { |
109 | 109 | $this->debug->uncaughtException($e); |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | protected function createResponse(?MatchResult $result, Request $request, Response $response) |
162 | 162 | { |
163 | 163 | if (SUDA_DEBUG) { |
164 | - $response->setHeader('x-route', $result === null?'default':$result->getName()); |
|
164 | + $response->setHeader('x-route', $result === null ? 'default' : $result->getName()); |
|
165 | 165 | } |
166 | 166 | if ($result === null) { |
167 | 167 | $content = $this->defaultResponse($this, $request, $response); |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function __construct($resource = []) |
28 | 28 | { |
29 | - $this->resource = is_array($resource)?$resource:[$resource]; |
|
29 | + $this->resource = is_array($resource) ? $resource : [$resource]; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param string $limitPath 父级溢出 |
67 | 67 | * @return string|null |
68 | 68 | */ |
69 | - public function getResourcePath(string $path, string $limitPath = null):?string |
|
69 | + public function getResourcePath(string $path, string $limitPath = null): ?string |
|
70 | 70 | { |
71 | 71 | foreach ($this->resource as $root) { |
72 | 72 | $target = $root.'/'.$path; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param string $path |
85 | 85 | * @return string|null |
86 | 86 | */ |
87 | - public function getConfigResourcePath(string $path):?string |
|
87 | + public function getConfigResourcePath(string $path): ?string |
|
88 | 88 | { |
89 | 89 | foreach ($this->resource as $root) { |
90 | 90 | if ($target = PathResolver::resolve($root.'/'.$path)) { |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @param string $name |
78 | 78 | * @return Module|null |
79 | 79 | */ |
80 | - public function find(string $name):?Module |
|
80 | + public function find(string $name): ?Module |
|
81 | 81 | { |
82 | 82 | return $this->module->get($name); |
83 | 83 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | $this->modulePaths[] = Resource::getPathByRelativePath($path, $this->path); |
112 | 112 | } |
113 | 113 | } else { |
114 | - $this->modulePaths = [ Resource::getPathByRelativePath('modules', $this->path) ]; |
|
114 | + $this->modulePaths = [Resource::getPathByRelativePath('modules', $this->path)]; |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | */ |
135 | 135 | protected function className(string $name) |
136 | 136 | { |
137 | - return str_replace(['.','/'], '\\', $name); |
|
137 | + return str_replace(['.', '/'], '\\', $name); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @param array|Config $extra |
112 | 112 | * @return array|null |
113 | 113 | */ |
114 | - public static function loadConfig(string $path, $extra = []):?array |
|
114 | + public static function loadConfig(string $path, $extra = []): ?array |
|
115 | 115 | { |
116 | 116 | if (!file_exists($path)) { |
117 | 117 | $path = PathResolver::resolve($path); |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | } |
122 | 122 | if ($path) { |
123 | 123 | $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION)); |
124 | - if (in_array($ext, ['yaml','yml','json','php','ini'])) { |
|
124 | + if (in_array($ext, ['yaml', 'yml', 'json', 'php', 'ini'])) { |
|
125 | 125 | return ContentLoader::{'load'.ucfirst($ext)}($path, $extra); |
126 | 126 | } |
127 | 127 | return ContentLoader::loadJson($path, $extra); |
@@ -279,7 +279,7 @@ |
||
279 | 279 | |
280 | 280 | if ($this->expire !== 0) { |
281 | 281 | $time = $this->fulltime ? $this->expire : time() + $this->expire; |
282 | - $dateTime = DateTime::createFromFormat('U', $time , new DateTimeZone('GMT')); |
|
282 | + $dateTime = DateTime::createFromFormat('U', $time, new DateTimeZone('GMT')); |
|
283 | 283 | $cookie .= '; expires='.str_replace('+0000', '', $dateTime->format('D, d M Y H:i:s T')); |
284 | 284 | } |
285 | 285 |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | |
44 | 44 | public function __construct(array $methods, string $uri, array $attribute = []) |
45 | 45 | { |
46 | - array_walk($methods, function ($value) { |
|
46 | + array_walk($methods, function($value) { |
|
47 | 47 | return strtoupper($value); |
48 | 48 | }); |
49 | 49 | $this->methods = $methods; |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * @param Request $request |
160 | 160 | * @return array|null |
161 | 161 | */ |
162 | - public function match(Request $request):?array |
|
162 | + public function match(Request $request): ?array |
|
163 | 163 | { |
164 | 164 | if (count($this->methods) > 0 && !in_array($request->getMethod(), $this->methods)) { |
165 | 165 | return null; |
@@ -34,9 +34,9 @@ discard block |
||
34 | 34 | // 添加忽略 |
35 | 35 | $url = preg_replace('/(\[)([^\[\]]+)(?(1)\])/', '(?:$2)?', $url); |
36 | 36 | // 添加 * ? 匹配 |
37 | - $url = str_replace(['\*','\?'], ['[^/]*?','[^/]'], $url); |
|
37 | + $url = str_replace(['\*', '\?'], ['[^/]*?', '[^/]'], $url); |
|
38 | 38 | // 编译页面参数 |
39 | - $url = preg_replace_callback('/\{(\w+)(?:\:([^}]+?))?\}/', function ($match) use (&$parameters) { |
|
39 | + $url = preg_replace_callback('/\{(\w+)(?:\:([^}]+?))?\}/', function($match) use (&$parameters) { |
|
40 | 40 | $name = $match[1]; |
41 | 41 | $type = 'string'; |
42 | 42 | $extra = ''; |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | // 拆分参数 |
66 | 66 | list($mapper, $query, $parameter) = static::analyseParameter($matcher, $parameter); |
67 | 67 | // for * ? |
68 | - $url = str_replace(['*','?'], ['','-'], $uri); |
|
68 | + $url = str_replace(['*', '?'], ['', '-'], $uri); |
|
69 | 69 | // for ignore value |
70 | 70 | $url = static::parseIgnoreableParameter($url, $matcher, $parameter, $mapper); |
71 | 71 | $url = static::replaceParameter($url, $matcher, $parameter, $mapper); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | protected static function parseIgnoreableParameter(string $url, UriMatcher $matcher, array $parameter, array $mapper):string |
79 | 79 | { |
80 | - return preg_replace_callback('/\[(.+?)\]/', function ($match) use ($matcher, $parameter, $mapper) { |
|
80 | + return preg_replace_callback('/\[(.+?)\]/', function($match) use ($matcher, $parameter, $mapper) { |
|
81 | 81 | if (preg_match('/\{(\w+).+?\}/', $match[1])) { |
82 | 82 | $count = 0; |
83 | 83 | $subUrl = static::replaceParameter($match[1], $matcher, $parameter, $mapper, true, $count); |
@@ -113,14 +113,14 @@ discard block |
||
113 | 113 | |
114 | 114 | protected static function replaceParameter(string $input, UriMatcher $matcher, array $parameter, array $mapper, bool $ignore = false, ?int &$count = null) |
115 | 115 | { |
116 | - return preg_replace_callback('/\{(\w+).+?\}/', function ($match) use ($matcher, $parameter, $mapper, $ignore, &$count) { |
|
116 | + return preg_replace_callback('/\{(\w+).+?\}/', function($match) use ($matcher, $parameter, $mapper, $ignore, &$count) { |
|
117 | 117 | if (array_key_exists($match[1], $mapper)) { |
118 | - $count ++; |
|
118 | + $count++; |
|
119 | 119 | return $mapper[$match[1]]->packValue($parameter[$match[1]]); |
120 | 120 | } |
121 | 121 | if ($default = $matcher->getParameter($match[1])) { |
122 | 122 | if ($default->hasDefault()) { |
123 | - $count ++; |
|
123 | + $count++; |
|
124 | 124 | return $default->getDefaultValue(); |
125 | 125 | } |
126 | 126 | } |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | * @param boolean $ignoreCase |
47 | 47 | * @return array|null |
48 | 48 | */ |
49 | - public function match(string $url, bool $ignoreCase = true):?array |
|
49 | + public function match(string $url, bool $ignoreCase = true): ?array |
|
50 | 50 | { |
51 | - $match = '#^'. $this->match.'$#'. ($ignoreCase?'i':''); |
|
51 | + $match = '#^'.$this->match.'$#'.($ignoreCase ? 'i' : ''); |
|
52 | 52 | $parameter = []; |
53 | 53 | if (preg_match($match, $url, $parameter, PREG_UNMATCHED_AS_NULL) > 0) { |
54 | 54 | return array_slice($parameter, 1); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | return $parameters; |
80 | 80 | } |
81 | 81 | |
82 | - public function getParameter(string $name):?Parameter |
|
82 | + public function getParameter(string $name): ?Parameter |
|
83 | 83 | { |
84 | 84 | foreach ($this->parameter as $parameter) { |
85 | 85 | if ($parameter->getIndexName() === $name) { |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @param integer $index |
130 | 130 | * @return Parameter|null |
131 | 131 | */ |
132 | - public function getParameterByIndex(int $index):?Parameter |
|
132 | + public function getParameterByIndex(int $index): ?Parameter |
|
133 | 133 | { |
134 | 134 | foreach ($this->parameter as $parameter) { |
135 | 135 | if ($parameter->getIndex() === $index) { |