@@ -26,18 +26,18 @@ discard block |
||
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]; |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | |
57 | 57 | public static function buildUri(UriMatcher $matcher, array $parameter, bool $allowQuery = true):string |
58 | 58 | { |
59 | - $uri = $matcher->getUri(); |
|
59 | + $uri = $matcher->getUri(); |
|
60 | 60 | $query = []; |
61 | 61 | $mapper = []; |
62 | 62 | |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | } |
71 | 71 | |
72 | 72 | // for * ? |
73 | - $url=\str_replace(['*','?'],['','-'], $uri); |
|
73 | + $url = \str_replace(['*', '?'], ['', '-'], $uri); |
|
74 | 74 | // for ignore value |
75 | - $url=preg_replace_callback('/\[(.+?)\]/', function ($match) use ($matcher, $parameter, $mapper) { |
|
75 | + $url = preg_replace_callback('/\[(.+?)\]/', function($match) use ($matcher, $parameter, $mapper) { |
|
76 | 76 | if (preg_match('/\{(\w+).+?\}/', $match[1])) { |
77 | 77 | $count = 0; |
78 | - $subUrl= static::replaceParameter($match[1], $matcher, $parameter, $mapper, $count); |
|
79 | - if ($count > 0 ){ |
|
78 | + $subUrl = static::replaceParameter($match[1], $matcher, $parameter, $mapper, $count); |
|
79 | + if ($count > 0) { |
|
80 | 80 | return $subUrl; |
81 | 81 | } |
82 | 82 | throw new Exception(sprintf('unknown parameter %s in %s', $key, $matcher->getUri()), 1); |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | } |
86 | 86 | }, $url); |
87 | 87 | |
88 | - $url= static::replaceParameter($url, $matcher, $parameter, $mapper); |
|
88 | + $url = static::replaceParameter($url, $matcher, $parameter, $mapper); |
|
89 | 89 | |
90 | 90 | if (count($query) && $allowQuery) { |
91 | 91 | return $url.'?'.http_build_query($query, 'v', '&', PHP_QUERY_RFC3986); |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | } |
95 | 95 | |
96 | 96 | |
97 | - protected static function replaceParameter(string $input,UriMatcher $matcher,array $parameter, array $mapper, ?int &$count=null) { |
|
98 | - return preg_replace_callback('/\{(\w+).+?\}/', function ($match) use ($matcher, $parameter, $mapper) { |
|
97 | + protected static function replaceParameter(string $input, UriMatcher $matcher, array $parameter, array $mapper, ?int &$count = null) { |
|
98 | + return preg_replace_callback('/\{(\w+).+?\}/', function($match) use ($matcher, $parameter, $mapper) { |
|
99 | 99 | if (\array_key_exists($match[1], $mapper)) { |
100 | 100 | return $mapper[$match[1]]->packValue($parameter[$match[1]]); |
101 | 101 | } |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | * @param boolean $ignoreCase |
46 | 46 | * @return array|null |
47 | 47 | */ |
48 | - public function match(string $url, bool $ignoreCase = true):?array |
|
48 | + public function match(string $url, bool $ignoreCase = true): ?array |
|
49 | 49 | { |
50 | - $match = '#^'. $this->match.'$#'. ($ignoreCase?'i':''); |
|
50 | + $match = '#^'.$this->match.'$#'.($ignoreCase ? 'i' : ''); |
|
51 | 51 | if (preg_match($match, $url, $parameter)) { |
52 | 52 | array_shift($parameter); |
53 | 53 | return $parameter; |
@@ -70,12 +70,12 @@ discard block |
||
70 | 70 | } else { |
71 | 71 | $value = $parameter->getDefaultValue(); |
72 | 72 | } |
73 | - $parameters[$parameter->getIndexName()] = $value; |
|
73 | + $parameters[$parameter->getIndexName()] = $value; |
|
74 | 74 | } |
75 | 75 | return $parameters; |
76 | 76 | } |
77 | 77 | |
78 | - public function getParameter(string $name):?Parameter { |
|
78 | + public function getParameter(string $name): ?Parameter { |
|
79 | 79 | foreach ($this->parameter as $parameter) { |
80 | 80 | if ($parameter->getIndexName() === $name) { |
81 | 81 | return $parameter; |