@@ -5,7 +5,7 @@ |
||
5 | 5 | * 可执行命令表达式 |
6 | 6 | * |
7 | 7 | */ |
8 | -class RouteMatcher { |
|
8 | +class RouteMatcher { |
|
9 | 9 | /** |
10 | 10 | * 匹配的URI |
11 | 11 | * |
@@ -35,9 +35,9 @@ discard block |
||
35 | 35 | * @param boolean $ignoreCase |
36 | 36 | * @return array|null |
37 | 37 | */ |
38 | - public function match(string $url, bool $ignoreCase = true):?array |
|
38 | + public function match(string $url, bool $ignoreCase = true): ?array |
|
39 | 39 | { |
40 | - $match = '#^'. $this->match.'$#'. ($ignoreCase?'i':''); |
|
40 | + $match = '#^'.$this->match.'$#'.($ignoreCase ? 'i' : ''); |
|
41 | 41 | if (preg_match($match, $url, $parameter)) { |
42 | 42 | array_shift($parameter); |
43 | 43 | return $parameter; |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | } else { |
61 | 61 | $value = $parameter->getDefaultValue(); |
62 | 62 | } |
63 | - $parameters[$parameter->getIndexName()] = $value; |
|
63 | + $parameters[$parameter->getIndexName()] = $value; |
|
64 | 64 | } |
65 | 65 | return $parameters; |
66 | 66 | } |
@@ -26,18 +26,18 @@ |
||
26 | 26 | // 参数 |
27 | 27 | $parameters = []; |
28 | 28 | // 转义正则 |
29 | - $url=preg_replace('/([\/\.\\\\\+\(\^\)\$\!\<\>\-\?\*])/', '\\\\$1', $uri); |
|
29 | + $url = preg_replace('/([\/\.\\\\\+\(\^\)\$\!\<\>\-\?\*])/', '\\\\$1', $uri); |
|
30 | 30 | // 添加忽略 |
31 | - $url=preg_replace('/(\[)([^\[\]]+)(?(1)\])/', '(?:$2)?', $url); |
|
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 = ''; |
39 | 39 | if (isset($match[2])) { |
40 | - if (strpos($match[2], '=')!==false) { |
|
40 | + if (strpos($match[2], '=') !== false) { |
|
41 | 41 | list($type, $extra) = \explode('=', $match[2]); |
42 | 42 | } else { |
43 | 43 | $type = $match[2]; |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | /** |
5 | 5 | * 匹配参数 |
6 | 6 | */ |
7 | -abstract class Parameter { |
|
7 | +abstract class Parameter { |
|
8 | 8 | |
9 | 9 | protected static $name; |
10 | 10 | /** |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | } |
26 | 26 | |
27 | 27 | public static function build(string $indexName, string $extra):Parameter { |
28 | - $parameter = new static($extra); |
|
28 | + $parameter = new static($extra); |
|
29 | 29 | $parameter->setIndexName($indexName); |
30 | 30 | return $parameter; |
31 | 31 | } |