@@ -8,7 +8,7 @@ |
||
8 | 8 | // +---------------------------------------------------------------------- |
9 | 9 | // | Author: liu21st <[email protected]> |
10 | 10 | // +---------------------------------------------------------------------- |
11 | -declare(strict_types = 1); |
|
11 | +declare(strict_types=1); |
|
12 | 12 | |
13 | 13 | namespace think\route; |
14 | 14 |
@@ -8,7 +8,7 @@ |
||
8 | 8 | // +---------------------------------------------------------------------- |
9 | 9 | // | Author: liu21st <[email protected]> |
10 | 10 | // +---------------------------------------------------------------------- |
11 | -declare(strict_types = 1); |
|
11 | +declare(strict_types=1); |
|
12 | 12 | |
13 | 13 | namespace think\route\dispatch; |
14 | 14 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | // +---------------------------------------------------------------------- |
9 | 9 | // | Author: liu21st <[email protected]> |
10 | 10 | // +---------------------------------------------------------------------- |
11 | -declare(strict_types = 1); |
|
11 | +declare(strict_types=1); |
|
12 | 12 | |
13 | 13 | namespace think\route\dispatch; |
14 | 14 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | if ($bind && preg_match('/^[a-z]/is', $bind)) { |
47 | 47 | $bind = str_replace('/', $depr, $bind); |
48 | 48 | // 如果有域名绑定 |
49 | - $url = $bind . ('.' != substr($bind, -1) ? $depr : '') . ltrim($url, $depr); |
|
49 | + $url = $bind.('.' != substr($bind, -1) ? $depr : '').ltrim($url, $depr); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | $path = $this->rule->parseUrlPath($url); |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $controller = !empty($path) ? array_shift($path) : null; |
59 | 59 | |
60 | 60 | if ($controller && !preg_match('/^[A-Za-z0-9][\w|\.]*$/', $controller)) { |
61 | - throw new HttpException(404, 'controller not exists:' . $controller); |
|
61 | + throw new HttpException(404, 'controller not exists:'.$controller); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | // 解析操作 |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | |
68 | 68 | // 解析额外参数 |
69 | 69 | if ($path) { |
70 | - preg_replace_callback('/(\w+)\|([^\|]+)/', function ($match) use (&$var) { |
|
70 | + preg_replace_callback('/(\w+)\|([^\|]+)/', function($match) use (&$var) { |
|
71 | 71 | $var[$match[1]] = strip_tags($match[2]); |
72 | 72 | }, implode('|', $path)); |
73 | 73 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $route = [$controller, $action]; |
86 | 86 | |
87 | 87 | if ($this->hasDefinedRoute($route)) { |
88 | - throw new HttpException(404, 'invalid request:' . str_replace('|', $depr, $url)); |
|
88 | + throw new HttpException(404, 'invalid request:'.str_replace('|', $depr, $url)); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | return $route; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | [$controller, $action] = $route; |
103 | 103 | |
104 | 104 | // 检查地址是否被定义过路由 |
105 | - $name = strtolower(Str::studly($controller) . '/' . $action); |
|
105 | + $name = strtolower(Str::studly($controller).'/'.$action); |
|
106 | 106 | |
107 | 107 | $host = $this->request->host(true); |
108 | 108 | $method = $this->request->method(); |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | // +---------------------------------------------------------------------- |
9 | 9 | // | Author: liu21st <[email protected]> |
10 | 10 | // +---------------------------------------------------------------------- |
11 | -declare(strict_types = 1); |
|
11 | +declare(strict_types=1); |
|
12 | 12 | |
13 | 13 | namespace think\route\dispatch; |
14 | 14 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | if (strpos($controller, '.')) { |
55 | 55 | $pos = strrpos($controller, '.'); |
56 | - $this->controller = substr($controller, 0, $pos) . '.' . Str::studly(substr($controller, $pos + 1)); |
|
56 | + $this->controller = substr($controller, 0, $pos).'.'.Str::studly(substr($controller, $pos + 1)); |
|
57 | 57 | } else { |
58 | 58 | $this->controller = Str::studly($controller); |
59 | 59 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | // 实例化控制器 |
74 | 74 | $instance = $this->controller($this->controller); |
75 | 75 | } catch (ClassNotFoundException $e) { |
76 | - throw new HttpException(404, 'controller not exists:' . $e->getClass()); |
|
76 | + throw new HttpException(404, 'controller not exists:'.$e->getClass()); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | // 注册控制器中间件 |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | |
82 | 82 | return $this->app->middleware->pipeline('controller') |
83 | 83 | ->send($this->request) |
84 | - ->then(function () use ($instance) { |
|
84 | + ->then(function() use ($instance) { |
|
85 | 85 | // 获取当前操作名 |
86 | 86 | $suffix = $this->rule->config('action_suffix'); |
87 | - $action = $this->actionName . $suffix; |
|
87 | + $action = $this->actionName.$suffix; |
|
88 | 88 | |
89 | 89 | if (is_callable([$instance, $action])) { |
90 | 90 | $vars = $this->request->param(); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | } |
105 | 105 | } else { |
106 | 106 | // 操作不存在 |
107 | - throw new HttpException(404, 'method not exists:' . get_class($instance) . '->' . $action . '()'); |
|
107 | + throw new HttpException(404, 'method not exists:'.get_class($instance).'->'.$action.'()'); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | $data = $this->app->invokeReflectMethod($instance, $reflect, $vars); |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | |
132 | 132 | foreach ($middlewares as $key => $val) { |
133 | 133 | if (!is_int($key)) { |
134 | - if (isset($val['only']) && !in_array($this->request->action(true), array_map(function ($item) { |
|
134 | + if (isset($val['only']) && !in_array($this->request->action(true), array_map(function($item) { |
|
135 | 135 | return strtolower($item); |
136 | 136 | }, is_string($val['only']) ? explode(",", $val['only']) : $val['only']))) { |
137 | 137 | continue; |
138 | - } elseif (isset($val['except']) && in_array($this->request->action(true), array_map(function ($item) { |
|
138 | + } elseif (isset($val['except']) && in_array($this->request->action(true), array_map(function($item) { |
|
139 | 139 | return strtolower($item); |
140 | 140 | }, is_string($val['except']) ? explode(',', $val['except']) : $val['except']))) { |
141 | 141 | continue; |
@@ -170,14 +170,14 @@ discard block |
||
170 | 170 | $controllerLayer = $this->rule->config('controller_layer') ?: 'controller'; |
171 | 171 | $emptyController = $this->rule->config('empty_controller') ?: 'Error'; |
172 | 172 | |
173 | - $class = $this->app->parseClass($controllerLayer, $name . $suffix); |
|
173 | + $class = $this->app->parseClass($controllerLayer, $name.$suffix); |
|
174 | 174 | |
175 | 175 | if (class_exists($class)) { |
176 | 176 | return $this->app->make($class, [], true); |
177 | - } elseif ($emptyController && class_exists($emptyClass = $this->app->parseClass($controllerLayer, $emptyController . $suffix))) { |
|
177 | + } elseif ($emptyController && class_exists($emptyClass = $this->app->parseClass($controllerLayer, $emptyController.$suffix))) { |
|
178 | 178 | return $this->app->make($emptyClass, [], true); |
179 | 179 | } |
180 | 180 | |
181 | - throw new ClassNotFoundException('class not exists:' . $class, $class); |
|
181 | + throw new ClassNotFoundException('class not exists:'.$class, $class); |
|
182 | 182 | } |
183 | 183 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | // +---------------------------------------------------------------------- |
9 | 9 | // | Author: liu21st <[email protected]> |
10 | 10 | // +---------------------------------------------------------------------- |
11 | -declare(strict_types = 1); |
|
11 | +declare(strict_types=1); |
|
12 | 12 | |
13 | 13 | namespace think\route; |
14 | 14 | |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | { |
613 | 613 | if (is_string($route) && isset($option['prefix'])) { |
614 | 614 | // 路由地址前缀 |
615 | - $route = $option['prefix'] . $route; |
|
615 | + $route = $option['prefix'].$route; |
|
616 | 616 | } |
617 | 617 | |
618 | 618 | // 替换路由地址中的变量 |
@@ -620,10 +620,10 @@ discard block |
||
620 | 620 | $search = $replace = []; |
621 | 621 | |
622 | 622 | foreach ($matches as $key => $value) { |
623 | - $search[] = '<' . $key . '>'; |
|
623 | + $search[] = '<'.$key.'>'; |
|
624 | 624 | $replace[] = $value; |
625 | 625 | |
626 | - $search[] = ':' . $key; |
|
626 | + $search[] = ':'.$key; |
|
627 | 627 | $replace[] = $value; |
628 | 628 | } |
629 | 629 | |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | // AJAX PJAX 请求检查 |
729 | 729 | foreach (['ajax', 'pjax', 'json'] as $item) { |
730 | 730 | if (isset($option[$item])) { |
731 | - $call = 'is' . $item; |
|
731 | + $call = 'is'.$item; |
|
732 | 732 | if ($option[$item] && !$request->$call() || !$option[$item] && $request->$call()) { |
733 | 733 | return false; |
734 | 734 | } |
@@ -736,8 +736,8 @@ discard block |
||
736 | 736 | } |
737 | 737 | |
738 | 738 | // 伪静态后缀检测 |
739 | - if ($request->url() != '/' && ((isset($option['ext']) && false === stripos('|' . $option['ext'] . '|', '|' . $request->ext() . '|')) |
|
740 | - || (isset($option['deny_ext']) && false !== stripos('|' . $option['deny_ext'] . '|', '|' . $request->ext() . '|')))) { |
|
739 | + if ($request->url() != '/' && ((isset($option['ext']) && false === stripos('|'.$option['ext'].'|', '|'.$request->ext().'|')) |
|
740 | + || (isset($option['deny_ext']) && false !== stripos('|'.$option['deny_ext'].'|', '|'.$request->ext().'|')))) { |
|
741 | 741 | return false; |
742 | 742 | } |
743 | 743 | |
@@ -774,7 +774,7 @@ discard block |
||
774 | 774 | protected function parseUrlParams(string $url, array &$var = []): void |
775 | 775 | { |
776 | 776 | if ($url) { |
777 | - preg_replace_callback('/(\w+)\|([^\|]+)/', function ($match) use (&$var) { |
|
777 | + preg_replace_callback('/(\w+)\|([^\|]+)/', function($match) use (&$var) { |
|
778 | 778 | $var[$match[1]] = strip_tags($match[2]); |
779 | 779 | }, $url); |
780 | 780 | } |
@@ -836,7 +836,7 @@ discard block |
||
836 | 836 | $regex .= '\/'; |
837 | 837 | } |
838 | 838 | |
839 | - return $regex . ($completeMatch ? '$' : ''); |
|
839 | + return $regex.($completeMatch ? '$' : ''); |
|
840 | 840 | } |
841 | 841 | |
842 | 842 | /** |
@@ -853,7 +853,7 @@ discard block |
||
853 | 853 | $slash = substr($name, 0, 1); |
854 | 854 | |
855 | 855 | if (in_array($slash, ['/', '-'])) { |
856 | - $prefix = '\\' . $slash; |
|
856 | + $prefix = '\\'.$slash; |
|
857 | 857 | $name = substr($name, 1); |
858 | 858 | $slash = substr($name, 0, 1); |
859 | 859 | } else { |
@@ -861,7 +861,7 @@ discard block |
||
861 | 861 | } |
862 | 862 | |
863 | 863 | if ('<' != $slash) { |
864 | - return $prefix . preg_quote($name, '/'); |
|
864 | + return $prefix.preg_quote($name, '/'); |
|
865 | 865 | } |
866 | 866 | |
867 | 867 | if (strpos($name, '?')) { |
@@ -880,7 +880,7 @@ discard block |
||
880 | 880 | $nameRule = $this->router->config('default_route_pattern'); |
881 | 881 | } |
882 | 882 | |
883 | - return '(' . $prefix . '(?<' . $name . $suffix . '>' . $nameRule . '))' . $optional; |
|
883 | + return '('.$prefix.'(?<'.$name.$suffix.'>'.$nameRule.'))'.$optional; |
|
884 | 884 | } |
885 | 885 | |
886 | 886 | /** |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | // +---------------------------------------------------------------------- |
9 | 9 | // | Author: liu21st <[email protected]> |
10 | 10 | // +---------------------------------------------------------------------- |
11 | -declare(strict_types = 1); |
|
11 | +declare(strict_types=1); |
|
12 | 12 | |
13 | 13 | namespace think\route; |
14 | 14 | |
@@ -109,10 +109,10 @@ discard block |
||
109 | 109 | $item = []; |
110 | 110 | |
111 | 111 | foreach ($array as $val) { |
112 | - $item[] = $val . '/<' . ($option['var'][$val] ?? $val . '_id') . '>'; |
|
112 | + $item[] = $val.'/<'.($option['var'][$val] ?? $val.'_id').'>'; |
|
113 | 113 | } |
114 | 114 | |
115 | - $rule = implode('/', $item) . '/' . $last; |
|
115 | + $rule = implode('/', $item).'/'.$last; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | $prefix = substr($rule, strlen($this->name) + 1); |
@@ -125,12 +125,12 @@ discard block |
||
125 | 125 | } |
126 | 126 | |
127 | 127 | if (isset($last) && strpos($val[1], '<id>') && isset($option['var'][$last])) { |
128 | - $val[1] = str_replace('<id>', '<' . $option['var'][$last] . '>', $val[1]); |
|
128 | + $val[1] = str_replace('<id>', '<'.$option['var'][$last].'>', $val[1]); |
|
129 | 129 | } elseif (strpos($val[1], '<id>') && isset($option['var'][$rule])) { |
130 | - $val[1] = str_replace('<id>', '<' . $option['var'][$rule] . '>', $val[1]); |
|
130 | + $val[1] = str_replace('<id>', '<'.$option['var'][$rule].'>', $val[1]); |
|
131 | 131 | } |
132 | 132 | |
133 | - $ruleItem = $this->addRule(trim($prefix . $val[1], '/'), $this->route . '/' . $val[2], $val[0]); |
|
133 | + $ruleItem = $this->addRule(trim($prefix.$val[1], '/'), $this->route.'/'.$val[2], $val[0]); |
|
134 | 134 | |
135 | 135 | foreach (['model', 'validate', 'middleware'] as $name) { |
136 | 136 | if (isset($this->$name[$key])) { |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | // +---------------------------------------------------------------------- |
9 | 9 | // | Author: liu21st <[email protected]> |
10 | 10 | // +---------------------------------------------------------------------- |
11 | -declare(strict_types = 1); |
|
11 | +declare(strict_types=1); |
|
12 | 12 | |
13 | 13 | namespace think\route; |
14 | 14 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | $rule = '/' != $rule ? ltrim($rule, '/') : ''; |
135 | 135 | |
136 | 136 | if ($this->parent && $prefix = $this->parent->getFullName()) { |
137 | - $rule = $prefix . ($rule ? '/' . ltrim($rule, '/') : ''); |
|
137 | + $rule = $prefix.($rule ? '/'.ltrim($rule, '/') : ''); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | if (false !== strpos($rule, ':')) { |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | |
238 | 238 | if (isset($option['ext'])) { |
239 | 239 | // 路由ext参数 优先于系统配置的URL伪静态后缀参数 |
240 | - $url = preg_replace('/\.(' . $request->ext() . ')$/i', '', $url); |
|
240 | + $url = preg_replace('/\.('.$request->ext().')$/i', '', $url); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | return $url; |
@@ -261,38 +261,38 @@ discard block |
||
261 | 261 | $pattern = array_merge($this->parent->getPattern(), $this->pattern); |
262 | 262 | |
263 | 263 | // 检查完整规则定义 |
264 | - if (isset($pattern['__url__']) && !preg_match(0 === strpos($pattern['__url__'], '/') ? $pattern['__url__'] : '/^' . $pattern['__url__'] . ($completeMatch ? '$' : '') . '/', str_replace('|', $depr, $url))) { |
|
264 | + if (isset($pattern['__url__']) && !preg_match(0 === strpos($pattern['__url__'], '/') ? $pattern['__url__'] : '/^'.$pattern['__url__'].($completeMatch ? '$' : '').'/', str_replace('|', $depr, $url))) { |
|
265 | 265 | return false; |
266 | 266 | } |
267 | 267 | |
268 | 268 | $var = []; |
269 | - $url = $depr . str_replace('|', $depr, $url); |
|
270 | - $rule = $depr . str_replace('/', $depr, $this->rule); |
|
269 | + $url = $depr.str_replace('|', $depr, $url); |
|
270 | + $rule = $depr.str_replace('/', $depr, $this->rule); |
|
271 | 271 | |
272 | 272 | if ($depr == $rule && $depr != $url) { |
273 | 273 | return false; |
274 | 274 | } |
275 | 275 | |
276 | 276 | if (false === strpos($rule, '<')) { |
277 | - if (0 === strcasecmp($rule, $url) || (!$completeMatch && 0 === strncasecmp($rule . $depr, $url . $depr, strlen($rule . $depr)))) { |
|
277 | + if (0 === strcasecmp($rule, $url) || (!$completeMatch && 0 === strncasecmp($rule.$depr, $url.$depr, strlen($rule.$depr)))) { |
|
278 | 278 | return $var; |
279 | 279 | } |
280 | 280 | return false; |
281 | 281 | } |
282 | 282 | |
283 | - $slash = preg_quote('/-' . $depr, '/'); |
|
283 | + $slash = preg_quote('/-'.$depr, '/'); |
|
284 | 284 | |
285 | - if ($matchRule = preg_split('/[' . $slash . ']?<\w+\??>/', $rule, 2)) { |
|
285 | + if ($matchRule = preg_split('/['.$slash.']?<\w+\??>/', $rule, 2)) { |
|
286 | 286 | if ($matchRule[0] && 0 !== strncasecmp($rule, $url, strlen($matchRule[0]))) { |
287 | 287 | return false; |
288 | 288 | } |
289 | 289 | } |
290 | 290 | |
291 | - if (preg_match_all('/[' . $slash . ']?<?\w+\??>?/', $rule, $matches)) { |
|
291 | + if (preg_match_all('/['.$slash.']?<?\w+\??>?/', $rule, $matches)) { |
|
292 | 292 | $regex = $this->buildRuleRegex($rule, $matches[0], $pattern, $option, $completeMatch); |
293 | 293 | |
294 | 294 | try { |
295 | - if (!preg_match('/^' . $regex . '/u', $url, $match)) { |
|
295 | + if (!preg_match('/^'.$regex.'/u', $url, $match)) { |
|
296 | 296 | return false; |
297 | 297 | } |
298 | 298 | } catch (\Exception $e) { |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | // +---------------------------------------------------------------------- |
9 | 9 | // | Author: liu21st <[email protected]> |
10 | 10 | // +---------------------------------------------------------------------- |
11 | -declare(strict_types = 1); |
|
11 | +declare(strict_types=1); |
|
12 | 12 | |
13 | 13 | namespace think\route; |
14 | 14 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | } |
191 | 191 | } |
192 | 192 | } elseif (false === strpos($domain, '.') && 0 !== strpos($domain, $rootDomain)) { |
193 | - $domain .= '.' . $rootDomain; |
|
193 | + $domain .= '.'.$rootDomain; |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | if (false !== strpos($domain, '://')) { |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | $scheme = $this->https || $request->isSsl() ? 'https://' : 'http://'; |
200 | 200 | } |
201 | 201 | |
202 | - return $scheme . $domain; |
|
202 | + return $scheme.$domain; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
221 | - return (empty($suffix) || 0 === strpos($suffix, '.')) ? (string) $suffix : '.' . $suffix; |
|
221 | + return (empty($suffix) || 0 === strpos($suffix, '.')) ? (string) $suffix : '.'.$suffix; |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | // 解析到控制器 |
243 | 243 | $url = substr($url, 1); |
244 | 244 | } elseif ('' === $url) { |
245 | - $url = $request->controller() . '/' . $request->action(); |
|
245 | + $url = $request->controller().'/'.$request->action(); |
|
246 | 246 | } else { |
247 | 247 | $controller = $request->controller(); |
248 | 248 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | $action = array_pop($path); |
251 | 251 | $controller = empty($path) ? $controller : array_pop($path); |
252 | 252 | |
253 | - $url = $controller . '/' . $action; |
|
253 | + $url = $controller.'/'.$action; |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | return $url; |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | { |
298 | 298 | $request = $this->app->request; |
299 | 299 | if (is_string($allowDomain) && false === strpos($allowDomain, '.')) { |
300 | - $allowDomain .= '.' . $request->rootDomain(); |
|
300 | + $allowDomain .= '.'.$request->rootDomain(); |
|
301 | 301 | } |
302 | 302 | $port = $request->port(); |
303 | 303 | |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | } |
317 | 317 | |
318 | 318 | if ($port && !in_array($port, [80, 443])) { |
319 | - $domain .= ':' . $port; |
|
319 | + $domain .= ':'.$port; |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | if (empty($pattern)) { |
@@ -328,12 +328,12 @@ discard block |
||
328 | 328 | |
329 | 329 | foreach ($pattern as $key => $val) { |
330 | 330 | if (isset($vars[$key])) { |
331 | - $url = str_replace(['[:' . $key . ']', '<' . $key . '?>', ':' . $key, '<' . $key . '>'], $type ? $vars[$key] : urlencode((string) $vars[$key]), $url); |
|
331 | + $url = str_replace(['[:'.$key.']', '<'.$key.'?>', ':'.$key, '<'.$key.'>'], $type ? $vars[$key] : urlencode((string) $vars[$key]), $url); |
|
332 | 332 | $keys[] = $key; |
333 | 333 | $url = str_replace(['/?', '-?'], ['/', '-'], $url); |
334 | 334 | $result = [rtrim($url, '?/-'), $domain, $suffix]; |
335 | 335 | } elseif (2 == $val) { |
336 | - $url = str_replace(['/[:' . $key . ']', '[:' . $key . ']', '<' . $key . '?>'], '', $url); |
|
336 | + $url = str_replace(['/[:'.$key.']', '[:'.$key.']', '<'.$key.'?>'], '', $url); |
|
337 | 337 | $url = str_replace(['/?', '-?'], ['/', '-'], $url); |
338 | 338 | $result = [rtrim($url, '?/-'), $domain, $suffix]; |
339 | 339 | } else { |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | if (0 === strpos($url, '[') && $pos = strpos($url, ']')) { |
366 | 366 | // [name] 表示使用路由命名标识生成URL |
367 | 367 | $name = substr($url, 1, $pos - 1); |
368 | - $url = 'name' . substr($url, $pos + 1); |
|
368 | + $url = 'name'.substr($url, $pos + 1); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | if (false === strpos($url, '://') && 0 !== strpos($url, '/')) { |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | } |
393 | 393 | |
394 | 394 | if ($url) { |
395 | - $checkName = isset($name) ? $name : $url . (isset($info['query']) ? '?' . $info['query'] : ''); |
|
395 | + $checkName = isset($name) ? $name : $url.(isset($info['query']) ? '?'.$info['query'] : ''); |
|
396 | 396 | $checkDomain = $domain && is_string($domain) ? $domain : null; |
397 | 397 | |
398 | 398 | $rule = $this->route->getName($checkName, $checkDomain); |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | $suffix = $match[2]; |
419 | 419 | } |
420 | 420 | } elseif (!empty($rule) && isset($name)) { |
421 | - throw new \InvalidArgumentException('route name not exists:' . $name); |
|
421 | + throw new \InvalidArgumentException('route name not exists:'.$name); |
|
422 | 422 | } else { |
423 | 423 | // 检测URL绑定 |
424 | 424 | $bind = $this->route->getDomainBind($domain && is_string($domain) ? $domain : null); |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | $file = str_replace('\\', '/', dirname($file)); |
457 | 457 | } |
458 | 458 | |
459 | - $url = rtrim($file, '/') . '/' . $url; |
|
459 | + $url = rtrim($file, '/').'/'.$url; |
|
460 | 460 | |
461 | 461 | // URL后缀 |
462 | 462 | if ('/' == substr($url, -1) || '' == $url) { |
@@ -466,33 +466,33 @@ discard block |
||
466 | 466 | } |
467 | 467 | |
468 | 468 | // 锚点 |
469 | - $anchor = !empty($anchor) ? '#' . $anchor : ''; |
|
469 | + $anchor = !empty($anchor) ? '#'.$anchor : ''; |
|
470 | 470 | |
471 | 471 | // 参数组装 |
472 | 472 | if (!empty($vars)) { |
473 | 473 | // 添加参数 |
474 | 474 | if ($this->route->config('url_common_param')) { |
475 | 475 | $vars = http_build_query($vars); |
476 | - $url .= $suffix . '?' . $vars . $anchor; |
|
476 | + $url .= $suffix.'?'.$vars.$anchor; |
|
477 | 477 | } else { |
478 | 478 | foreach ($vars as $var => $val) { |
479 | 479 | $val = (string) $val; |
480 | 480 | if ('' !== $val) { |
481 | - $url .= $depr . $var . $depr . urlencode($val); |
|
481 | + $url .= $depr.$var.$depr.urlencode($val); |
|
482 | 482 | } |
483 | 483 | } |
484 | 484 | |
485 | - $url .= $suffix . $anchor; |
|
485 | + $url .= $suffix.$anchor; |
|
486 | 486 | } |
487 | 487 | } else { |
488 | - $url .= $suffix . $anchor; |
|
488 | + $url .= $suffix.$anchor; |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | // 检测域名 |
492 | 492 | $domain = $this->parseDomain($url, $domain); |
493 | 493 | |
494 | 494 | // URL组装 |
495 | - return $domain . rtrim($this->root, '/') . '/' . ltrim($url, '/'); |
|
495 | + return $domain.rtrim($this->root, '/').'/'.ltrim($url, '/'); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | public function __toString() |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | // +---------------------------------------------------------------------- |
9 | 9 | // | Author: liu21st <[email protected]> |
10 | 10 | // +---------------------------------------------------------------------- |
11 | -declare(strict_types = 1); |
|
11 | +declare(strict_types=1); |
|
12 | 12 | |
13 | 13 | namespace think\route; |
14 | 14 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | } |
95 | 95 | |
96 | 96 | if ($this->parent && $this->parent->getFullName()) { |
97 | - $this->fullName = $this->parent->getFullName() . ($this->name ? '/' . $this->name : ''); |
|
97 | + $this->fullName = $this->parent->getFullName().($this->name ? '/'.$this->name : ''); |
|
98 | 98 | } else { |
99 | 99 | $this->fullName = $this->name; |
100 | 100 | } |
@@ -278,14 +278,14 @@ discard block |
||
278 | 278 | protected function checkMergeRuleRegex(Request $request, array &$rules, string $url, bool $completeMatch) |
279 | 279 | { |
280 | 280 | $depr = $this->router->config('pathinfo_depr'); |
281 | - $url = $depr . str_replace('|', $depr, $url); |
|
281 | + $url = $depr.str_replace('|', $depr, $url); |
|
282 | 282 | $regex = []; |
283 | 283 | $items = []; |
284 | 284 | |
285 | 285 | foreach ($rules as $key => $val) { |
286 | 286 | $item = $val[1]; |
287 | 287 | if ($item instanceof RuleItem) { |
288 | - $rule = $depr . str_replace('/', $depr, $item->getRule()); |
|
288 | + $rule = $depr.str_replace('/', $depr, $item->getRule()); |
|
289 | 289 | if ($depr == $rule && $depr != $url) { |
290 | 290 | unset($rules[$key]); |
291 | 291 | continue; |
@@ -302,21 +302,21 @@ discard block |
||
302 | 302 | continue; |
303 | 303 | } |
304 | 304 | |
305 | - $slash = preg_quote('/-' . $depr, '/'); |
|
305 | + $slash = preg_quote('/-'.$depr, '/'); |
|
306 | 306 | |
307 | - if ($matchRule = preg_split('/[' . $slash . ']<\w+\??>/', $rule, 2)) { |
|
307 | + if ($matchRule = preg_split('/['.$slash.']<\w+\??>/', $rule, 2)) { |
|
308 | 308 | if ($matchRule[0] && 0 !== strncasecmp($rule, $url, strlen($matchRule[0]))) { |
309 | 309 | unset($rules[$key]); |
310 | 310 | continue; |
311 | 311 | } |
312 | 312 | } |
313 | 313 | |
314 | - if (preg_match_all('/[' . $slash . ']?<?\w+\??>?/', $rule, $matches)) { |
|
314 | + if (preg_match_all('/['.$slash.']?<?\w+\??>?/', $rule, $matches)) { |
|
315 | 315 | unset($rules[$key]); |
316 | 316 | $pattern = array_merge($this->getPattern(), $item->getPattern()); |
317 | 317 | $option = array_merge($this->getOption(), $item->getOption()); |
318 | 318 | |
319 | - $regex[$key] = $this->buildRuleRegex($rule, $matches[0], $pattern, $option, $complete, '_THINK_' . $key); |
|
319 | + $regex[$key] = $this->buildRuleRegex($rule, $matches[0], $pattern, $option, $complete, '_THINK_'.$key); |
|
320 | 320 | $items[$key] = $item; |
321 | 321 | } |
322 | 322 | } |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | } |
328 | 328 | |
329 | 329 | try { |
330 | - $result = preg_match('/^(?:' . implode('|', $regex) . ')/u', $url, $match); |
|
330 | + $result = preg_match('/^(?:'.implode('|', $regex).')/u', $url, $match); |
|
331 | 331 | } catch (\Exception $e) { |
332 | 332 | throw new Exception('route pattern error'); |
333 | 333 | } |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | |
345 | 345 | if (!isset($pos)) { |
346 | 346 | foreach ($regex as $key => $item) { |
347 | - if (0 === strpos(str_replace(['\/', '\-', '\\' . $depr], ['/', '-', $depr], $item), $match[0])) { |
|
347 | + if (0 === strpos(str_replace(['\/', '\-', '\\'.$depr], ['/', '-', $depr], $item), $match[0])) { |
|
348 | 348 | $pos = $key; |
349 | 349 | break; |
350 | 350 | } |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | * @access public |
374 | 374 | * @return RuleItem|null |
375 | 375 | */ |
376 | - public function getMissRule(): ? RuleItem |
|
376 | + public function getMissRule(): ? RuleItem |
|
377 | 377 | { |
378 | 378 | return $this->miss; |
379 | 379 | } |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | public function prefix(string $prefix) |
460 | 460 | { |
461 | 461 | if ($this->parent && $this->parent->getOption('prefix')) { |
462 | - $prefix = $this->parent->getOption('prefix') . $prefix; |
|
462 | + $prefix = $this->parent->getOption('prefix').$prefix; |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | return $this->setOption('prefix', $prefix); |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | return $this->rules; |
499 | 499 | } |
500 | 500 | |
501 | - return array_filter($this->rules, function ($item) use ($method) { |
|
501 | + return array_filter($this->rules, function($item) use ($method) { |
|
502 | 502 | return $method == $item[0] || $item[0] = '*'; |
503 | 503 | }); |
504 | 504 | } |