@@ -7,13 +7,13 @@ discard block |
||
7 | 7 | use Lead\Router\Exception\RouterException; |
8 | 8 | use Lead\Router\Host; |
9 | 9 | |
10 | -describe("Host", function () { |
|
10 | +describe("Host", function() { |
|
11 | 11 | |
12 | 12 | |
13 | - describe("->scheme()", function () { |
|
13 | + describe("->scheme()", function() { |
|
14 | 14 | |
15 | 15 | |
16 | - it("gets/sets the scheme", function () { |
|
16 | + it("gets/sets the scheme", function() { |
|
17 | 17 | |
18 | 18 | |
19 | 19 | $host = new Host(); |
@@ -22,10 +22,10 @@ discard block |
||
22 | 22 | expect($host->getScheme())->toBe('https'); |
23 | 23 | }); |
24 | 24 | }); |
25 | - describe("->pattern()", function () { |
|
25 | + describe("->pattern()", function() { |
|
26 | 26 | |
27 | 27 | |
28 | - it("gets/sets the pattern", function () { |
|
28 | + it("gets/sets the pattern", function() { |
|
29 | 29 | |
30 | 30 | |
31 | 31 | $host = new Host(); |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | 'domain' => false |
38 | 38 | ]); |
39 | 39 | }); |
40 | - it("updates the regex", function () { |
|
40 | + it("updates the regex", function() { |
|
41 | 41 | |
42 | 42 | |
43 | 43 | $host = new Host(); |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | expect($host->setPattern('foo.{domain}.baz'))->toBe($host); |
47 | 47 | expect($host->getRegex())->toBe('foo\\.([^.]+)\\.baz'); |
48 | 48 | }); |
49 | - it("updates the variables", function () { |
|
49 | + it("updates the variables", function() { |
|
50 | 50 | |
51 | 51 | |
52 | 52 | $host = new Host(); |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | ]); |
61 | 61 | }); |
62 | 62 | }); |
63 | - describe("->match()", function () { |
|
63 | + describe("->match()", function() { |
|
64 | 64 | |
65 | 65 | |
66 | - it("returns `true` when host & scheme matches", function () { |
|
66 | + it("returns `true` when host & scheme matches", function() { |
|
67 | 67 | |
68 | 68 | |
69 | 69 | $host = new Host(['pattern' => 'foo.{domain}.bar', 'scheme' => 'https']); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | expect($host->match(['scheme' => 'https', 'host' => 'biz.bar.baz'], $variables))->toBe(false); |
73 | 73 | expect($host->match(['scheme' => 'http', 'host' => 'foo.baz.bar'], $variables))->toBe(false); |
74 | 74 | }); |
75 | - it("returns `true` when host matches with a wildcard as host's scheme", function () { |
|
75 | + it("returns `true` when host matches with a wildcard as host's scheme", function() { |
|
76 | 76 | |
77 | 77 | |
78 | 78 | $host = new Host(['pattern' => 'foo.{domain}.bar', 'scheme' => 'https']); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | expect($variables)->toBe(['domain' => 'baz']); |
81 | 81 | expect($host->match(['scheme' => '*', 'host' => 'biz.baz.bar'], $variables))->toBe(false); |
82 | 82 | }); |
83 | - it("returns `true` when host matches with a wildcard as request's scheme", function () { |
|
83 | + it("returns `true` when host matches with a wildcard as request's scheme", function() { |
|
84 | 84 | |
85 | 85 | |
86 | 86 | $host = new Host(['pattern' => 'foo.{domain}.bar', 'scheme' => '*']); |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | expect($variables)->toBe(['domain' => 'baz']); |
89 | 89 | expect($host->match(['scheme' => 'https', 'host' => 'biz.baz.bar'], $variables))->toBe(false); |
90 | 90 | }); |
91 | - it("returns `true` when scheme matches with a wildcard as host's pattern", function () { |
|
91 | + it("returns `true` when scheme matches with a wildcard as host's pattern", function() { |
|
92 | 92 | |
93 | 93 | |
94 | 94 | $host = new Host(['pattern' => '*', 'scheme' => 'http']); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | expect($variables)->toBe([]); |
97 | 97 | expect($host->match(['scheme' => 'https', 'host' => 'foo.baz.bar'], $variables))->toBe(false); |
98 | 98 | }); |
99 | - it("returns `true` when scheme matches with a wildcard as request's pattern", function () { |
|
99 | + it("returns `true` when scheme matches with a wildcard as request's pattern", function() { |
|
100 | 100 | |
101 | 101 | |
102 | 102 | $host = new Host(['pattern' => 'foo.{domain}.bar', 'scheme' => 'http']); |
@@ -105,24 +105,24 @@ discard block |
||
105 | 105 | expect($host->match(['scheme' => 'https', 'host' => '*'], $variables))->toBe(false); |
106 | 106 | }); |
107 | 107 | }); |
108 | - describe("->link()", function () { |
|
108 | + describe("->link()", function() { |
|
109 | 109 | |
110 | 110 | |
111 | - it("builds an host link", function () { |
|
111 | + it("builds an host link", function() { |
|
112 | 112 | |
113 | 113 | |
114 | 114 | $host = new Host(['pattern' => 'www.{domain}.com', 'scheme' => 'https']); |
115 | 115 | $link = $host->link(['domain' => 'example']); |
116 | 116 | expect($link)->toBe('https://www.example.com'); |
117 | 117 | }); |
118 | - it("builds a scheme less host link", function () { |
|
118 | + it("builds a scheme less host link", function() { |
|
119 | 119 | |
120 | 120 | |
121 | 121 | $host = new Host(['pattern' => 'www.{domain}.com']); |
122 | 122 | $link = $host->link(['domain' => 'example']); |
123 | 123 | expect($link)->toBe('//www.example.com'); |
124 | 124 | }); |
125 | - it("overrides scheme when passed as parameter", function () { |
|
125 | + it("overrides scheme when passed as parameter", function() { |
|
126 | 126 | |
127 | 127 | |
128 | 128 | $host = new Host(['pattern' => 'www.{domain}.com']); |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | ]); |
132 | 132 | expect($link)->toBe('http://www.example.com'); |
133 | 133 | }); |
134 | - it("processes complex pattern", function () { |
|
134 | + it("processes complex pattern", function() { |
|
135 | 135 | |
136 | 136 | |
137 | 137 | $host = new Host(['pattern' => '[{subdomains}.]*{domain}.com', 'scheme' => 'https']); |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | 'domain' => 'example' |
146 | 146 | ]))->toBe('https://a.b.c.example.com'); |
147 | 147 | }); |
148 | - it("throws an exception when variables are missing", function () { |
|
148 | + it("throws an exception when variables are missing", function() { |
|
149 | 149 | |
150 | 150 | |
151 | - $closure = function () { |
|
151 | + $closure = function() { |
|
152 | 152 | |
153 | 153 | $host = new Host(['pattern' => 'www.{domain}.com']); |
154 | 154 | $link = $host->link(); |
@@ -7,13 +7,13 @@ discard block |
||
7 | 7 | use Lead\Router\Exception\ParserException; |
8 | 8 | use Lead\Router\Parser; |
9 | 9 | |
10 | -describe("Parser", function () { |
|
10 | +describe("Parser", function() { |
|
11 | 11 | |
12 | 12 | |
13 | - describe("::tokenize()", function () { |
|
13 | + describe("::tokenize()", function() { |
|
14 | 14 | |
15 | 15 | |
16 | - it("parses an empty url", function () { |
|
16 | + it("parses an empty url", function() { |
|
17 | 17 | |
18 | 18 | |
19 | 19 | $result = Parser::tokenize(''); |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | 'tokens' => [] |
26 | 26 | ]); |
27 | 27 | }); |
28 | - it("parses a static url", function () { |
|
28 | + it("parses a static url", function() { |
|
29 | 29 | |
30 | 30 | |
31 | 31 | $result = Parser::tokenize('/test'); |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | 'tokens' => ['/test'] |
38 | 38 | ]); |
39 | 39 | }); |
40 | - it("parses an url with a variable", function () { |
|
40 | + it("parses an url with a variable", function() { |
|
41 | 41 | |
42 | 42 | |
43 | 43 | $result = Parser::tokenize('/test/{param}'); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | ] |
56 | 56 | ]); |
57 | 57 | }); |
58 | - it("parses an url with several variables", function () { |
|
58 | + it("parses an url with several variables", function() { |
|
59 | 59 | |
60 | 60 | |
61 | 61 | $result = Parser::tokenize('/test/{param1}/test2/{param2}'); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | ] |
79 | 79 | ]); |
80 | 80 | }); |
81 | - it("parses an url with a variable with a custom regex", function () { |
|
81 | + it("parses an url with a variable with a custom regex", function() { |
|
82 | 82 | |
83 | 83 | |
84 | 84 | $result = Parser::tokenize('/test/{param:\d+}'); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | ] |
97 | 97 | ]); |
98 | 98 | }); |
99 | - it("parses an url with an optional segment", function () { |
|
99 | + it("parses an url with an optional segment", function() { |
|
100 | 100 | |
101 | 101 | |
102 | 102 | $result = Parser::tokenize('/test[opt]'); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | ] |
120 | 120 | ]); |
121 | 121 | }); |
122 | - it("parses an optional segment", function () { |
|
122 | + it("parses an optional segment", function() { |
|
123 | 123 | |
124 | 124 | |
125 | 125 | $result = Parser::tokenize('[test]'); |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | ] |
142 | 142 | ]); |
143 | 143 | }); |
144 | - it("parses an optional segment inside a route definition", function () { |
|
144 | + it("parses an optional segment inside a route definition", function() { |
|
145 | 145 | |
146 | 146 | |
147 | 147 | $result = Parser::tokenize('/test[/opt]/required'); |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | ] |
166 | 166 | ]); |
167 | 167 | }); |
168 | - it("parses an url with an optional variable", function () { |
|
168 | + it("parses an url with an optional variable", function() { |
|
169 | 169 | |
170 | 170 | |
171 | 171 | $result = Parser::tokenize('/test[/{param}]'); |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | ] |
193 | 193 | ]); |
194 | 194 | }); |
195 | - it("parses an url with a variable with a prefix and a suffix inside an optional segment", function () { |
|
195 | + it("parses an url with a variable with a prefix and a suffix inside an optional segment", function() { |
|
196 | 196 | |
197 | 197 | |
198 | 198 | $result = Parser::tokenize('/test[/:{param}:]'); |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | ] |
221 | 221 | ]); |
222 | 222 | }); |
223 | - it("parses an url with a variable and an optional segment", function () { |
|
223 | + it("parses an url with a variable and an optional segment", function() { |
|
224 | 224 | |
225 | 225 | |
226 | 226 | $result = Parser::tokenize('/{param}[opt]'); |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | ] |
248 | 248 | ]); |
249 | 249 | }); |
250 | - it("parses nested segments", function () { |
|
250 | + it("parses nested segments", function() { |
|
251 | 251 | |
252 | 252 | |
253 | 253 | $result = Parser::tokenize('/test[/{name}[/{id:[0-9]+}]]'); |
@@ -287,25 +287,25 @@ discard block |
||
287 | 287 | ] |
288 | 288 | ]); |
289 | 289 | }); |
290 | - it("throws an exception when there's a missing closing square bracket", function () { |
|
290 | + it("throws an exception when there's a missing closing square bracket", function() { |
|
291 | 291 | |
292 | 292 | |
293 | - $closure = function () { |
|
293 | + $closure = function() { |
|
294 | 294 | |
295 | 295 | Parser::tokenize('/test[opt'); |
296 | 296 | }; |
297 | 297 | expect($closure)->toThrow(ParserException::squareBracketMismatch()); |
298 | - $closure = function () { |
|
298 | + $closure = function() { |
|
299 | 299 | |
300 | 300 | Parser::tokenize('/test[opt[opt2]'); |
301 | 301 | }; |
302 | 302 | expect($closure)->toThrow(ParserException::squareBracketMismatch()); |
303 | 303 | }); |
304 | 304 | }); |
305 | - describe("::compile()", function () { |
|
305 | + describe("::compile()", function() { |
|
306 | 306 | |
307 | 307 | |
308 | - it("compiles a tokens structure", function () { |
|
308 | + it("compiles a tokens structure", function() { |
|
309 | 309 | |
310 | 310 | |
311 | 311 | $token = Parser::tokenize('/test[/{name}[/{id:[0-9]+}]]'); |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | '/test(?:/([^/]+)(?:/([0-9]+))?)?', ['name' => false, 'id' => false] |
315 | 315 | ]); |
316 | 316 | }); |
317 | - it("compiles a tokens structure with repeatable patterns", function () { |
|
317 | + it("compiles a tokens structure with repeatable patterns", function() { |
|
318 | 318 | |
319 | 319 | |
320 | 320 | $tokens = Parser::tokenize('/test[/{name}[/{id:[0-9]+}]*]'); |
@@ -323,28 +323,28 @@ discard block |
||
323 | 323 | '/test(?:/([^/]+)((?:/[0-9]+)*))?', ['name' => false, 'id' => '/{id:[0-9]+}'] |
324 | 324 | ]); |
325 | 325 | }); |
326 | - it("throws an exception when a placeholder is present several time", function () { |
|
326 | + it("throws an exception when a placeholder is present several time", function() { |
|
327 | 327 | |
328 | 328 | |
329 | - $closure = function () { |
|
329 | + $closure = function() { |
|
330 | 330 | |
331 | 331 | Parser::compile(Parser::tokenize('/test/{var}/{var}')); |
332 | 332 | }; |
333 | 333 | expect($closure)->toThrow(ParserException::duplicatePlaceholder('var')); |
334 | 334 | }); |
335 | - it("throws an exception when a placeholder is present several time through different segments", function () { |
|
335 | + it("throws an exception when a placeholder is present several time through different segments", function() { |
|
336 | 336 | |
337 | 337 | |
338 | - $closure = function () { |
|
338 | + $closure = function() { |
|
339 | 339 | |
340 | 340 | Parser::compile(Parser::tokenize('/test/{var}[/{var}]')); |
341 | 341 | }; |
342 | 342 | expect($closure)->toThrow(ParserException::duplicatePlaceholder('var')); |
343 | 343 | }); |
344 | - it("throws an exception when multiple placeholder are present in repeatable segments", function () { |
|
344 | + it("throws an exception when multiple placeholder are present in repeatable segments", function() { |
|
345 | 345 | |
346 | 346 | |
347 | - $closure = function () { |
|
347 | + $closure = function() { |
|
348 | 348 | |
349 | 349 | Parser::compile(Parser::tokenize('/test[/{var1}/{var2}]*')); |
350 | 350 | }; |
@@ -94,12 +94,12 @@ discard block |
||
94 | 94 | $scope = $this->scope; |
95 | 95 | |
96 | 96 | if (!empty($options['name'])) { |
97 | - $options['name'] = $scope['name'] ? $scope['name'] . '.' . $options['name'] : $options['name']; |
|
97 | + $options['name'] = $scope['name'] ? $scope['name'].'.'.$options['name'] : $options['name']; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | if (!empty($options['prefix'])) { |
101 | - $options['prefix'] = $scope['prefix'] . trim($options['prefix'], '/'); |
|
102 | - $options['prefix'] = $options['prefix'] ? $options['prefix'] . '/' : ''; |
|
101 | + $options['prefix'] = $scope['prefix'].trim($options['prefix'], '/'); |
|
102 | + $options['prefix'] = $options['prefix'] ? $options['prefix'].'/' : ''; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | if (isset($options['persist'])) { |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | } |
108 | 108 | |
109 | 109 | if (isset($options['namespace'])) { |
110 | - $options['namespace'] = $scope['namespace'] . trim($options['namespace'], '\\') . '\\'; |
|
110 | + $options['namespace'] = $scope['namespace'].trim($options['namespace'], '\\').'\\'; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | return $options + $scope; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | public static function tokenize(string $pattern, string $delimiter = '/'): array |
81 | 81 | { |
82 | 82 | // Checks if the pattern has some optional segments. |
83 | - if (count(preg_split('~' . static::PLACEHOLDER_REGEX . '(*SKIP)(*F)|\[~x', $pattern)) > 1) { |
|
83 | + if (count(preg_split('~'.static::PLACEHOLDER_REGEX.'(*SKIP)(*F)|\[~x', $pattern)) > 1) { |
|
84 | 84 | $tokens = static::_tokenizePattern($pattern, $delimiter); |
85 | 85 | } else { |
86 | 86 | $tokens = static::tokenizeSegment($pattern, $delimiter); |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | $tokens = []; |
144 | 144 | $index = 0; |
145 | 145 | $path = ''; |
146 | - if (preg_match_all('~' . static::PLACEHOLDER_REGEX . '()~x', $pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { |
|
146 | + if (preg_match_all('~'.static::PLACEHOLDER_REGEX.'()~x', $pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { |
|
147 | 147 | foreach ($matches as $match) { |
148 | 148 | $offset = $match[0][1]; |
149 | 149 | $path .= substr($pattern, $index, $offset - $index); |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | } |
155 | 155 | |
156 | 156 | $variable = $match[1][0]; |
157 | - $capture = $match[2][0] ?: '[^' . $delimiter . ']+'; |
|
157 | + $capture = $match[2][0] ?: '[^'.$delimiter.']+'; |
|
158 | 158 | $tokens[] = [ |
159 | 159 | 'name' => $variable, |
160 | 160 | 'pattern' => $capture |
@@ -259,9 +259,9 @@ discard block |
||
259 | 259 | if (count($rule[1]) > 1) { |
260 | 260 | throw ParserException::placeholderExceeded(); |
261 | 261 | } |
262 | - $regex .= '((?:' . $rule[0] . ')' . $child['greedy'] . ')'; |
|
262 | + $regex .= '((?:'.$rule[0].')'.$child['greedy'].')'; |
|
263 | 263 | } elseif ($child['optional']) { |
264 | - $regex .= '(?:' . $rule[0] . ')?'; |
|
264 | + $regex .= '(?:'.$rule[0].')?'; |
|
265 | 265 | } |
266 | 266 | foreach ($rule[1] as $name => $pattern) { |
267 | 267 | if (isset($variables[$name])) { |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | $regex .= $child['pattern']; |
280 | 280 | } else { |
281 | 281 | $variables[$name] = false; |
282 | - $regex .= '(' . $child['pattern'] . ')'; |
|
282 | + $regex .= '('.$child['pattern'].')'; |
|
283 | 283 | } |
284 | 284 | } |
285 | 285 | } |
@@ -70,12 +70,12 @@ |
||
70 | 70 | \} |
71 | 71 | EOD; |
72 | 72 | /** |
73 | - * Tokenizes a route pattern. Optional segments are identified by square brackets. |
|
74 | - * |
|
75 | - * @param string $pattern A route pattern |
|
76 | - * @param string $delimiter The path delimiter. |
|
77 | - * @return array |
|
78 | - */ |
|
73 | + * Tokenizes a route pattern. Optional segments are identified by square brackets. |
|
74 | + * |
|
75 | + * @param string $pattern A route pattern |
|
76 | + * @param string $delimiter The path delimiter. |
|
77 | + * @return array |
|
78 | + */ |
|
79 | 79 | public static function tokenize(string $pattern, string $delimiter = '/'): array |
80 | 80 | { |
81 | 81 | // Checks if the pattern has some optional segments. |
@@ -81,17 +81,17 @@ |
||
81 | 81 | public function match($request, &$variables = null, &$hostVariables = null): bool; |
82 | 82 | |
83 | 83 | /** |
84 | - * Returns the route's link. |
|
85 | - * |
|
86 | - * @param array $params The route parameters. |
|
87 | - * @param array $options Options for generating the proper prefix. Accepted values are: |
|
88 | - * - `'absolute'` _boolean_: `true` or `false`. - `'scheme'` |
|
89 | - * _string_ : The scheme. - `'host'` _string_ : The host |
|
90 | - * name. - `'basePath'` _string_ : The base path. - `'query'` |
|
91 | - * _string_ : The query string. - `'fragment'` _string_ : The |
|
92 | - * fragment string. |
|
93 | - * @return string The link. |
|
94 | - */ |
|
84 | + * Returns the route's link. |
|
85 | + * |
|
86 | + * @param array $params The route parameters. |
|
87 | + * @param array $options Options for generating the proper prefix. Accepted values are: |
|
88 | + * - `'absolute'` _boolean_: `true` or `false`. - `'scheme'` |
|
89 | + * _string_ : The scheme. - `'host'` _string_ : The host |
|
90 | + * name. - `'basePath'` _string_ : The base path. - `'query'` |
|
91 | + * _string_ : The query string. - `'fragment'` _string_ : The |
|
92 | + * fragment string. |
|
93 | + * @return string The link. |
|
94 | + */ |
|
95 | 95 | public function link(array $params = [], array $options = []): string; |
96 | 96 | |
97 | 97 | /** |
@@ -11,13 +11,13 @@ discard block |
||
11 | 11 | use Lead\Router\Router; |
12 | 12 | use Lead\Router\Route; |
13 | 13 | |
14 | -describe("Route", function () { |
|
14 | +describe("Route", function() { |
|
15 | 15 | |
16 | 16 | |
17 | - describe("->pattern()", function () { |
|
17 | + describe("->pattern()", function() { |
|
18 | 18 | |
19 | 19 | |
20 | - it("gets/sets the pattern", function () { |
|
20 | + it("gets/sets the pattern", function() { |
|
21 | 21 | |
22 | 22 | |
23 | 23 | $route = new Route(); |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | 'paths' => '/{paths}' |
30 | 30 | ]); |
31 | 31 | }); |
32 | - it("updates the regex", function () { |
|
32 | + it("updates the regex", function() { |
|
33 | 33 | |
34 | 34 | |
35 | 35 | $route = new Route(); |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | expect($route->setPattern('/foo/baz/{id}[/{paths}]*'))->toBe($route); |
39 | 39 | expect($route->Regex())->toBe('/foo/baz/([^/]+)((?:/[^/]+)*)'); |
40 | 40 | }); |
41 | - it("updates the variables", function () { |
|
41 | + it("updates the variables", function() { |
|
42 | 42 | |
43 | 43 | |
44 | 44 | $route = new Route(); |
@@ -54,10 +54,10 @@ discard block |
||
54 | 54 | ]); |
55 | 55 | }); |
56 | 56 | }); |
57 | - describe("->scope()", function () { |
|
57 | + describe("->scope()", function() { |
|
58 | 58 | |
59 | 59 | |
60 | - it("gets/sets route scope", function () { |
|
60 | + it("gets/sets route scope", function() { |
|
61 | 61 | |
62 | 62 | |
63 | 63 | $scope = new Scope(); |
@@ -66,17 +66,17 @@ discard block |
||
66 | 66 | expect($route->Scope())->toBe($scope); |
67 | 67 | }); |
68 | 68 | }); |
69 | - describe("->methods()", function () { |
|
69 | + describe("->methods()", function() { |
|
70 | 70 | |
71 | 71 | |
72 | - it("gets/sets route methods", function () { |
|
72 | + it("gets/sets route methods", function() { |
|
73 | 73 | |
74 | 74 | |
75 | 75 | $route = new Route(); |
76 | 76 | expect($route->setMethods(['POST', 'PUT']))->toBe($route); |
77 | 77 | expect($route->Methods())->toBe(['POST', 'PUT']); |
78 | 78 | }); |
79 | - it("formats method names", function () { |
|
79 | + it("formats method names", function() { |
|
80 | 80 | |
81 | 81 | |
82 | 82 | $route = new Route(); |
@@ -84,17 +84,17 @@ discard block |
||
84 | 84 | expect($route->Methods())->toBe(['POST', 'PUT']); |
85 | 85 | }); |
86 | 86 | }); |
87 | - describe("->allow()", function () { |
|
87 | + describe("->allow()", function() { |
|
88 | 88 | |
89 | 89 | |
90 | - it("adds some extra allowed methods", function () { |
|
90 | + it("adds some extra allowed methods", function() { |
|
91 | 91 | |
92 | 92 | |
93 | 93 | $route = new Route(['methods' => []]); |
94 | 94 | expect($route->allow(['POST', 'PUT']))->toBe($route); |
95 | 95 | expect($route->Methods())->toBe(['POST', 'PUT']); |
96 | 96 | }); |
97 | - it("formats newly allowed method names", function () { |
|
97 | + it("formats newly allowed method names", function() { |
|
98 | 98 | |
99 | 99 | |
100 | 100 | $route = new Route(['methods' => []]); |
@@ -102,39 +102,39 @@ discard block |
||
102 | 102 | expect($route->Methods())->toBe(['POST', 'PUT']); |
103 | 103 | }); |
104 | 104 | }); |
105 | - describe("->apply()", function () { |
|
105 | + describe("->apply()", function() { |
|
106 | 106 | |
107 | 107 | |
108 | - it("applies middlewares", function () { |
|
108 | + it("applies middlewares", function() { |
|
109 | 109 | |
110 | 110 | |
111 | 111 | $r = new Router(); |
112 | - $route = $r->bind('foo/bar', function ($route) { |
|
112 | + $route = $r->bind('foo/bar', function($route) { |
|
113 | 113 | |
114 | 114 | return 'A'; |
115 | - })->apply(function ($request, $response, $next) { |
|
115 | + })->apply(function($request, $response, $next) { |
|
116 | 116 | |
117 | - return '1' . $next() . '1'; |
|
118 | - })->apply(function ($request, $response, $next) { |
|
117 | + return '1'.$next().'1'; |
|
118 | + })->apply(function($request, $response, $next) { |
|
119 | 119 | |
120 | - return '2' . $next() . '2'; |
|
120 | + return '2'.$next().'2'; |
|
121 | 121 | }); |
122 | 122 | $route = $r->route('foo/bar'); |
123 | 123 | $actual = $route->dispatch(); |
124 | 124 | expect($actual)->toBe('21A12'); |
125 | 125 | }); |
126 | 126 | }); |
127 | - describe("->link()", function () { |
|
127 | + describe("->link()", function() { |
|
128 | 128 | |
129 | 129 | |
130 | - it("creates relative links", function () { |
|
130 | + it("creates relative links", function() { |
|
131 | 131 | |
132 | 132 | |
133 | 133 | $route = new Route(['pattern' => '/foo/{bar}']); |
134 | 134 | $link = $route->link(['bar' => 'baz']); |
135 | 135 | expect($link)->toBe('/foo/baz'); |
136 | 136 | }); |
137 | - it("supports optionnal parameters", function () { |
|
137 | + it("supports optionnal parameters", function() { |
|
138 | 138 | |
139 | 139 | |
140 | 140 | $route = new Route(['pattern' => '/foo[/{bar}]']); |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | $link = $route->link(['bar' => 'baz']); |
144 | 144 | expect($link)->toBe('/foo/baz'); |
145 | 145 | }); |
146 | - it("supports multiple optionnal parameters", function () { |
|
146 | + it("supports multiple optionnal parameters", function() { |
|
147 | 147 | |
148 | 148 | |
149 | 149 | $route = new Route(['pattern' => '/file[/{paths}]*']); |
@@ -152,14 +152,14 @@ discard block |
||
152 | 152 | $link = $route->link(['paths' => ['some', 'file', 'path']]); |
153 | 153 | expect($link)->toBe('/file/some/file/path'); |
154 | 154 | }); |
155 | - it("merges default params", function () { |
|
155 | + it("merges default params", function() { |
|
156 | 156 | |
157 | 157 | |
158 | 158 | $route = new Route(['pattern' => '/foo/{bar}', 'params' => ['bar' => 'baz']]); |
159 | 159 | $link = $route->link(); |
160 | 160 | expect($link)->toBe('/foo/baz'); |
161 | 161 | }); |
162 | - it("creates absolute links with custom base path", function () { |
|
162 | + it("creates absolute links with custom base path", function() { |
|
163 | 163 | |
164 | 164 | |
165 | 165 | $route = new Route([ |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | ]); |
177 | 177 | expect($link)->toBe('https://www.example.com/app/foo/baz'); |
178 | 178 | }); |
179 | - it("allows host and scheme overriding", function () { |
|
179 | + it("allows host and scheme overriding", function() { |
|
180 | 180 | |
181 | 181 | |
182 | 182 | $route = new Route([ |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | ]); |
196 | 196 | expect($link)->toBe('http://www.overrided.com/app/foo/baz'); |
197 | 197 | }); |
198 | - it("supports repeatable parameter placeholders as an array", function () { |
|
198 | + it("supports repeatable parameter placeholders as an array", function() { |
|
199 | 199 | |
200 | 200 | |
201 | 201 | $route = new Route(['pattern' => 'post[/{id}]*']); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | expect($route->link(['id' => ['123']]))->toBe('/post/123'); |
208 | 208 | expect($route->link(['id' => ['123', '456', '789']]))->toBe('/post/123/456/789'); |
209 | 209 | }); |
210 | - it("supports route with multiple optional segments", function () { |
|
210 | + it("supports route with multiple optional segments", function() { |
|
211 | 211 | |
212 | 212 | |
213 | 213 | $route = new Route(['pattern' => '[{relation}/{rid:[^/:][^/]*}/]post[/{id:[^/:][^/]*}][/:{action}]']); |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | $link = $route->link(['relation' => 'user', 'rid' => 5, 'action' => 'edit', 'id' => 12]); |
223 | 223 | expect($link)->toBe('/user/5/post/12/:edit'); |
224 | 224 | }); |
225 | - it("supports route with complex repeatable optional segments", function () { |
|
225 | + it("supports route with complex repeatable optional segments", function() { |
|
226 | 226 | |
227 | 227 | |
228 | 228 | $route = new Route(['pattern' => '[{relations:[^/]+/[^/:][^/]*}/]*post[/{id:[^/:][^/]*}][/:{action}]']); |
@@ -237,40 +237,40 @@ discard block |
||
237 | 237 | $link = $route->link(['relations' => [['user', 5]], 'action' => 'edit', 'id' => 12]); |
238 | 238 | expect($link)->toBe('/user/5/post/12/:edit'); |
239 | 239 | }); |
240 | - it("throws an exception for missing variables", function () { |
|
240 | + it("throws an exception for missing variables", function() { |
|
241 | 241 | |
242 | 242 | |
243 | - $closure = function () { |
|
243 | + $closure = function() { |
|
244 | 244 | |
245 | 245 | $route = new Route(['pattern' => 'post[/{id}]+']); |
246 | 246 | echo $route->link([]); |
247 | 247 | }; |
248 | 248 | expect($closure)->toThrow(new RouterException("Missing parameters `'id'` for route: `'#/post[/{id}]+'`.")); |
249 | 249 | }); |
250 | - it("throws an exception when a variable doesn't match its capture pattern", function () { |
|
250 | + it("throws an exception when a variable doesn't match its capture pattern", function() { |
|
251 | 251 | |
252 | 252 | |
253 | - $closure = function () { |
|
253 | + $closure = function() { |
|
254 | 254 | |
255 | 255 | $route = new Route(['pattern' => 'post/{id:[0-9]{3}}']); |
256 | 256 | $route->link(['id' => '1234']); |
257 | 257 | }; |
258 | 258 | expect($closure)->toThrow(new RouterException("Expected `'id'` to match `'[0-9]{3}'`, but received `'1234'`.")); |
259 | 259 | }); |
260 | - it("throws an exception when a an array is provided for a non repeatable parameter placeholder", function () { |
|
260 | + it("throws an exception when a an array is provided for a non repeatable parameter placeholder", function() { |
|
261 | 261 | |
262 | 262 | |
263 | - $closure = function () { |
|
263 | + $closure = function() { |
|
264 | 264 | |
265 | 265 | $route = new Route(['pattern' => 'post/{id}']); |
266 | 266 | $route->link(['id' => ['123', '456']]); |
267 | 267 | }; |
268 | 268 | expect($closure)->toThrow(new RouterException("Expected `'id'` to match `'[^/]+'`, but received `'123/456'`.")); |
269 | 269 | }); |
270 | - it("throws an exception when one element of an array doesn't match the capture pattern", function () { |
|
270 | + it("throws an exception when one element of an array doesn't match the capture pattern", function() { |
|
271 | 271 | |
272 | 272 | |
273 | - $closure = function () { |
|
273 | + $closure = function() { |
|
274 | 274 | |
275 | 275 | $route = new Route(['pattern' => 'post[/{id:[0-9]{3}}]+']); |
276 | 276 | $route->link(['id' => ['123', '456', '78']]); |
@@ -278,17 +278,17 @@ discard block |
||
278 | 278 | expect($closure)->toThrow(new RouterException("Expected `'id'` to match `'[0-9]{3}'`, but received `'78'`.")); |
279 | 279 | }); |
280 | 280 | }); |
281 | - describe("->dispatch()", function () { |
|
281 | + describe("->dispatch()", function() { |
|
282 | 282 | |
283 | 283 | |
284 | - it("passes route as argument of the handler function", function () { |
|
284 | + it("passes route as argument of the handler function", function() { |
|
285 | 285 | |
286 | 286 | |
287 | 287 | $r = new Router(); |
288 | 288 | $r->get( |
289 | 289 | 'foo/{var1}[/{var2}]', |
290 | 290 | ['host' => '{subdomain}.{domain}.bar'], |
291 | - function ($route, $response) { |
|
291 | + function($route, $response) { |
|
292 | 292 | |
293 | 293 | return array_merge([$response], array_values($route->params)); |
294 | 294 | } |
@@ -301,13 +301,13 @@ discard block |
||
301 | 301 | $actual = $route->dispatch($response); |
302 | 302 | expect($actual)->toBe([$response, 'foo', 'biz', '25', 'bar']); |
303 | 303 | }); |
304 | - it("throws an exception on non valid routes", function () { |
|
304 | + it("throws an exception on non valid routes", function() { |
|
305 | 305 | |
306 | 306 | |
307 | - $closure = function () { |
|
307 | + $closure = function() { |
|
308 | 308 | |
309 | 309 | $r = new Router(); |
310 | - $r->get('foo', function () { |
|
310 | + $r->get('foo', function() { |
|
311 | 311 | }); |
312 | 312 | $route = $r->route('bar'); |
313 | 313 | $route->dispatch(); |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | public function setBasePath(string $basePath): self |
184 | 184 | { |
185 | 185 | $basePath = trim($basePath, '/'); |
186 | - $this->basePath = $basePath ? '/' . $basePath : ''; |
|
186 | + $this->basePath = $basePath ? '/'.$basePath : ''; |
|
187 | 187 | return $this; |
188 | 188 | } |
189 | 189 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | $options['host'] = $this->hosts[$scheme][$host]; |
221 | 221 | } |
222 | 222 | |
223 | - $patternKey = md5($options['pattern'] . '-' . $options['name']); |
|
223 | + $patternKey = md5($options['pattern'].'-'.$options['name']); |
|
224 | 224 | if (isset($this->pattern[$scheme][$host][$patternKey])) { |
225 | 225 | $route = $this->pattern[$scheme][$host][$patternKey]; |
226 | 226 | } else { |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | $options['host'] = $this->hosts[$scheme][$host]; |
281 | 281 | } |
282 | 282 | |
283 | - $patternKey = md5($options['pattern'] . '-' . $options['name']); |
|
283 | + $patternKey = md5($options['pattern'].'-'.$options['name']); |
|
284 | 284 | if (isset($this->pattern[$scheme][$host][$patternKey])) { |
285 | 285 | $instance = $this->pattern[$scheme][$host][$patternKey]; |
286 | 286 | } else { |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | $this->pattern[$scheme][$host][$patternKey] = $instance; |
294 | 294 | } |
295 | 295 | |
296 | - $methods = $options['methods'] ? (array)$options['methods'] : []; |
|
296 | + $methods = $options['methods'] ? (array) $options['methods'] : []; |
|
297 | 297 | $instance->allow($methods); |
298 | 298 | foreach ($methods as $method) { |
299 | 299 | $this->routes[$scheme][$host][strtoupper($method)][] = $instance; |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | $request = $parsed + $request; |
412 | 412 | } |
413 | 413 | |
414 | - $request['path'] = (ltrim((string)strtok($request['path'], '?'), '/')); |
|
414 | + $request['path'] = (ltrim((string) strtok($request['path'], '?'), '/')); |
|
415 | 415 | $request['method'] = strtoupper($request['method']); |
416 | 416 | |
417 | 417 | return $request; |
@@ -12,32 +12,32 @@ discard block |
||
12 | 12 | use Psr\Http\Message\ServerRequestInterface; |
13 | 13 | use Psr\Http\Message\UriInterface; |
14 | 14 | |
15 | -describe("Router", function () { |
|
15 | +describe("Router", function() { |
|
16 | 16 | |
17 | 17 | |
18 | - beforeEach(function () { |
|
18 | + beforeEach(function() { |
|
19 | 19 | |
20 | 20 | |
21 | 21 | $this->router = new Router(); |
22 | - $this->export = function ($request) { |
|
22 | + $this->export = function($request) { |
|
23 | 23 | |
24 | 24 | return array_intersect_key($request, array_fill_keys(['path', 'method', 'host', 'scheme'], true)); |
25 | 25 | }; |
26 | 26 | }); |
27 | - describe("->__construct()", function () { |
|
27 | + describe("->__construct()", function() { |
|
28 | 28 | |
29 | 29 | |
30 | - it("formats the basePath", function () { |
|
30 | + it("formats the basePath", function() { |
|
31 | 31 | |
32 | 32 | |
33 | 33 | $router = new Router(['basePath' => '/']); |
34 | 34 | expect($router->getBasePath())->toBe(''); |
35 | 35 | }); |
36 | 36 | }); |
37 | - describe("->getBasePath()", function () { |
|
37 | + describe("->getBasePath()", function() { |
|
38 | 38 | |
39 | 39 | |
40 | - it("sets an empty basePath", function () { |
|
40 | + it("sets an empty basePath", function() { |
|
41 | 41 | |
42 | 42 | |
43 | 43 | expect($this->router->setBasePath('/'))->toBe($this->router); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | expect($this->router->setBasePath(''))->toBe($this->router); |
46 | 46 | expect($this->router->getBasePath())->toBe(''); |
47 | 47 | }); |
48 | - it("adds an leading slash for non empty basePath", function () { |
|
48 | + it("adds an leading slash for non empty basePath", function() { |
|
49 | 49 | |
50 | 50 | |
51 | 51 | expect($this->router->setBasePath('app'))->toBe($this->router); |
@@ -54,24 +54,24 @@ discard block |
||
54 | 54 | expect($this->router->getBasePath())->toBe('/base'); |
55 | 55 | }); |
56 | 56 | }); |
57 | - describe("->bind()", function () { |
|
57 | + describe("->bind()", function() { |
|
58 | 58 | |
59 | 59 | |
60 | - it("binds a named route", function () { |
|
60 | + it("binds a named route", function() { |
|
61 | 61 | |
62 | 62 | |
63 | 63 | $r = $this->router; |
64 | - $route = $r->bind('foo/bar', ['name' => 'foo'], function () { |
|
64 | + $route = $r->bind('foo/bar', ['name' => 'foo'], function() { |
|
65 | 65 | return 'hello'; |
66 | 66 | }); |
67 | 67 | expect(isset($r['foo']))->toBe(true); |
68 | 68 | expect($r['foo'])->toBe($route); |
69 | 69 | }); |
70 | - it("matches on methods", function () { |
|
70 | + it("matches on methods", function() { |
|
71 | 71 | |
72 | 72 | |
73 | 73 | $r = $this->router; |
74 | - $r->bind('foo/bar', ['methods' => ['POST', 'PUT']], function () { |
|
74 | + $r->bind('foo/bar', ['methods' => ['POST', 'PUT']], function() { |
|
75 | 75 | }); |
76 | 76 | $route = $r->route('foo/bar', 'POST'); |
77 | 77 | expect($route->Methods())->toBe(['POST', 'PUT']); |
@@ -83,11 +83,11 @@ discard block |
||
83 | 83 | expect($e->getMessage())->toBe("No route found for `*:*:GET:/bar/foo`."); |
84 | 84 | } |
85 | 85 | }); |
86 | - it("supports lowercase method names", function () { |
|
86 | + it("supports lowercase method names", function() { |
|
87 | 87 | |
88 | 88 | |
89 | 89 | $r = $this->router; |
90 | - $r->bind('foo/bar', ['methods' => ['POST', 'PUT']], function () { |
|
90 | + $r->bind('foo/bar', ['methods' => ['POST', 'PUT']], function() { |
|
91 | 91 | }); |
92 | 92 | $route = $r->route('foo/bar', 'post'); |
93 | 93 | expect($route->Methods())->toBe(['POST', 'PUT']); |
@@ -99,52 +99,52 @@ discard block |
||
99 | 99 | expect($e->getMessage())->toBe("No route found for `*:*:GET:/bar/foo`."); |
100 | 100 | } |
101 | 101 | }); |
102 | - it("matches on same path different methods", function () { |
|
102 | + it("matches on same path different methods", function() { |
|
103 | 103 | |
104 | 104 | $r = $this->router; |
105 | - $r->bind('foo/bar', ['name' => 'foo', 'methods' => ['POST']], function () { |
|
105 | + $r->bind('foo/bar', ['name' => 'foo', 'methods' => ['POST']], function() { |
|
106 | 106 | }); |
107 | - $r->bind('foo/bar', ['name' => 'bar', 'methods' => ['PUT']], function () { |
|
107 | + $r->bind('foo/bar', ['name' => 'bar', 'methods' => ['PUT']], function() { |
|
108 | 108 | }); |
109 | 109 | $route = $r->route('foo/bar', 'POST'); |
110 | 110 | expect($route->name)->toBe('foo'); |
111 | 111 | $route = $r->route('foo/bar', 'PUT'); |
112 | 112 | expect($route->name)->toBe('bar'); |
113 | 113 | }); |
114 | - it("throws an exception when the handler is not a closure", function () { |
|
114 | + it("throws an exception when the handler is not a closure", function() { |
|
115 | 115 | |
116 | 116 | |
117 | - $closure = function () { |
|
117 | + $closure = function() { |
|
118 | 118 | |
119 | 119 | $r = $this->router; |
120 | 120 | $r->bind('foo', 'substr'); |
121 | 121 | }; |
122 | 122 | expect($closure)->toThrow(new RouterException("The handler needs to be an instance of `Closure` or implements the `__invoke()` magic method.")); |
123 | 123 | }); |
124 | - it("throws an exception when trying to use the `'method'` option", function () { |
|
124 | + it("throws an exception when trying to use the `'method'` option", function() { |
|
125 | 125 | |
126 | 126 | |
127 | - $closure = function () { |
|
127 | + $closure = function() { |
|
128 | 128 | |
129 | 129 | $r = $this->router; |
130 | - $r->bind('foo', ['method' => 'GET'], function () { |
|
130 | + $r->bind('foo', ['method' => 'GET'], function() { |
|
131 | 131 | }); |
132 | 132 | }; |
133 | 133 | expect($closure)->toThrow(new RouterException("Use the `'methods'` option to limit HTTP verbs on a route binding definition.")); |
134 | 134 | }); |
135 | 135 | }); |
136 | - describe("->link()", function () { |
|
136 | + describe("->link()", function() { |
|
137 | 137 | |
138 | 138 | |
139 | - it("forwards router base path", function () { |
|
139 | + it("forwards router base path", function() { |
|
140 | 140 | |
141 | 141 | |
142 | 142 | $r = $this->router; |
143 | 143 | $r->basePath('app'); |
144 | 144 | |
145 | - $r->group(['host' => 'www.{domain}.com', 'scheme' => 'https'], function ($r) { |
|
145 | + $r->group(['host' => 'www.{domain}.com', 'scheme' => 'https'], function($r) { |
|
146 | 146 | |
147 | - $r->bind('foo/{bar}', ['name' => 'foo'], function () { |
|
147 | + $r->bind('foo/{bar}', ['name' => 'foo'], function() { |
|
148 | 148 | }); |
149 | 149 | }); |
150 | 150 | $link = $r->link('foo', [ |
@@ -153,28 +153,28 @@ discard block |
||
153 | 153 | ], ['absolute' => true]); |
154 | 154 | expect($link)->toBe('https://www.example.com/app/foo/baz'); |
155 | 155 | }); |
156 | - it("maintains prefixes in nested routes", function () { |
|
156 | + it("maintains prefixes in nested routes", function() { |
|
157 | 157 | |
158 | 158 | |
159 | 159 | $r = $this->router; |
160 | - $r->group('foo', ['name' => 'foz'], function ($r) { |
|
160 | + $r->group('foo', ['name' => 'foz'], function($r) { |
|
161 | 161 | |
162 | - $r->group('bar', ['name' => 'baz'], function ($r) { |
|
162 | + $r->group('bar', ['name' => 'baz'], function($r) { |
|
163 | 163 | |
164 | - $r->bind('{var1}', ['name' => 'quz'], function () { |
|
164 | + $r->bind('{var1}', ['name' => 'quz'], function() { |
|
165 | 165 | }); |
166 | 166 | }); |
167 | 167 | }); |
168 | 168 | $link = $r->link('foz.baz.quz', ['var1' => 'hello']); |
169 | 169 | expect($link)->toBe('/foo/bar/hello'); |
170 | 170 | }); |
171 | - it("persists persisted parameters in a dispatching context", function () { |
|
171 | + it("persists persisted parameters in a dispatching context", function() { |
|
172 | 172 | |
173 | 173 | |
174 | 174 | $r = $this->router; |
175 | - $r->group('{locale:en|fr}', ['persist' => 'locale'], function ($r) { |
|
175 | + $r->group('{locale:en|fr}', ['persist' => 'locale'], function($r) { |
|
176 | 176 | |
177 | - $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function () { |
|
177 | + $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function() { |
|
178 | 178 | }); |
179 | 179 | }); |
180 | 180 | $r->route('fr/post/index'); |
@@ -192,13 +192,13 @@ discard block |
||
192 | 192 | ]); |
193 | 193 | expect($link)->toBe('/en/post/view/5'); |
194 | 194 | }); |
195 | - it("overrides persisted parameters in a dispatching context", function () { |
|
195 | + it("overrides persisted parameters in a dispatching context", function() { |
|
196 | 196 | |
197 | 197 | |
198 | 198 | $r = $this->router; |
199 | - $r->group('{locale:en|fr}', ['persist' => 'locale'], function ($r) { |
|
199 | + $r->group('{locale:en|fr}', ['persist' => 'locale'], function($r) { |
|
200 | 200 | |
201 | - $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function () { |
|
201 | + $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function() { |
|
202 | 202 | }); |
203 | 203 | }); |
204 | 204 | $r->route('fr/post/index'); |
@@ -210,24 +210,24 @@ discard block |
||
210 | 210 | ]); |
211 | 211 | expect($link)->toBe('/en/post/view/5'); |
212 | 212 | }); |
213 | - it("throws an exception when no route is found for a specified name", function () { |
|
213 | + it("throws an exception when no route is found for a specified name", function() { |
|
214 | 214 | |
215 | 215 | |
216 | - $closure = function () { |
|
216 | + $closure = function() { |
|
217 | 217 | |
218 | 218 | $this->router->link('not.binded.yet', []); |
219 | 219 | }; |
220 | 220 | expect($closure)->toThrow(new RouterException("No binded route defined for `'not.binded.yet'`, bind it first with `bind()`.")); |
221 | 221 | }); |
222 | 222 | }); |
223 | - describe("->route()", function () { |
|
223 | + describe("->route()", function() { |
|
224 | 224 | |
225 | 225 | |
226 | - it("routes on a simple route", function () { |
|
226 | + it("routes on a simple route", function() { |
|
227 | 227 | |
228 | 228 | |
229 | 229 | $r = $this->router; |
230 | - $r->bind('foo/bar', function () { |
|
230 | + $r->bind('foo/bar', function() { |
|
231 | 231 | }); |
232 | 232 | $route = $r->route('foo/bar', 'GET'); |
233 | 233 | expect($this->export($route->request))->toEqual([ |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | expect($e->getMessage())->toBe("No route found for `*:*:GET:/bar/foo`."); |
243 | 243 | } |
244 | 244 | }); |
245 | - it("routes on a named route", function () { |
|
245 | + it("routes on a named route", function() { |
|
246 | 246 | |
247 | 247 | |
248 | 248 | $r = $this->router; |
249 | - $r->bind('foo/bar', ['name' => 'foo'], function () { |
|
249 | + $r->bind('foo/bar', ['name' => 'foo'], function() { |
|
250 | 250 | }); |
251 | 251 | $route = $r->route('foo/bar', 'GET'); |
252 | 252 | expect($route->name)->toBe('foo'); |
@@ -256,11 +256,11 @@ discard block |
||
256 | 256 | expect($e->getMessage())->toBe("No route found for `*:*:GET:/bar/foo`."); |
257 | 257 | } |
258 | 258 | }); |
259 | - it("supports empty as index route", function () { |
|
259 | + it("supports empty as index route", function() { |
|
260 | 260 | |
261 | 261 | |
262 | 262 | $r = $this->router; |
263 | - $r->bind('', function () { |
|
263 | + $r->bind('', function() { |
|
264 | 264 | }); |
265 | 265 | $route = $r->route('', 'GET'); |
266 | 266 | expect($this->export($route->request))->toEqual([ |
@@ -270,11 +270,11 @@ discard block |
||
270 | 270 | 'path' => '' |
271 | 271 | ]); |
272 | 272 | }); |
273 | - it("supports a slash as indes route", function () { |
|
273 | + it("supports a slash as indes route", function() { |
|
274 | 274 | |
275 | 275 | |
276 | 276 | $r = $this->router; |
277 | - $r->bind('/', function () { |
|
277 | + $r->bind('/', function() { |
|
278 | 278 | }); |
279 | 279 | $route = $r->route('', 'GET'); |
280 | 280 | expect($this->export($route->request))->toEqual([ |
@@ -284,11 +284,11 @@ discard block |
||
284 | 284 | 'path' => '' |
285 | 285 | ]); |
286 | 286 | }); |
287 | - it("supports route variables", function () { |
|
287 | + it("supports route variables", function() { |
|
288 | 288 | |
289 | 289 | |
290 | 290 | $r = $this->router; |
291 | - $r->get('foo/{param}', function () { |
|
291 | + $r->get('foo/{param}', function() { |
|
292 | 292 | }); |
293 | 293 | $route = $r->route('foo/bar', 'GET'); |
294 | 294 | expect($route->params)->toBe(['param' => 'bar']); |
@@ -298,11 +298,11 @@ discard block |
||
298 | 298 | expect($e->getMessage())->toBe("No route found for `*:*:GET:/bar/foo`."); |
299 | 299 | } |
300 | 300 | }); |
301 | - it("supports constrained route variables", function () { |
|
301 | + it("supports constrained route variables", function() { |
|
302 | 302 | |
303 | 303 | |
304 | 304 | $r = $this->router; |
305 | - $r->get('foo/{var1:\d+}', function () { |
|
305 | + $r->get('foo/{var1:\d+}', function() { |
|
306 | 306 | }); |
307 | 307 | $route = $r->route('foo/25', 'GET'); |
308 | 308 | expect($route->params)->toBe(['var1' => '25']); |
@@ -312,22 +312,22 @@ discard block |
||
312 | 312 | expect($e->getMessage())->toBe("No route found for `*:*:GET:/foo/bar`."); |
313 | 313 | } |
314 | 314 | }); |
315 | - it("supports optional segments with variables", function () { |
|
315 | + it("supports optional segments with variables", function() { |
|
316 | 316 | |
317 | 317 | |
318 | 318 | $r = $this->router; |
319 | - $r->get('foo[/{var1}]', function () { |
|
319 | + $r->get('foo[/{var1}]', function() { |
|
320 | 320 | }); |
321 | 321 | $route = $r->route('foo', 'GET'); |
322 | 322 | expect($route->params)->toBe(['var1' => null]); |
323 | 323 | $route = $r->route('foo/bar', 'GET'); |
324 | 324 | expect($route->params)->toBe(['var1' => 'bar']); |
325 | 325 | }); |
326 | - it("supports repeatable segments", function () { |
|
326 | + it("supports repeatable segments", function() { |
|
327 | 327 | |
328 | 328 | |
329 | 329 | $r = $this->router; |
330 | - $r->get('foo[/:{var1}]*[/bar[/:{var2}]*]', function () { |
|
330 | + $r->get('foo[/:{var1}]*[/bar[/:{var2}]*]', function() { |
|
331 | 331 | }); |
332 | 332 | $route = $r->route('foo', 'GET'); |
333 | 333 | expect($route->params)->toBe([ |
@@ -345,11 +345,11 @@ discard block |
||
345 | 345 | 'var2' => ['fuz'] |
346 | 346 | ]); |
347 | 347 | }); |
348 | - it("supports optional segments with custom variable regex", function () { |
|
348 | + it("supports optional segments with custom variable regex", function() { |
|
349 | 349 | |
350 | 350 | |
351 | 351 | $r = $this->router; |
352 | - $r->get('foo[/{var1:\d+}]', function () { |
|
352 | + $r->get('foo[/{var1:\d+}]', function() { |
|
353 | 353 | }); |
354 | 354 | $route = $r->route('foo', 'GET'); |
355 | 355 | expect($route->params)->toBe(['var1' => null]); |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | expect($e->getMessage())->toBe("No route found for `*:*:GET:/foo/baz`."); |
362 | 362 | } |
363 | 363 | }); |
364 | - it("supports multiple optional segments", function () { |
|
364 | + it("supports multiple optional segments", function() { |
|
365 | 365 | |
366 | 366 | |
367 | 367 | $patterns = [ |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | $r = $this->router; |
371 | 371 | |
372 | 372 | foreach ($patterns as $pattern) { |
373 | - $r->get($pattern, function () { |
|
373 | + $r->get($pattern, function() { |
|
374 | 374 | }); |
375 | 375 | $route = $r->route('foo', 'GET'); |
376 | 376 | expect($route->params)->toBe(['var1' => 'foo', 'var2' => null]); |
@@ -379,13 +379,13 @@ discard block |
||
379 | 379 | $r->clear(); |
380 | 380 | }; |
381 | 381 | }); |
382 | - it("supports host variables", function () { |
|
382 | + it("supports host variables", function() { |
|
383 | 383 | |
384 | 384 | |
385 | 385 | $r = $this->router; |
386 | - $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.bar'], function () { |
|
386 | + $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.bar'], function() { |
|
387 | 387 | }); |
388 | - $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.baz'], function () { |
|
388 | + $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.baz'], function() { |
|
389 | 389 | }); |
390 | 390 | $route = $r->route('foo/25', 'GET', 'foo.biz.bar'); |
391 | 391 | expect($route->Host()->getPattern())->toBe('foo.{domain}.bar'); |
@@ -394,27 +394,27 @@ discard block |
||
394 | 394 | expect($route->Host()->getPattern())->toBe('foo.{domain}.baz'); |
395 | 395 | expect($route->params)->toBe(['domain' => 'buz', 'var1' => '50']); |
396 | 396 | }); |
397 | - it("supports constrained host variables", function () { |
|
397 | + it("supports constrained host variables", function() { |
|
398 | 398 | |
399 | 399 | |
400 | 400 | $r = $this->router; |
401 | - $r->get('foo/{var1:\d+}', ['host' => '{subdomain:foo}.{domain}.bar'], function () { |
|
401 | + $r->get('foo/{var1:\d+}', ['host' => '{subdomain:foo}.{domain}.bar'], function() { |
|
402 | 402 | }); |
403 | 403 | $route = $r->route('foo/25', 'GET', 'foo.biz.bar'); |
404 | - expect($route->params)->toBe([ 'subdomain' => 'foo', 'domain' => 'biz', 'var1' => '25']); |
|
404 | + expect($route->params)->toBe(['subdomain' => 'foo', 'domain' => 'biz', 'var1' => '25']); |
|
405 | 405 | try { |
406 | 406 | $route = $r->route('foo/bar', 'GET', 'foo.biz.bar'); |
407 | 407 | } catch (RouteNotFoundException $e) { |
408 | 408 | expect($e->getMessage())->toBe("No route found for `*:foo.biz.bar:GET:/foo/bar`."); |
409 | 409 | } |
410 | 410 | }); |
411 | - it("supports absolute URL", function () { |
|
411 | + it("supports absolute URL", function() { |
|
412 | 412 | |
413 | 413 | |
414 | 414 | $r = $this->router; |
415 | - $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.bar'], function () { |
|
415 | + $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.bar'], function() { |
|
416 | 416 | }); |
417 | - $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.baz'], function () { |
|
417 | + $r->get('foo/{var1:\d+}', ['host' => 'foo.{domain}.baz'], function() { |
|
418 | 418 | }); |
419 | 419 | $route = $r->route('http://foo.biz.bar/foo/25', 'GET'); |
420 | 420 | expect($route->Host()->getPattern())->toBe('foo.{domain}.bar'); |
@@ -423,23 +423,23 @@ discard block |
||
423 | 423 | expect($route->Host()->getPattern())->toBe('foo.{domain}.baz'); |
424 | 424 | expect($route->params)->toBe(['domain' => 'buz', 'var1' => '50']); |
425 | 425 | }); |
426 | - it("supports RESTful routes", function () { |
|
426 | + it("supports RESTful routes", function() { |
|
427 | 427 | |
428 | 428 | |
429 | 429 | $r = $this->router; |
430 | - $r->get('foo/bar', function () { |
|
430 | + $r->get('foo/bar', function() { |
|
431 | 431 | }); |
432 | - $r->head('foo/bar', function () { |
|
432 | + $r->head('foo/bar', function() { |
|
433 | 433 | }); |
434 | - $r->post('foo/bar', function () { |
|
434 | + $r->post('foo/bar', function() { |
|
435 | 435 | }); |
436 | - $r->put('foo/bar', function () { |
|
436 | + $r->put('foo/bar', function() { |
|
437 | 437 | }); |
438 | - $r->patch('foo/bar', function () { |
|
438 | + $r->patch('foo/bar', function() { |
|
439 | 439 | }); |
440 | - $r->delete('foo/bar', function () { |
|
440 | + $r->delete('foo/bar', function() { |
|
441 | 441 | }); |
442 | - $r->options('foo/bar', function () { |
|
442 | + $r->options('foo/bar', function() { |
|
443 | 443 | }); |
444 | 444 | $methods = ['OPTIONS', 'DELETE', 'PATCH', 'PUT', 'POST', 'HEAD', 'GET']; |
445 | 445 | $route = $r->route('foo/bar', 'GET'); |
@@ -457,11 +457,11 @@ discard block |
||
457 | 457 | $route = $r->route('foo/bar', 'OPTIONS'); |
458 | 458 | expect($route->Methods())->toBe($methods); |
459 | 459 | }); |
460 | - it("matches relationships based routes", function () { |
|
460 | + it("matches relationships based routes", function() { |
|
461 | 461 | |
462 | 462 | |
463 | 463 | $r = $this->router; |
464 | - $r->get('[/{relations:[^/]+/[^/:][^/]*}]*/comment[/{id:[^/:][^/]*}][/:{action}]', function () { |
|
464 | + $r->get('[/{relations:[^/]+/[^/:][^/]*}]*/comment[/{id:[^/:][^/]*}][/:{action}]', function() { |
|
465 | 465 | }); |
466 | 466 | $route = $r->route('blog/1/post/22/comment/:show', 'GET'); |
467 | 467 | expect($route->params)->toBe([ |
@@ -473,35 +473,35 @@ discard block |
||
473 | 473 | 'action' => 'show' |
474 | 474 | ]); |
475 | 475 | }); |
476 | - it("dispatches HEAD requests on matching GET routes if the HEAD routes are missing", function () { |
|
476 | + it("dispatches HEAD requests on matching GET routes if the HEAD routes are missing", function() { |
|
477 | 477 | |
478 | 478 | |
479 | 479 | $r = $this->router; |
480 | - $r->get('foo/bar', function () { |
|
480 | + $r->get('foo/bar', function() { |
|
481 | 481 | return 'GET'; |
482 | 482 | }); |
483 | 483 | $route = $r->route('foo/bar', 'HEAD'); |
484 | 484 | expect($route->Methods())->toBe(['GET']); |
485 | 485 | }); |
486 | - it("dispatches HEAD requests on matching HEAD routes", function () { |
|
486 | + it("dispatches HEAD requests on matching HEAD routes", function() { |
|
487 | 487 | |
488 | 488 | |
489 | 489 | $r = $this->router; |
490 | 490 | |
491 | - $r->head('foo/bar', function () { |
|
491 | + $r->head('foo/bar', function() { |
|
492 | 492 | return 'HEAD'; |
493 | 493 | }); |
494 | - $r->get('foo/bar', function () { |
|
494 | + $r->get('foo/bar', function() { |
|
495 | 495 | return 'GET'; |
496 | 496 | }); |
497 | 497 | $route = $r->route('foo/bar', 'HEAD'); |
498 | 498 | expect($route->Methods())->toBe(['GET', 'HEAD']); |
499 | 499 | }); |
500 | - it("supports requests as a list of arguments", function () { |
|
500 | + it("supports requests as a list of arguments", function() { |
|
501 | 501 | |
502 | 502 | |
503 | 503 | $r = $this->router; |
504 | - $r->bind('foo/bar', function () { |
|
504 | + $r->bind('foo/bar', function() { |
|
505 | 505 | }); |
506 | 506 | $route = $r->route('foo/bar', 'GET'); |
507 | 507 | expect($this->export($route->request))->toEqual([ |
@@ -511,10 +511,10 @@ discard block |
||
511 | 511 | 'path' => 'foo/bar' |
512 | 512 | ]); |
513 | 513 | }); |
514 | - it("supports requests as an object", function () { |
|
514 | + it("supports requests as an object", function() { |
|
515 | 515 | |
516 | 516 | $r = $this->router; |
517 | - $r->bind('foo/bar', function () { |
|
517 | + $r->bind('foo/bar', function() { |
|
518 | 518 | }); |
519 | 519 | $request = Double::instance(['implements' => ServerRequestInterface::class]); |
520 | 520 | $uri = Double::instance(['implements' => UriInterface::class]); |
@@ -527,11 +527,11 @@ discard block |
||
527 | 527 | $route = $r->route($request, 'GET'); |
528 | 528 | expect($route->request)->toBe($request); |
529 | 529 | }); |
530 | - it("supports requests as an array", function () { |
|
530 | + it("supports requests as an array", function() { |
|
531 | 531 | |
532 | 532 | |
533 | 533 | $r = $this->router; |
534 | - $r->bind('foo/bar', function () { |
|
534 | + $r->bind('foo/bar', function() { |
|
535 | 535 | }); |
536 | 536 | $route = $r->route(['path' => 'foo/bar'], 'GET'); |
537 | 537 | expect($this->export($route->request))->toEqual([ |
@@ -542,59 +542,59 @@ discard block |
||
542 | 542 | ]); |
543 | 543 | }); |
544 | 544 | }); |
545 | - describe("->group()", function () { |
|
545 | + describe("->group()", function() { |
|
546 | 546 | |
547 | 547 | |
548 | - it("supports nested named route", function () { |
|
548 | + it("supports nested named route", function() { |
|
549 | 549 | |
550 | 550 | |
551 | 551 | $r = $this->router; |
552 | - $r->group('foo', ['name' => 'foz'], function ($r) use (&$route) { |
|
552 | + $r->group('foo', ['name' => 'foz'], function($r) use (&$route) { |
|
553 | 553 | |
554 | - $r->group('bar', ['name' => 'baz'], function ($r) use (&$route) { |
|
554 | + $r->group('bar', ['name' => 'baz'], function($r) use (&$route) { |
|
555 | 555 | |
556 | - $route = $r->bind('{var1}', ['name' => 'quz'], function () { |
|
556 | + $route = $r->bind('{var1}', ['name' => 'quz'], function() { |
|
557 | 557 | }); |
558 | 558 | }); |
559 | 559 | }); |
560 | 560 | expect(isset($r['foz.baz.quz']))->toBe(true); |
561 | 561 | expect($r['foz.baz.quz'])->toBe($route); |
562 | 562 | }); |
563 | - it("returns a working scope", function () { |
|
563 | + it("returns a working scope", function() { |
|
564 | 564 | |
565 | 565 | |
566 | 566 | $r = $this->router; |
567 | - $route = $r->group('foo', ['name' => 'foz'], function () { |
|
568 | - })->group('bar', ['name' => 'baz'], function () { |
|
569 | - })->bind('{var1}', ['name' => 'quz'], function () { |
|
567 | + $route = $r->group('foo', ['name' => 'foz'], function() { |
|
568 | + })->group('bar', ['name' => 'baz'], function() { |
|
569 | + })->bind('{var1}', ['name' => 'quz'], function() { |
|
570 | 570 | }); |
571 | 571 | expect(isset($r['foz.baz.quz']))->toBe(true); |
572 | 572 | expect($r['foz.baz.quz'])->toBe($route); |
573 | 573 | }); |
574 | - context("with a prefix contraint", function () { |
|
574 | + context("with a prefix contraint", function() { |
|
575 | 575 | |
576 | 576 | |
577 | - beforeEach(function () { |
|
577 | + beforeEach(function() { |
|
578 | 578 | |
579 | 579 | |
580 | 580 | $r = $this->router; |
581 | - $r->group('foo', function ($r) { |
|
581 | + $r->group('foo', function($r) { |
|
582 | 582 | |
583 | - $r->bind('{var1}', function () { |
|
583 | + $r->bind('{var1}', function() { |
|
584 | 584 | }); |
585 | 585 | }); |
586 | 586 | }); |
587 | - it("respects url's prefix constraint", function () { |
|
587 | + it("respects url's prefix constraint", function() { |
|
588 | 588 | |
589 | 589 | |
590 | 590 | $r = $this->router; |
591 | 591 | $route = $r->route('foo/bar'); |
592 | 592 | expect($route->params)->toBe(['var1' => 'bar']); |
593 | 593 | }); |
594 | - it("throws an exception when the prefix does not match", function () { |
|
594 | + it("throws an exception when the prefix does not match", function() { |
|
595 | 595 | |
596 | 596 | |
597 | - $closure = function () { |
|
597 | + $closure = function() { |
|
598 | 598 | |
599 | 599 | $r = $this->router; |
600 | 600 | $route = $r->route('bar/foo', 'GET'); |
@@ -602,30 +602,30 @@ discard block |
||
602 | 602 | expect($closure)->toThrow(new RouteNotFoundException("No route found for `*:*:GET:/bar/foo`.")); |
603 | 603 | }); |
604 | 604 | }); |
605 | - context("with a prefix contraint and an optional parameter", function () { |
|
605 | + context("with a prefix contraint and an optional parameter", function() { |
|
606 | 606 | |
607 | 607 | |
608 | - beforeEach(function () { |
|
608 | + beforeEach(function() { |
|
609 | 609 | |
610 | 610 | |
611 | 611 | $r = $this->router; |
612 | - $r->group('foo', function ($r) { |
|
612 | + $r->group('foo', function($r) { |
|
613 | 613 | |
614 | - $r->bind('[{var1}]', function () { |
|
614 | + $r->bind('[{var1}]', function() { |
|
615 | 615 | }); |
616 | 616 | }); |
617 | 617 | }); |
618 | - it("respects url's prefix constraint", function () { |
|
618 | + it("respects url's prefix constraint", function() { |
|
619 | 619 | |
620 | 620 | |
621 | 621 | $r = $this->router; |
622 | 622 | $route = $r->route('foo'); |
623 | 623 | expect($route->params)->toBe(['var1' => null]); |
624 | 624 | }); |
625 | - it("throws an exception when the prefix does not match", function () { |
|
625 | + it("throws an exception when the prefix does not match", function() { |
|
626 | 626 | |
627 | 627 | |
628 | - $closure = function () { |
|
628 | + $closure = function() { |
|
629 | 629 | |
630 | 630 | $r = $this->router; |
631 | 631 | $route = $r->route('bar/foo', 'GET'); |
@@ -633,23 +633,23 @@ discard block |
||
633 | 633 | expect($closure)->toThrow(new RouteNotFoundException("No route found for `*:*:GET:/bar/foo`.")); |
634 | 634 | }); |
635 | 635 | }); |
636 | - context("with a host constraint", function () { |
|
636 | + context("with a host constraint", function() { |
|
637 | 637 | |
638 | 638 | |
639 | - beforeEach(function () { |
|
639 | + beforeEach(function() { |
|
640 | 640 | |
641 | 641 | |
642 | 642 | $r = $this->router; |
643 | - $r->group('foo', ['host' => 'foo.{domain}.bar'], function ($r) { |
|
643 | + $r->group('foo', ['host' => 'foo.{domain}.bar'], function($r) { |
|
644 | 644 | |
645 | - $r->group('bar', function ($r) { |
|
645 | + $r->group('bar', function($r) { |
|
646 | 646 | |
647 | - $r->bind('{var1}', function () { |
|
647 | + $r->bind('{var1}', function() { |
|
648 | 648 | }); |
649 | 649 | }); |
650 | 650 | }); |
651 | 651 | }); |
652 | - it("respects url's host constraint", function () { |
|
652 | + it("respects url's host constraint", function() { |
|
653 | 653 | |
654 | 654 | |
655 | 655 | $r = $this->router; |
@@ -659,10 +659,10 @@ discard block |
||
659 | 659 | 'var1' => 'baz' |
660 | 660 | ]); |
661 | 661 | }); |
662 | - it("throws an exception when the host does not match", function () { |
|
662 | + it("throws an exception when the host does not match", function() { |
|
663 | 663 | |
664 | 664 | |
665 | - $closure = function () { |
|
665 | + $closure = function() { |
|
666 | 666 | |
667 | 667 | $r = $this->router; |
668 | 668 | $route = $r->route('http://bar.hello.foo/foo/bar/baz', 'GET'); |
@@ -670,23 +670,23 @@ discard block |
||
670 | 670 | expect($closure)->toThrow(new RouteNotFoundException("No route found for `http:bar.hello.foo:GET:/foo/bar/baz`.")); |
671 | 671 | }); |
672 | 672 | }); |
673 | - context("with a scheme constraint", function () { |
|
673 | + context("with a scheme constraint", function() { |
|
674 | 674 | |
675 | 675 | |
676 | - beforeEach(function () { |
|
676 | + beforeEach(function() { |
|
677 | 677 | |
678 | 678 | |
679 | 679 | $r = $this->router; |
680 | - $r->group('foo', ['scheme' => 'http'], function ($r) { |
|
680 | + $r->group('foo', ['scheme' => 'http'], function($r) { |
|
681 | 681 | |
682 | - $r->group('bar', function ($r) { |
|
682 | + $r->group('bar', function($r) { |
|
683 | 683 | |
684 | - $r->bind('{var1}', function () { |
|
684 | + $r->bind('{var1}', function() { |
|
685 | 685 | }); |
686 | 686 | }); |
687 | 687 | }); |
688 | 688 | }); |
689 | - it("respects url's scheme constraint", function () { |
|
689 | + it("respects url's scheme constraint", function() { |
|
690 | 690 | |
691 | 691 | |
692 | 692 | $r = $this->router; |
@@ -695,10 +695,10 @@ discard block |
||
695 | 695 | 'var1' => 'baz' |
696 | 696 | ]); |
697 | 697 | }); |
698 | - it("throws an exception when route is not found", function () { |
|
698 | + it("throws an exception when route is not found", function() { |
|
699 | 699 | |
700 | 700 | |
701 | - $closure = function () { |
|
701 | + $closure = function() { |
|
702 | 702 | |
703 | 703 | $r = $this->router; |
704 | 704 | $route = $r->route('https://domain.com/foo/bar/baz', 'GET'); |
@@ -706,25 +706,25 @@ discard block |
||
706 | 706 | expect($closure)->toThrow(new RouteNotFoundException("No route found for `https:domain.com:GET:/foo/bar/baz`.")); |
707 | 707 | }); |
708 | 708 | }); |
709 | - it("concats namespace values", function () { |
|
709 | + it("concats namespace values", function() { |
|
710 | 710 | |
711 | 711 | |
712 | 712 | $r = $this->router; |
713 | - $r->group('foo', ['namespace' => 'My'], function ($r) { |
|
713 | + $r->group('foo', ['namespace' => 'My'], function($r) { |
|
714 | 714 | |
715 | - $r->group('bar', ['namespace' => 'Name'], function ($r) { |
|
715 | + $r->group('bar', ['namespace' => 'Name'], function($r) { |
|
716 | 716 | |
717 | - $r->bind('{var1}', ['namespace' => 'Space'], function () { |
|
717 | + $r->bind('{var1}', ['namespace' => 'Space'], function() { |
|
718 | 718 | }); |
719 | 719 | }); |
720 | 720 | }); |
721 | 721 | $route = $r->route('foo/bar/baz', 'GET'); |
722 | 722 | expect($route->namespace)->toBe('My\Name\Space\\'); |
723 | 723 | }); |
724 | - it("throws an exception when the handler is not a closure", function () { |
|
724 | + it("throws an exception when the handler is not a closure", function() { |
|
725 | 725 | |
726 | 726 | |
727 | - $closure = function () { |
|
727 | + $closure = function() { |
|
728 | 728 | |
729 | 729 | $r = $this->router; |
730 | 730 | $r->group('foo', 'substr'); |
@@ -732,24 +732,24 @@ discard block |
||
732 | 732 | expect($closure)->toThrow(new RouterException("The handler needs to be an instance of `Closure` or implements the `__invoke()` magic method.")); |
733 | 733 | }); |
734 | 734 | }); |
735 | - describe("->middleware()", function () { |
|
735 | + describe("->middleware()", function() { |
|
736 | 736 | |
737 | 737 | |
738 | - it("returns global middleware", function () { |
|
738 | + it("returns global middleware", function() { |
|
739 | 739 | |
740 | 740 | |
741 | 741 | $r = $this->router; |
742 | - $mw1 = function ($request, $response, $next) { |
|
742 | + $mw1 = function($request, $response, $next) { |
|
743 | 743 | |
744 | - return '1' . $next() . '1'; |
|
744 | + return '1'.$next().'1'; |
|
745 | 745 | }; |
746 | - $mw2 = function ($request, $response, $next) { |
|
746 | + $mw2 = function($request, $response, $next) { |
|
747 | 747 | |
748 | - return '2' . $next() . '2'; |
|
748 | + return '2'.$next().'2'; |
|
749 | 749 | }; |
750 | 750 | $r->apply($mw1, $mw2); |
751 | 751 | |
752 | - $next = function () { |
|
752 | + $next = function() { |
|
753 | 753 | return ''; |
754 | 754 | }; |
755 | 755 | $generator = $r->middleware(); |
@@ -760,21 +760,21 @@ discard block |
||
760 | 760 | expect($actual1(null, null, $next))->toBe('11'); |
761 | 761 | }); |
762 | 762 | }); |
763 | - describe("->apply()", function () { |
|
763 | + describe("->apply()", function() { |
|
764 | 764 | |
765 | 765 | |
766 | - it("applies middlewares globally", function () { |
|
766 | + it("applies middlewares globally", function() { |
|
767 | 767 | |
768 | 768 | |
769 | 769 | $r = $this->router; |
770 | - $r->apply(function ($request, $response, $next) { |
|
770 | + $r->apply(function($request, $response, $next) { |
|
771 | 771 | |
772 | - return '1' . $next() . '1'; |
|
773 | - })->apply(function ($request, $response, $next) { |
|
772 | + return '1'.$next().'1'; |
|
773 | + })->apply(function($request, $response, $next) { |
|
774 | 774 | |
775 | - return '2' . $next() . '2'; |
|
775 | + return '2'.$next().'2'; |
|
776 | 776 | }); |
777 | - $route = $r->bind('/foo/bar', function ($route) { |
|
777 | + $route = $r->bind('/foo/bar', function($route) { |
|
778 | 778 | |
779 | 779 | return 'A'; |
780 | 780 | }); |
@@ -782,27 +782,27 @@ discard block |
||
782 | 782 | $actual = $route->dispatch(); |
783 | 783 | expect($actual)->toBe('21A12'); |
784 | 784 | }); |
785 | - it("applies middlewares globally and per groups", function () { |
|
785 | + it("applies middlewares globally and per groups", function() { |
|
786 | 786 | |
787 | 787 | |
788 | 788 | $r = $this->router; |
789 | - $r->apply(function ($request, $response, $next) { |
|
789 | + $r->apply(function($request, $response, $next) { |
|
790 | 790 | |
791 | - return '1' . $next() . '1'; |
|
791 | + return '1'.$next().'1'; |
|
792 | 792 | }); |
793 | - $r->bind('foo/{foo}', ['name' => 'foo'], function () { |
|
793 | + $r->bind('foo/{foo}', ['name' => 'foo'], function() { |
|
794 | 794 | |
795 | 795 | return 'A'; |
796 | 796 | }); |
797 | - $r->group('bar', function ($r) { |
|
797 | + $r->group('bar', function($r) { |
|
798 | 798 | |
799 | - $r->bind('{bar}', ['name' => 'bar'], function () { |
|
799 | + $r->bind('{bar}', ['name' => 'bar'], function() { |
|
800 | 800 | |
801 | 801 | return 'A'; |
802 | 802 | }); |
803 | - })->apply(function ($request, $response, $next) { |
|
803 | + })->apply(function($request, $response, $next) { |
|
804 | 804 | |
805 | - return '2' . $next() . '2'; |
|
805 | + return '2'.$next().'2'; |
|
806 | 806 | }); |
807 | 807 | $route = $r->route('foo/foo'); |
808 | 808 | $actual = $route->dispatch(); |
@@ -812,15 +812,15 @@ discard block |
||
812 | 812 | expect($actual)->toBe('21A12'); |
813 | 813 | }); |
814 | 814 | }); |
815 | - describe("->strategy()", function () { |
|
815 | + describe("->strategy()", function() { |
|
816 | 816 | |
817 | 817 | |
818 | - it("sets a strategy", function () { |
|
818 | + it("sets a strategy", function() { |
|
819 | 819 | |
820 | 820 | $r = $this->router; |
821 | - $mystrategy = function ($router) { |
|
821 | + $mystrategy = function($router) { |
|
822 | 822 | |
823 | - $router->bind('foo/bar', function () { |
|
823 | + $router->bind('foo/bar', function() { |
|
824 | 824 | |
825 | 825 | return 'Hello World!'; |
826 | 826 | }); |
@@ -831,11 +831,11 @@ discard block |
||
831 | 831 | $route = $r->route('foo/bar'); |
832 | 832 | expect($route->Pattern())->toBe('/foo/bar'); |
833 | 833 | }); |
834 | - it("unsets a strategy", function () { |
|
834 | + it("unsets a strategy", function() { |
|
835 | 835 | |
836 | 836 | $r = $this->router; |
837 | 837 | |
838 | - $mystrategy = function () { |
|
838 | + $mystrategy = function() { |
|
839 | 839 | }; |
840 | 840 | $r->setStrategy('mystrategy', $mystrategy); |
841 | 841 | expect($r->strategy('mystrategy'))->toBe($mystrategy); |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | $this->setMethods($config['methods']); |
181 | 181 | $this->setScope($config['scope']); |
182 | 182 | $this->setPattern($config['pattern']); |
183 | - $this->setMiddleware((array)$config['middleware']); |
|
183 | + $this->setMiddleware((array) $config['middleware']); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function setMiddleware(array $middleware) |
193 | 193 | { |
194 | - $this->middleware = (array)$middleware; |
|
194 | + $this->middleware = (array) $middleware; |
|
195 | 195 | |
196 | 196 | return $this; |
197 | 197 | } |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | { |
372 | 372 | $this->prefix = trim($prefix, '/'); |
373 | 373 | if ($this->prefix) { |
374 | - $this->prefix = '/' . $this->prefix; |
|
374 | + $this->prefix = '/'.$this->prefix; |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | return $this; |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | */ |
441 | 441 | public function setMethods($methods): self |
442 | 442 | { |
443 | - $methods = $methods ? (array)$methods : []; |
|
443 | + $methods = $methods ? (array) $methods : []; |
|
444 | 444 | $methods = array_map('strtoupper', $methods); |
445 | 445 | $methods = array_fill_keys($methods, true); |
446 | 446 | |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | */ |
464 | 464 | public function allow($methods = []) |
465 | 465 | { |
466 | - $methods = $methods ? (array)$methods : []; |
|
466 | + $methods = $methods ? (array) $methods : []; |
|
467 | 467 | $methods = array_map('strtoupper', $methods); |
468 | 468 | $methods = array_fill_keys($methods, true) + $this->methods; |
469 | 469 | |
@@ -523,10 +523,10 @@ discard block |
||
523 | 523 | $this->variables = null; |
524 | 524 | |
525 | 525 | if (!$pattern || $pattern[0] !== '[') { |
526 | - $pattern = '/' . trim($pattern, '/'); |
|
526 | + $pattern = '/'.trim($pattern, '/'); |
|
527 | 527 | } |
528 | 528 | |
529 | - $this->pattern = $this->prefix . $pattern; |
|
529 | + $this->pattern = $this->prefix.$pattern; |
|
530 | 530 | |
531 | 531 | return $this; |
532 | 532 | } |
@@ -640,9 +640,9 @@ discard block |
||
640 | 640 | } |
641 | 641 | } |
642 | 642 | |
643 | - $path = '/' . trim($path, '/'); |
|
643 | + $path = '/'.trim($path, '/'); |
|
644 | 644 | |
645 | - if (!preg_match('~^' . $this->regex() . '$~', $path, $matches)) { |
|
645 | + if (!preg_match('~^'.$this->regex().'$~', $path, $matches)) { |
|
646 | 646 | return false; |
647 | 647 | } |
648 | 648 | $variables = $this->_buildVariables($matches); |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | } else { |
675 | 675 | $token = $parser::tokenize($pattern, '/'); |
676 | 676 | $rule = $parser::compile($token); |
677 | - if (preg_match_all('~' . $rule[0] . '~', $values[$i], $parts)) { |
|
677 | + if (preg_match_all('~'.$rule[0].'~', $values[$i], $parts)) { |
|
678 | 678 | foreach ($parts[1] as $value) { |
679 | 679 | if (strpos($value, '/') !== false) { |
680 | 680 | $variables[$name][] = explode('/', $value); |
@@ -705,7 +705,7 @@ discard block |
||
705 | 705 | |
706 | 706 | $generator = $this->middleware(); |
707 | 707 | |
708 | - $next = function () use ($request, $response, $generator, &$next) { |
|
708 | + $next = function() use ($request, $response, $generator, &$next) { |
|
709 | 709 | $handler = $generator->current(); |
710 | 710 | $generator->next(); |
711 | 711 | |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | } |
734 | 734 | } |
735 | 735 | |
736 | - yield function () { |
|
736 | + yield function() { |
|
737 | 737 | $handler = $this->handler(); |
738 | 738 | if ($handler === null) { |
739 | 739 | return null; |
@@ -781,7 +781,7 @@ discard block |
||
781 | 781 | |
782 | 782 | $options = array_filter( |
783 | 783 | $options, |
784 | - function ($value) { |
|
784 | + function($value) { |
|
785 | 785 | return $value !== '*'; |
786 | 786 | } |
787 | 787 | ); |
@@ -793,24 +793,24 @@ discard block |
||
793 | 793 | |
794 | 794 | $basePath = trim($options['basePath'], '/'); |
795 | 795 | if ($basePath) { |
796 | - $basePath = '/' . $basePath; |
|
796 | + $basePath = '/'.$basePath; |
|
797 | 797 | } |
798 | 798 | $link = isset($link) ? ltrim($link, '/') : ''; |
799 | - $link = $basePath . ($link ? '/' . $link : $link); |
|
800 | - $query = $options['query'] ? '?' . $options['query'] : ''; |
|
801 | - $fragment = $options['fragment'] ? '#' . $options['fragment'] : ''; |
|
799 | + $link = $basePath.($link ? '/'.$link : $link); |
|
800 | + $query = $options['query'] ? '?'.$options['query'] : ''; |
|
801 | + $fragment = $options['fragment'] ? '#'.$options['fragment'] : ''; |
|
802 | 802 | |
803 | 803 | if ($options['absolute']) { |
804 | 804 | if ($this->host !== null) { |
805 | - $link = $this->host->link($params, $options) . "{$link}"; |
|
805 | + $link = $this->host->link($params, $options)."{$link}"; |
|
806 | 806 | } else { |
807 | - $scheme = !empty($options['scheme']) ? $options['scheme'] . '://' : '//'; |
|
807 | + $scheme = !empty($options['scheme']) ? $options['scheme'].'://' : '//'; |
|
808 | 808 | $host = isset($options['host']) ? $options['host'] : 'localhost'; |
809 | 809 | $link = "{$scheme}{$host}{$link}"; |
810 | 810 | } |
811 | 811 | } |
812 | 812 | |
813 | - return $link . $query . $fragment; |
|
813 | + return $link.$query.$fragment; |
|
814 | 814 | } |
815 | 815 | |
816 | 816 | /** |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | if (isset($child['tokens'])) { |
832 | 832 | if ($child['repeat']) { |
833 | 833 | $name = $child['repeat']; |
834 | - $values = isset($params[$name]) && $params[$name] !== null ? (array)$params[$name] : []; |
|
834 | + $values = isset($params[$name]) && $params[$name] !== null ? (array) $params[$name] : []; |
|
835 | 835 | if (!$values && !$child['optional']) { |
836 | 836 | throw new RouterException("Missing parameters `'{$name}'` for route: `'{$this->name}#{$this->pattern}'`."); |
837 | 837 | } |
@@ -858,12 +858,12 @@ discard block |
||
858 | 858 | $parts = []; |
859 | 859 | } |
860 | 860 | foreach ($parts as $key => $value) { |
861 | - $parts[$key] = rawurlencode((string)$value); |
|
861 | + $parts[$key] = rawurlencode((string) $value); |
|
862 | 862 | } |
863 | 863 | $value = join('/', $parts); |
864 | 864 | |
865 | - if (!preg_match('~^' . $child['pattern'] . '$~', $value)) { |
|
866 | - throw new RouterException("Expected `'" . $child['name'] . "'` to match `'" . $child['pattern'] . "'`, but received `'" . $value . "'`."); |
|
865 | + if (!preg_match('~^'.$child['pattern'].'$~', $value)) { |
|
866 | + throw new RouterException("Expected `'".$child['name']."'` to match `'".$child['pattern']."'`, but received `'".$value."'`."); |
|
867 | 867 | } |
868 | 868 | $link .= $value; |
869 | 869 | } |