@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | // 添加忽略 |
31 | 31 | $url = preg_replace('/(\[)([^\[\]]+)(?(1)\])/', '(?:$2)?', $url); |
32 | 32 | // 添加 * ? 匹配 |
33 | - $url = str_replace(['\*','\?'], ['[^/]*?','[^/]'], $url); |
|
33 | + $url = str_replace(['\*', '\?'], ['[^/]*?', '[^/]'], $url); |
|
34 | 34 | // 编译页面参数 |
35 | - $url = preg_replace_callback('/\{(\w+)(?:\:([^}]+?))?\}/', function ($match) use (&$parameters) { |
|
35 | + $url = preg_replace_callback('/\{(\w+)(?:\:([^}]+?))?\}/', function($match) use (&$parameters) { |
|
36 | 36 | $name = $match[1]; |
37 | 37 | $type = 'string'; |
38 | 38 | $extra = ''; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | // 拆分参数 |
62 | 62 | list($mapper, $query, $parameter) = static::analyseParameter($matcher, $parameter); |
63 | 63 | // for * ? |
64 | - $url = \str_replace(['*','?'], ['','-'], $uri); |
|
64 | + $url = \str_replace(['*', '?'], ['', '-'], $uri); |
|
65 | 65 | // for ignore value |
66 | 66 | $url = static::parseIgnoreableParameter($url, $matcher, $parameter, $mapper); |
67 | 67 | $url = static::replaceParameter($url, $matcher, $parameter, $mapper); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | protected static function parseIgnoreableParameter(string $url, UriMatcher $matcher, array $parameter, array $mapper):string |
75 | 75 | { |
76 | - return preg_replace_callback('/\[(.+?)\]/', function ($match) use ($matcher, $parameter, $mapper) { |
|
76 | + return preg_replace_callback('/\[(.+?)\]/', function($match) use ($matcher, $parameter, $mapper) { |
|
77 | 77 | if (preg_match('/\{(\w+).+?\}/', $match[1])) { |
78 | 78 | $count = 0; |
79 | 79 | $subUrl = static::replaceParameter($match[1], $matcher, $parameter, $mapper, true, $count); |
@@ -109,14 +109,14 @@ discard block |
||
109 | 109 | |
110 | 110 | protected static function replaceParameter(string $input, UriMatcher $matcher, array $parameter, array $mapper, bool $ignore = false, ?int &$count = null) |
111 | 111 | { |
112 | - return preg_replace_callback('/\{(\w+).+?\}/', function ($match) use ($matcher, $parameter, $mapper, $ignore, &$count) { |
|
112 | + return preg_replace_callback('/\{(\w+).+?\}/', function($match) use ($matcher, $parameter, $mapper, $ignore, &$count) { |
|
113 | 113 | if (\array_key_exists($match[1], $mapper)) { |
114 | - $count ++; |
|
114 | + $count++; |
|
115 | 115 | return $mapper[$match[1]]->packValue($parameter[$match[1]]); |
116 | 116 | } |
117 | 117 | if ($default = $matcher->getParameter($match[1])) { |
118 | 118 | if ($default->hasDefault()) { |
119 | - $count ++; |
|
119 | + $count++; |
|
120 | 120 | return $default->getDefaultValue(); |
121 | 121 | } |
122 | 122 | } |
@@ -24,7 +24,7 @@ |
||
24 | 24 | |
25 | 25 | public function packValue(?string $matched) |
26 | 26 | { |
27 | - return $matched ? urlencode($matched): ''; |
|
27 | + return $matched ? urlencode($matched) : ''; |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | */ |
181 | 181 | protected function loadRouteGroup(string $groupName) |
182 | 182 | { |
183 | - $group = $groupName === 'default' ? '': '-'. $groupName; |
|
183 | + $group = $groupName === 'default' ? '' : '-'.$groupName; |
|
184 | 184 | if ($path = $this->module->getResource()->getConfigResourcePath('config/route'.$group)) { |
185 | 185 | $routeConfig = Config::loadConfig($path, [ |
186 | 186 | 'module' => $this->module->getName(), |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | protected function loadRouteConfig(string $prefix, string $groupName, array $routeConfig) |
206 | 206 | { |
207 | - $module = $this->module->getFullName(); |
|
207 | + $module = $this->module->getFullName(); |
|
208 | 208 | foreach ($routeConfig as $name => $config) { |
209 | 209 | $exname = $this->application->getRouteName($name, $module, $groupName); |
210 | 210 | $method = $config['method'] ?? []; |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | if ($anti) { |
219 | 219 | $uri = '/'.trim($uri, '/'); |
220 | 220 | } else { |
221 | - $uri = '/'.trim($prefix . $uri, '/'); |
|
221 | + $uri = '/'.trim($prefix.$uri, '/'); |
|
222 | 222 | } |
223 | 223 | $this->application->request($method, $exname, $uri, $attriute); |
224 | 224 | } |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | protected static function valueToString(string $key, $value, int $deep):string |
65 | 65 | { |
66 | 66 | if (is_string($value) && strlen($value) > static::$dumpStringLength) { |
67 | - return $key.'='.json_encode(substr($value, 0, static::$dumpStringLength), JSON_UNESCAPED_UNICODE) .'... ,'; |
|
67 | + return $key.'='.json_encode(substr($value, 0, static::$dumpStringLength), JSON_UNESCAPED_UNICODE).'... ,'; |
|
68 | 68 | } elseif (is_bool($value)) { |
69 | 69 | return $key.'='.($value ? 'true' : 'false').' ,'; |
70 | 70 | } else { |
71 | - return $key.'='.self::parameterToString($value, $deep - 1) .' ,'; |
|
71 | + return $key.'='.self::parameterToString($value, $deep - 1).' ,'; |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | $argsDump = ''; |
117 | 117 | if (!empty($trace['args'])) { |
118 | 118 | foreach ($trace['args'] as $arg) { |
119 | - $argsDump .= self::parameterToString($arg) .','; |
|
119 | + $argsDump .= self::parameterToString($arg).','; |
|
120 | 120 | } |
121 | 121 | $argsDump = rtrim($argsDump, ','); |
122 | 122 | } |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | |
127 | 127 | public static function dumpThrowable(\Throwable $e) |
128 | 128 | { |
129 | - $dump = get_class($e).':'. $e->getMessage() .PHP_EOL; |
|
130 | - $dump .= 'At: ' . $e->getFile().':'.$e->getLine().PHP_EOL; |
|
129 | + $dump = get_class($e).':'.$e->getMessage().PHP_EOL; |
|
130 | + $dump .= 'At: '.$e->getFile().':'.$e->getLine().PHP_EOL; |
|
131 | 131 | $dump .= static::dumpTrace($e->getTrace()); |
132 | 132 | return $dump; |
133 | 133 | } |
@@ -13,7 +13,7 @@ |
||
13 | 13 | public function __construct(string $name, int $type = 0) |
14 | 14 | { |
15 | 15 | $this->name = $name; |
16 | - parent::__construct(sprintf('missing template %s', $name, $type == 0 ? 'source':'dest')); |
|
16 | + parent::__construct(sprintf('missing template %s', $name, $type == 0 ? 'source' : 'dest')); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | |
107 | 107 | protected function getStaticOutpath() |
108 | 108 | { |
109 | - $path = $this->config['assets-public'] ?? \constant('SUDA_PUBLIC').'/assets/'. $this->getStaticName(); |
|
109 | + $path = $this->config['assets-public'] ?? \constant('SUDA_PUBLIC').'/assets/'.$this->getStaticName(); |
|
110 | 110 | FileSystem::make($path); |
111 | 111 | return $path; |
112 | 112 | } |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | { |
121 | 121 | $output = $this->config['output'] ?? \constant('SUDA_DATA').'/template'; |
122 | 122 | FileSystem::make($output); |
123 | - return $output .'/'. $this->name.'-'.substr(md5_file($this->getSourcePath()), 10, 8).'.php'; |
|
123 | + return $output.'/'.$this->name.'-'.substr(md5_file($this->getSourcePath()), 10, 8).'.php'; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @return string|null |
130 | 130 | */ |
131 | - public function getSourcePath():?string |
|
131 | + public function getSourcePath(): ?string |
|
132 | 132 | { |
133 | 133 | return $this->source ?? null; |
134 | 134 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @return void |
151 | 151 | */ |
152 | - protected function compile(){ |
|
152 | + protected function compile() { |
|
153 | 153 | $sourcePath = $this->getSourcePath(); |
154 | 154 | $destPath = $this->getPath(); |
155 | 155 | if ($sourcePath === null) { |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | public function include(string $path) |
203 | 203 | { |
204 | 204 | $subfix = $this->config['subfix'] ?? ''; |
205 | - $included = new self(Resource::getPathByRelativedPath($path. $subfix, dirname($this->source)), $this->config); |
|
205 | + $included = new self(Resource::getPathByRelativedPath($path.$subfix, dirname($this->source)), $this->config); |
|
206 | 206 | $included->parent = $this; |
207 | 207 | echo $included->getRenderedString(); |
208 | 208 | } |
@@ -219,13 +219,13 @@ discard block |
||
219 | 219 | { |
220 | 220 | $this->prepareStaticSource(); |
221 | 221 | if (\array_key_exists('assets-prefix', $this->config)) { |
222 | - $prefix = $this->config['assets-prefix'] ; |
|
222 | + $prefix = $this->config['assets-prefix']; |
|
223 | 223 | } elseif (defined('SUDA_ASSETS')) { |
224 | 224 | $prefix = \constant('SUDA_ASSETS'); |
225 | 225 | } else { |
226 | 226 | $prefix = '/assets'; |
227 | 227 | } |
228 | - return $prefix .'/'.$this->getStaticName(); |
|
228 | + return $prefix.'/'.$this->getStaticName(); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | protected function prepareStaticSource() |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @return string|null |
28 | 28 | */ |
29 | - public function getSourcePath():?string |
|
29 | + public function getSourcePath(): ?string |
|
30 | 30 | { |
31 | 31 | $subfix = $this->config['subfix'] ?? '.tpl.html'; |
32 | 32 | return $this->getResource($this->module)->getResourcePath($this->getTemplatePath().'/'.$this->name.$subfix); |
@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function getPath() |
41 | 41 | { |
42 | - $output = $this->config['output'] ?? \constant('SUDA_DATA').'/template/'. $this->uriName; |
|
42 | + $output = $this->config['output'] ?? \constant('SUDA_DATA').'/template/'.$this->uriName; |
|
43 | 43 | FileSystem::make($output); |
44 | - return $output .'/'. $this->name.'.php'; |
|
44 | + return $output.'/'.$this->name.'.php'; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | } |
70 | 70 | return $this->application->getUrl($this->request, $name, $values ?? [], true, $this->module, $this->group); |
71 | 71 | } elseif (is_array($name) && \is_string($defaultName)) { |
72 | - return $this->application->getUrl($this->request, $defaultName, array_merge($this->request->get() ?? [], $name) , true, $this->module, $this->group); |
|
72 | + return $this->application->getUrl($this->request, $defaultName, array_merge($this->request->get() ?? [], $name), true, $this->module, $this->group); |
|
73 | 73 | } elseif (is_string($defaultName)) { |
74 | 74 | return $this->application->getUrl($this->request, $defaultName, $this->request->get() ?? [], true, $this->module, $this->group); |
75 | 75 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | if ($this->request->getAttribute('route') === $full) { |
89 | 89 | if (\is_array($parameter)) { |
90 | 90 | foreach ($parameter as $key => $value) { |
91 | - if ($this->request->getQuery($key) != $value){ |
|
91 | + if ($this->request->getQuery($key) != $value) { |
|
92 | 92 | return false; |
93 | 93 | } |
94 | 94 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | if (array_key_exists('server-port', $this->request->server())) { |
99 | 99 | return $this->request->server()['server-port']; |
100 | 100 | } |
101 | - return $this->getSecure()?443:80; |
|
101 | + return $this->getSecure() ? 443 : 80; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | */ |
139 | 139 | private function createUribase(Request $request) |
140 | 140 | { |
141 | - $scheme = $request->isSecure()?'https':'http'; |
|
141 | + $scheme = $request->isSecure() ? 'https' : 'http'; |
|
142 | 142 | $port = $request->getPort(); |
143 | 143 | if ($port == 80 && $scheme == 'http') { |
144 | 144 | $port = ''; |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | } else { |
148 | 148 | $port = ':'.$port; |
149 | 149 | } |
150 | - $base = $scheme.'://'. $request->getHost().$port; |
|
150 | + $base = $scheme.'://'.$request->getHost().$port; |
|
151 | 151 | $request->setUribase($base); |
152 | 152 | } |
153 | 153 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @param string|null $default |
22 | 22 | * @return string|null |
23 | 23 | */ |
24 | - public function getUrl(Request $request, string $name, array $parameter = [], bool $allowQuery = true, ?string $default = null, ?string $group = null):?string |
|
24 | + public function getUrl(Request $request, string $name, array $parameter = [], bool $allowQuery = true, ?string $default = null, ?string $group = null): ?string |
|
25 | 25 | { |
26 | 26 | $group = $group ?? $request->getAttribute('group'); |
27 | 27 | $default = $default ?? $request->getAttribute('module'); |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | protected function getUrlIndex(Request $request):string |
39 | 39 | { |
40 | - $indexs = $this->conf('indexs') ?? [ 'index.php' ]; |
|
40 | + $indexs = $this->conf('indexs') ?? ['index.php']; |
|
41 | 41 | $index = ltrim($request->getIndex(), '/'); |
42 | 42 | if (!\in_array($index, $indexs)) { |
43 | 43 | return $request->getIndex(); |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function getUribase(Request $request, bool $beautify = true):string { |
141 | 141 | $index = $beautify ? $this->getUrlIndex($request) : $request->getIndex(); |
142 | - return $request->getUribase() . $index; |
|
142 | + return $request->getUribase().$index; |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -150,6 +150,6 @@ discard block |
||
150 | 150 | */ |
151 | 151 | protected function getRouteGroupPrefix(?string $group):string |
152 | 152 | { |
153 | - return $group === null || $group === 'default' ? '': '@'. $group; |
|
153 | + return $group === null || $group === 'default' ? '' : '@'.$group; |
|
154 | 154 | } |
155 | 155 | } |