@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | return false; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - if (!preg_match('~^' . $this->getRegex() . '$~', $host, $matches)) { |
|
| 219 | + if (!preg_match('~^'.$this->getRegex().'$~', $host, $matches)) { |
|
| 220 | 220 | $hostVariables = null; |
| 221 | 221 | return false; |
| 222 | 222 | } |
@@ -242,8 +242,8 @@ discard block |
||
| 242 | 242 | $options['host'] = $this->_link($this->getToken(), $params); |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - $scheme = $options['scheme'] !== '*' ? $options['scheme'] . '://' : '//'; |
|
| 246 | - return $scheme . $options['host']; |
|
| 245 | + $scheme = $options['scheme'] !== '*' ? $options['scheme'].'://' : '//'; |
|
| 246 | + return $scheme.$options['host']; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
@@ -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; |
@@ -70,13 +70,13 @@ |
||
| 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 | - * @param array The tokens structure root node. |
|
| 78 | - * @return array |
|
| 79 | - */ |
|
| 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 | + * @param array The tokens structure root node. |
|
| 78 | + * @return array |
|
| 79 | + */ |
|
| 80 | 80 | public static function tokenize(string $pattern, string $delimiter = '/'): array |
| 81 | 81 | { |
| 82 | 82 | // Checks if the pattern has some optional segments. |
@@ -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 | } |
@@ -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 | /** |
@@ -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 | } |
@@ -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; |