@@ -118,9 +118,9 @@ discard block |
||
| 118 | 118 | $route = $r->bind('foo/bar', function($route) { |
| 119 | 119 | return 'A'; |
| 120 | 120 | })->apply(function($request, $response, $next) { |
| 121 | - return '1' . $next() . '1'; |
|
| 121 | + return '1'.$next().'1'; |
|
| 122 | 122 | })->apply(function($request, $response, $next) { |
| 123 | - return '2' . $next() . '2'; |
|
| 123 | + return '2'.$next().'2'; |
|
| 124 | 124 | }); |
| 125 | 125 | |
| 126 | 126 | $route = $r->route('foo/bar'); |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | 'scheme' => 'https' |
| 204 | 204 | ]); |
| 205 | 205 | |
| 206 | - $link =$route->link([ |
|
| 206 | + $link = $route->link([ |
|
| 207 | 207 | 'bar' => 'baz', |
| 208 | 208 | 'domain' => 'example' |
| 209 | 209 | ], [ |
@@ -93,12 +93,12 @@ discard block |
||
| 93 | 93 | $scope = $this->_scope; |
| 94 | 94 | |
| 95 | 95 | if (!empty($options['name'])) { |
| 96 | - $options['name'] = $scope['name'] ? $scope['name'] . '.' . $options['name'] : $options['name']; |
|
| 96 | + $options['name'] = $scope['name'] ? $scope['name'].'.'.$options['name'] : $options['name']; |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | if (!empty($options['prefix'])) { |
| 100 | - $options['prefix'] = $scope['prefix'] . trim($options['prefix'], '/'); |
|
| 101 | - $options['prefix'] = $options['prefix'] ? $options['prefix'] . '/' : ''; |
|
| 100 | + $options['prefix'] = $scope['prefix'].trim($options['prefix'], '/'); |
|
| 101 | + $options['prefix'] = $options['prefix'] ? $options['prefix'].'/' : ''; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | if (isset($options['persist'])) { |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | if (isset($options['namespace'])) { |
| 109 | - $options['namespace'] = $scope['namespace'] . trim($options['namespace'], '\\') . '\\'; |
|
| 109 | + $options['namespace'] = $scope['namespace'].trim($options['namespace'], '\\').'\\'; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | return $options + $scope; |
@@ -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 | /** |
@@ -80,16 +80,16 @@ |
||
| 80 | 80 | public function match($request, &$variables = null, &$hostVariables = null): bool; |
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | - * Returns the route's link. |
|
| 84 | - * |
|
| 85 | - * @param array $params The route parameters. |
|
| 86 | - * @param array $options Options for generating the proper prefix. Accepted values are: |
|
| 87 | - * - `'absolute'` _boolean_: `true` or `false`. - `'scheme'` |
|
| 88 | - * _string_ : The scheme. - `'host'` _string_ : The host |
|
| 89 | - * name. - `'basePath'` _string_ : The base path. - `'query'` |
|
| 90 | - * _string_ : The query string. - `'fragment'` _string_ : The |
|
| 91 | - * fragment string. |
|
| 92 | - * @return string The link. |
|
| 93 | - */ |
|
| 94 | - public function link(array $params = [], array $options = []): string; |
|
| 83 | + * Returns the route's link. |
|
| 84 | + * |
|
| 85 | + * @param array $params The route parameters. |
|
| 86 | + * @param array $options Options for generating the proper prefix. Accepted values are: |
|
| 87 | + * - `'absolute'` _boolean_: `true` or `false`. - `'scheme'` |
|
| 88 | + * _string_ : The scheme. - `'host'` _string_ : The host |
|
| 89 | + * name. - `'basePath'` _string_ : The base path. - `'query'` |
|
| 90 | + * _string_ : The query string. - `'fragment'` _string_ : The |
|
| 91 | + * fragment string. |
|
| 92 | + * @return string The link. |
|
| 93 | + */ |
|
| 94 | + public function link(array $params = [], array $options = []): string; |
|
| 95 | 95 | } |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | $this->setMethods($config['methods']); |
| 178 | 178 | $this->setScope($config['scope']); |
| 179 | 179 | $this->setPattern($config['pattern']); |
| 180 | - $this->setMiddleware((array)$config['middleware']); |
|
| 180 | + $this->setMiddleware((array) $config['middleware']); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | public function setMiddleware(array $middleware) |
| 190 | 190 | { |
| 191 | - $this->_middleware = (array)$middleware; |
|
| 191 | + $this->_middleware = (array) $middleware; |
|
| 192 | 192 | |
| 193 | 193 | return $this; |
| 194 | 194 | } |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | { |
| 369 | 369 | $this->_prefix = trim($prefix, '/'); |
| 370 | 370 | if ($this->_prefix) { |
| 371 | - $this->_prefix = '/' . $this->_prefix; |
|
| 371 | + $this->_prefix = '/'.$this->_prefix; |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | return $this; |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | */ |
| 438 | 438 | public function setMethods($methods): self |
| 439 | 439 | { |
| 440 | - $methods = $methods ? (array)$methods : []; |
|
| 440 | + $methods = $methods ? (array) $methods : []; |
|
| 441 | 441 | $methods = array_map('strtoupper', $methods); |
| 442 | 442 | $methods = array_fill_keys($methods, true); |
| 443 | 443 | |
@@ -460,7 +460,7 @@ discard block |
||
| 460 | 460 | */ |
| 461 | 461 | public function allow($methods = []) |
| 462 | 462 | { |
| 463 | - $methods = $methods ? (array)$methods : []; |
|
| 463 | + $methods = $methods ? (array) $methods : []; |
|
| 464 | 464 | $methods = array_map('strtoupper', $methods); |
| 465 | 465 | $methods = array_fill_keys($methods, true) + $this->_methods; |
| 466 | 466 | |
@@ -520,10 +520,10 @@ discard block |
||
| 520 | 520 | $this->_variables = null; |
| 521 | 521 | |
| 522 | 522 | if (!$pattern || $pattern[0] !== '[') { |
| 523 | - $pattern = '/' . trim($pattern, '/'); |
|
| 523 | + $pattern = '/'.trim($pattern, '/'); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | - $this->_pattern = $this->_prefix . $pattern; |
|
| 526 | + $this->_pattern = $this->_prefix.$pattern; |
|
| 527 | 527 | |
| 528 | 528 | return $this; |
| 529 | 529 | } |
@@ -637,9 +637,9 @@ discard block |
||
| 637 | 637 | } |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | - $path = '/' . trim($path, '/'); |
|
| 640 | + $path = '/'.trim($path, '/'); |
|
| 641 | 641 | |
| 642 | - if (!preg_match('~^' . $this->getRegex() . '$~', $path, $matches)) { |
|
| 642 | + if (!preg_match('~^'.$this->getRegex().'$~', $path, $matches)) { |
|
| 643 | 643 | return false; |
| 644 | 644 | } |
| 645 | 645 | $variables = $this->_buildVariables($matches); |
@@ -671,7 +671,7 @@ discard block |
||
| 671 | 671 | } else { |
| 672 | 672 | $token = $parser::tokenize($pattern, '/'); |
| 673 | 673 | $rule = $parser::compile($token); |
| 674 | - if (preg_match_all('~' . $rule[0] . '~', $values[$i], $parts)) { |
|
| 674 | + if (preg_match_all('~'.$rule[0].'~', $values[$i], $parts)) { |
|
| 675 | 675 | foreach ($parts[1] as $value) { |
| 676 | 676 | if (strpos($value, '/') !== false) { |
| 677 | 677 | $variables[$name][] = explode('/', $value); |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | |
| 703 | 703 | $generator = $this->middleware(); |
| 704 | 704 | |
| 705 | - $next = function () use ($request, $response, $generator, &$next) { |
|
| 705 | + $next = function() use ($request, $response, $generator, &$next) { |
|
| 706 | 706 | $handler = $generator->current(); |
| 707 | 707 | $generator->next(); |
| 708 | 708 | |
@@ -730,7 +730,7 @@ discard block |
||
| 730 | 730 | } |
| 731 | 731 | } |
| 732 | 732 | |
| 733 | - yield function () { |
|
| 733 | + yield function() { |
|
| 734 | 734 | $handler = $this->getHandler(); |
| 735 | 735 | if ($handler === null) { |
| 736 | 736 | return null; |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | ]; |
| 778 | 778 | |
| 779 | 779 | $options = array_filter( |
| 780 | - $options, function ($value) { |
|
| 780 | + $options, function($value) { |
|
| 781 | 781 | return $value !== '*'; |
| 782 | 782 | } |
| 783 | 783 | ); |
@@ -789,24 +789,24 @@ discard block |
||
| 789 | 789 | |
| 790 | 790 | $basePath = trim($options['basePath'], '/'); |
| 791 | 791 | if ($basePath) { |
| 792 | - $basePath = '/' . $basePath; |
|
| 792 | + $basePath = '/'.$basePath; |
|
| 793 | 793 | } |
| 794 | 794 | $link = isset($link) ? ltrim($link, '/') : ''; |
| 795 | - $link = $basePath . ($link ? '/' . $link : $link); |
|
| 796 | - $query = $options['query'] ? '?' . $options['query'] : ''; |
|
| 797 | - $fragment = $options['fragment'] ? '#' . $options['fragment'] : ''; |
|
| 795 | + $link = $basePath.($link ? '/'.$link : $link); |
|
| 796 | + $query = $options['query'] ? '?'.$options['query'] : ''; |
|
| 797 | + $fragment = $options['fragment'] ? '#'.$options['fragment'] : ''; |
|
| 798 | 798 | |
| 799 | 799 | if ($options['absolute']) { |
| 800 | 800 | if ($this->_host !== null) { |
| 801 | - $link = $this->_host->link($params, $options) . "{$link}"; |
|
| 801 | + $link = $this->_host->link($params, $options)."{$link}"; |
|
| 802 | 802 | } else { |
| 803 | - $scheme = !empty($options['scheme']) ? $options['scheme'] . '://' : '//'; |
|
| 803 | + $scheme = !empty($options['scheme']) ? $options['scheme'].'://' : '//'; |
|
| 804 | 804 | $host = isset($options['host']) ? $options['host'] : 'localhost'; |
| 805 | 805 | $link = "{$scheme}{$host}{$link}"; |
| 806 | 806 | } |
| 807 | 807 | } |
| 808 | 808 | |
| 809 | - return $link . $query . $fragment; |
|
| 809 | + return $link.$query.$fragment; |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | /** |
@@ -827,7 +827,7 @@ discard block |
||
| 827 | 827 | if (isset($child['tokens'])) { |
| 828 | 828 | if ($child['repeat']) { |
| 829 | 829 | $name = $child['repeat']; |
| 830 | - $values = isset($params[$name]) && $params[$name] !== null ? (array)$params[$name] : []; |
|
| 830 | + $values = isset($params[$name]) && $params[$name] !== null ? (array) $params[$name] : []; |
|
| 831 | 831 | if (!$values && !$child['optional']) { |
| 832 | 832 | throw new RouterException("Missing parameters `'{$name}'` for route: `'{$this->name}#{$this->_pattern}'`."); |
| 833 | 833 | } |
@@ -854,12 +854,12 @@ discard block |
||
| 854 | 854 | $parts = []; |
| 855 | 855 | } |
| 856 | 856 | foreach ($parts as $key => $value) { |
| 857 | - $parts[$key] = rawurlencode((string)$value); |
|
| 857 | + $parts[$key] = rawurlencode((string) $value); |
|
| 858 | 858 | } |
| 859 | 859 | $value = join('/', $parts); |
| 860 | 860 | |
| 861 | - if (!preg_match('~^' . $child['pattern'] . '$~', $value)) { |
|
| 862 | - throw new RouterException("Expected `'" . $child['name'] . "'` to match `'" . $child['pattern'] . "'`, but received `'" . $value . "'`."); |
|
| 861 | + if (!preg_match('~^'.$child['pattern'].'$~', $value)) { |
|
| 862 | + throw new RouterException("Expected `'".$child['name']."'` to match `'".$child['pattern']."'`, but received `'".$value."'`."); |
|
| 863 | 863 | } |
| 864 | 864 | $link .= $value; |
| 865 | 865 | } |
@@ -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); |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | $index = 0; |
| 149 | 149 | $path = ''; |
| 150 | 150 | |
| 151 | - if (preg_match_all('~' . static::PLACEHOLDER_REGEX . '()~x', $pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { |
|
| 151 | + if (preg_match_all('~'.static::PLACEHOLDER_REGEX.'()~x', $pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { |
|
| 152 | 152 | foreach ($matches as $match) { |
| 153 | 153 | $offset = $match[0][1]; |
| 154 | 154 | |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | $variable = $match[1][0]; |
| 164 | - $capture = $match[2][0] ?: '[^' . $delimiter . ']+'; |
|
| 164 | + $capture = $match[2][0] ?: '[^'.$delimiter.']+'; |
|
| 165 | 165 | |
| 166 | 166 | $tokens[] = [ |
| 167 | 167 | 'name' => $variable, |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | $opened--; |
| 222 | 222 | if ($opened === 0) { |
| 223 | 223 | $greedy = '?'; |
| 224 | - if ($i < $len -1) { |
|
| 224 | + if ($i < $len - 1) { |
|
| 225 | 225 | if ($pattern[$i + 1] === '*' || $pattern[$i + 1] === '+') { |
| 226 | 226 | $greedy = $pattern[$i + 1]; |
| 227 | 227 | $i++; |
@@ -265,9 +265,9 @@ discard block |
||
| 265 | 265 | if (count($rule[1]) > 1) { |
| 266 | 266 | throw ParserException::placeholderExceeded(); |
| 267 | 267 | } |
| 268 | - $regex .= '((?:' . $rule[0] . ')' . $child['greedy'] . ')'; |
|
| 268 | + $regex .= '((?:'.$rule[0].')'.$child['greedy'].')'; |
|
| 269 | 269 | } elseif ($child['optional']) { |
| 270 | - $regex .= '(?:' . $rule[0] . ')?'; |
|
| 270 | + $regex .= '(?:'.$rule[0].')?'; |
|
| 271 | 271 | } |
| 272 | 272 | foreach ($rule[1] as $name => $pattern) { |
| 273 | 273 | if (isset($variables[$name])) { |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | $regex .= $child['pattern']; |
| 286 | 286 | } else { |
| 287 | 287 | $variables[$name] = false; |
| 288 | - $regex .= '(' . $child['pattern'] . ')'; |
|
| 288 | + $regex .= '('.$child['pattern'].')'; |
|
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | 291 | } |
@@ -214,35 +214,35 @@ |
||
| 214 | 214 | * @return \Lead\Router\RouterInterface |
| 215 | 215 | */ |
| 216 | 216 | public function addRoute(RouteInterface $route): RouterInterface { |
| 217 | - $options['pattern'] = $pattern = $route->getPattern(); |
|
| 218 | - $options['handler'] = $route->getHandler(); |
|
| 219 | - $options['scope'] = $route->getScope(); |
|
| 217 | + $options['pattern'] = $pattern = $route->getPattern(); |
|
| 218 | + $options['handler'] = $route->getHandler(); |
|
| 219 | + $options['scope'] = $route->getScope(); |
|
| 220 | 220 | |
| 221 | - $scheme = $options['scheme']; |
|
| 222 | - $host = $options['host']; |
|
| 221 | + $scheme = $options['scheme']; |
|
| 222 | + $host = $options['host']; |
|
| 223 | 223 | |
| 224 | - if (isset($this->_hosts[$scheme][$host])) { |
|
| 225 | - $options['host'] = $this->_hosts[$scheme][$host]; |
|
| 226 | - } |
|
| 224 | + if (isset($this->_hosts[$scheme][$host])) { |
|
| 225 | + $options['host'] = $this->_hosts[$scheme][$host]; |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - if (isset($this->_pattern[$scheme][$host][$pattern])) { |
|
| 229 | - $route = $this->_pattern[$scheme][$host][$pattern]; |
|
| 230 | - } else { |
|
| 231 | - $this->_hosts[$scheme][$host] = $route->getHost(); |
|
| 232 | - } |
|
| 228 | + if (isset($this->_pattern[$scheme][$host][$pattern])) { |
|
| 229 | + $route = $this->_pattern[$scheme][$host][$pattern]; |
|
| 230 | + } else { |
|
| 231 | + $this->_hosts[$scheme][$host] = $route->getHost(); |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - if (!isset($this->_pattern[$scheme][$host][$pattern])) { |
|
| 235 | - $this->_pattern[$scheme][$host][$pattern] = $route; |
|
| 236 | - } |
|
| 234 | + if (!isset($this->_pattern[$scheme][$host][$pattern])) { |
|
| 235 | + $this->_pattern[$scheme][$host][$pattern] = $route; |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - $methods = $route->getMethods(); |
|
| 239 | - foreach ($methods as $method) { |
|
| 240 | - $this->_routes[$scheme][$host][strtoupper($method)][] = $route; |
|
| 241 | - } |
|
| 238 | + $methods = $route->getMethods(); |
|
| 239 | + foreach ($methods as $method) { |
|
| 240 | + $this->_routes[$scheme][$host][strtoupper($method)][] = $route; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - $this->_data[$route->getName()] = $route; |
|
| 243 | + $this->_data[$route->getName()] = $route; |
|
| 244 | 244 | |
| 245 | - return $this; |
|
| 245 | + return $this; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | public function setBasePath(string $basePath): self |
| 187 | 187 | { |
| 188 | 188 | $basePath = trim($basePath, '/'); |
| 189 | - $this->_basePath = $basePath ? '/' . $basePath : ''; |
|
| 189 | + $this->_basePath = $basePath ? '/'.$basePath : ''; |
|
| 190 | 190 | |
| 191 | 191 | return $this; |
| 192 | 192 | } |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | $this->_pattern[$scheme][$host][$pattern] = $instance; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - $methods = $options['methods'] ? (array)$options['methods'] : []; |
|
| 302 | + $methods = $options['methods'] ? (array) $options['methods'] : []; |
|
| 303 | 303 | |
| 304 | 304 | $instance->allow($methods); |
| 305 | 305 | |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | $request = $parsed + $request; |
| 427 | 427 | } |
| 428 | 428 | |
| 429 | - $request['path'] = (ltrim((string)strtok($request['path'], '?'), '/')); |
|
| 429 | + $request['path'] = (ltrim((string) strtok($request['path'], '?'), '/')); |
|
| 430 | 430 | $request['method'] = strtoupper($request['method']); |
| 431 | 431 | |
| 432 | 432 | return $request; |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | it("matches on methods", function() { |
| 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->getMethods())->toBe(['POST', 'PUT']); |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | it("matches on same path different methods", function() { |
| 90 | 90 | $r = $this->router; |
| 91 | - $r->bind('foo/bar', ['name' => 'foo', 'methods' => ['GET']], function () {}); |
|
| 92 | - $r->bind('foo/bar', ['name' => 'bar', 'methods' => ['PUT']], function () {}); |
|
| 91 | + $r->bind('foo/bar', ['name' => 'foo', 'methods' => ['GET']], function() {}); |
|
| 92 | + $r->bind('foo/bar', ['name' => 'bar', 'methods' => ['PUT']], function() {}); |
|
| 93 | 93 | |
| 94 | 94 | $route = $r->route('foo/bar', 'PUT'); |
| 95 | 95 | expect($route->name)->toBe('bar'); |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | it("supports lowercase method names", function() { |
| 99 | 99 | |
| 100 | 100 | $r = $this->router; |
| 101 | - $r->bind('foo/bar', ['methods' => ['POST', 'PUT']], function () {}); |
|
| 101 | + $r->bind('foo/bar', ['methods' => ['POST', 'PUT']], function() {}); |
|
| 102 | 102 | |
| 103 | 103 | $route = $r->route('foo/bar', 'post'); |
| 104 | 104 | expect($route->getMethods())->toBe(['POST', 'PUT']); |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | $r->basePath('app'); |
| 146 | 146 | |
| 147 | 147 | $r->group(['host' => 'www.{domain}.com', 'scheme' => 'https'], function($r) { |
| 148 | - $r->bind('foo/{bar}', ['name' => 'foo'], function () {}); |
|
| 148 | + $r->bind('foo/{bar}', ['name' => 'foo'], function() {}); |
|
| 149 | 149 | }); |
| 150 | 150 | |
| 151 | 151 | $link = $r->link('foo', [ |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | $r = $this->router; |
| 162 | 162 | $r->group('foo', ['name' => 'foz'], function($r) { |
| 163 | 163 | $r->group('bar', ['name' => 'baz'], function($r) { |
| 164 | - $r->bind('{var1}', ['name' => 'quz'], function () {}); |
|
| 164 | + $r->bind('{var1}', ['name' => 'quz'], function() {}); |
|
| 165 | 165 | }); |
| 166 | 166 | }); |
| 167 | 167 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | $r = $this->router; |
| 176 | 176 | $r->group('{locale:en|fr}', ['persist' => 'locale'], function($r) { |
| 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'); |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | |
| 200 | 200 | $r = $this->router; |
| 201 | 201 | $r->group('{locale:en|fr}', ['persist' => 'locale'], function($r) { |
| 202 | - $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function () {}); |
|
| 202 | + $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function() {}); |
|
| 203 | 203 | }); |
| 204 | 204 | |
| 205 | 205 | $r->route('fr/post/index'); |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | it("routes on a simple route", function() { |
| 231 | 231 | |
| 232 | 232 | $r = $this->router; |
| 233 | - $r->bind('foo/bar', function () {}); |
|
| 233 | + $r->bind('foo/bar', function() {}); |
|
| 234 | 234 | |
| 235 | 235 | $route = $r->route('foo/bar', 'GET'); |
| 236 | 236 | expect($this->export($route->request))->toEqual([ |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | it("routes on a named route", function() { |
| 251 | 251 | |
| 252 | 252 | $r = $this->router; |
| 253 | - $r->bind('foo/bar', ['name' => 'foo'], function () {}); |
|
| 253 | + $r->bind('foo/bar', ['name' => 'foo'], function() {}); |
|
| 254 | 254 | |
| 255 | 255 | $route = $r->route('foo/bar', 'GET'); |
| 256 | 256 | expect($route->name)->toBe('foo'); |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | it("supports empty as index route", function() { |
| 266 | 266 | |
| 267 | 267 | $r = $this->router; |
| 268 | - $r->bind('', function () {}); |
|
| 268 | + $r->bind('', function() {}); |
|
| 269 | 269 | |
| 270 | 270 | $route = $r->route('', 'GET'); |
| 271 | 271 | expect($this->export($route->request))->toEqual([ |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | it("supports a slash as indes route", function() { |
| 281 | 281 | |
| 282 | 282 | $r = $this->router; |
| 283 | - $r->bind('/', function () {}); |
|
| 283 | + $r->bind('/', function() {}); |
|
| 284 | 284 | |
| 285 | 285 | $route = $r->route('', 'GET'); |
| 286 | 286 | expect($this->export($route->request))->toEqual([ |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | $r->get('foo/{var1:\d+}', ['host' => '{subdomain:foo}.{domain}.bar'], function() {}); |
| 423 | 423 | |
| 424 | 424 | $route = $r->route('foo/25', 'GET', 'foo.biz.bar'); |
| 425 | - expect($route->params)->toBe([ 'subdomain' => 'foo', 'domain' => 'biz', 'var1' => '25']); |
|
| 425 | + expect($route->params)->toBe(['subdomain' => 'foo', 'domain' => 'biz', 'var1' => '25']); |
|
| 426 | 426 | |
| 427 | 427 | try { |
| 428 | 428 | $route = $r->route('foo/bar', 'GET', 'foo.biz.bar'); |
@@ -450,13 +450,13 @@ discard block |
||
| 450 | 450 | it("supports RESTful routes", function() { |
| 451 | 451 | |
| 452 | 452 | $r = $this->router; |
| 453 | - $r->get('foo/bar', function () {}); |
|
| 454 | - $r->head('foo/bar', function () {}); |
|
| 455 | - $r->post('foo/bar', function () {}); |
|
| 456 | - $r->put('foo/bar', function () {}); |
|
| 457 | - $r->patch('foo/bar', function () {}); |
|
| 458 | - $r->delete('foo/bar', function () {}); |
|
| 459 | - $r->options('foo/bar', function () {}); |
|
| 453 | + $r->get('foo/bar', function() {}); |
|
| 454 | + $r->head('foo/bar', function() {}); |
|
| 455 | + $r->post('foo/bar', function() {}); |
|
| 456 | + $r->put('foo/bar', function() {}); |
|
| 457 | + $r->patch('foo/bar', function() {}); |
|
| 458 | + $r->delete('foo/bar', function() {}); |
|
| 459 | + $r->options('foo/bar', function() {}); |
|
| 460 | 460 | |
| 461 | 461 | $methods = ['OPTIONS', 'DELETE', 'PATCH', 'PUT', 'POST', 'HEAD', 'GET']; |
| 462 | 462 | |
@@ -486,7 +486,7 @@ discard block |
||
| 486 | 486 | it("matches relationships based routes", function() { |
| 487 | 487 | |
| 488 | 488 | $r = $this->router; |
| 489 | - $r->get('[/{relations:[^/]+/[^/:][^/]*}]*/comment[/{id:[^/:][^/]*}][/:{action}]', function () {}); |
|
| 489 | + $r->get('[/{relations:[^/]+/[^/:][^/]*}]*/comment[/{id:[^/:][^/]*}][/:{action}]', function() {}); |
|
| 490 | 490 | |
| 491 | 491 | $route = $r->route('blog/1/post/22/comment/:show', 'GET'); |
| 492 | 492 | expect($route->params)->toBe([ |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | it("dispatches HEAD requests on matching GET routes if the HEAD routes are missing", function() { |
| 504 | 504 | |
| 505 | 505 | $r = $this->router; |
| 506 | - $r->get('foo/bar', function () { return 'GET'; }); |
|
| 506 | + $r->get('foo/bar', function() { return 'GET'; }); |
|
| 507 | 507 | |
| 508 | 508 | $route = $r->route('foo/bar', 'HEAD'); |
| 509 | 509 | expect($route->getMethods())->toBe(['GET']); |
@@ -514,8 +514,8 @@ discard block |
||
| 514 | 514 | |
| 515 | 515 | $r = $this->router; |
| 516 | 516 | |
| 517 | - $r->head('foo/bar', function () { return 'HEAD'; }); |
|
| 518 | - $r->get('foo/bar', function () { return 'GET'; }); |
|
| 517 | + $r->head('foo/bar', function() { return 'HEAD'; }); |
|
| 518 | + $r->get('foo/bar', function() { return 'GET'; }); |
|
| 519 | 519 | |
| 520 | 520 | $route = $r->route('foo/bar', 'HEAD'); |
| 521 | 521 | expect($route->getMethods())->toBe(['GET', 'HEAD']); |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | it("supports requests as a list of arguments", function() { |
| 526 | 526 | |
| 527 | 527 | $r = $this->router; |
| 528 | - $r->bind('foo/bar', function () {}); |
|
| 528 | + $r->bind('foo/bar', function() {}); |
|
| 529 | 529 | |
| 530 | 530 | $route = $r->route('foo/bar', 'GET'); |
| 531 | 531 | expect($this->export($route->request))->toEqual([ |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | |
| 540 | 540 | it("supports requests as an object", function() { |
| 541 | 541 | $r = $this->router; |
| 542 | - $r->bind('foo/bar', function () {}); |
|
| 542 | + $r->bind('foo/bar', function() {}); |
|
| 543 | 543 | |
| 544 | 544 | $request = Double::instance(['implements' => ServerRequestInterface::class]); |
| 545 | 545 | $uri = Double::instance(['implements' => UriInterface::class]); |
@@ -559,7 +559,7 @@ discard block |
||
| 559 | 559 | it("supports requests as an array", function() { |
| 560 | 560 | |
| 561 | 561 | $r = $this->router; |
| 562 | - $r->bind('foo/bar', function () {}); |
|
| 562 | + $r->bind('foo/bar', function() {}); |
|
| 563 | 563 | |
| 564 | 564 | $route = $r->route(['path' =>'foo/bar'], 'GET'); |
| 565 | 565 | expect($this->export($route->request))->toEqual([ |
@@ -607,7 +607,7 @@ discard block |
||
| 607 | 607 | |
| 608 | 608 | $r = $this->router; |
| 609 | 609 | $r->group('foo', function($r) { |
| 610 | - $r->bind('{var1}', function () {}); |
|
| 610 | + $r->bind('{var1}', function() {}); |
|
| 611 | 611 | }); |
| 612 | 612 | |
| 613 | 613 | }); |
@@ -620,9 +620,9 @@ discard block |
||
| 620 | 620 | |
| 621 | 621 | }); |
| 622 | 622 | |
| 623 | - it("throws an exception when the prefix does not match", function () { |
|
| 623 | + it("throws an exception when the prefix does not match", function() { |
|
| 624 | 624 | |
| 625 | - $closure = function () { |
|
| 625 | + $closure = function() { |
|
| 626 | 626 | $r = $this->router; |
| 627 | 627 | $route = $r->route('bar/foo', 'GET'); |
| 628 | 628 | }; |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | |
| 638 | 638 | $r = $this->router; |
| 639 | 639 | $r->group('foo', function($r) { |
| 640 | - $r->bind('[{var1}]', function () {}); |
|
| 640 | + $r->bind('[{var1}]', function() {}); |
|
| 641 | 641 | }); |
| 642 | 642 | |
| 643 | 643 | }); |
@@ -650,9 +650,9 @@ discard block |
||
| 650 | 650 | |
| 651 | 651 | }); |
| 652 | 652 | |
| 653 | - it("throws an exception when the prefix does not match", function () { |
|
| 653 | + it("throws an exception when the prefix does not match", function() { |
|
| 654 | 654 | |
| 655 | - $closure = function () { |
|
| 655 | + $closure = function() { |
|
| 656 | 656 | $r = $this->router; |
| 657 | 657 | $route = $r->route('bar/foo', 'GET'); |
| 658 | 658 | }; |
@@ -668,7 +668,7 @@ discard block |
||
| 668 | 668 | $r = $this->router; |
| 669 | 669 | $r->group('foo', ['host' => 'foo.{domain}.bar'], function($r) { |
| 670 | 670 | $r->group('bar', function($r) { |
| 671 | - $r->bind('{var1}', function () {}); |
|
| 671 | + $r->bind('{var1}', function() {}); |
|
| 672 | 672 | }); |
| 673 | 673 | }); |
| 674 | 674 | |
@@ -685,9 +685,9 @@ discard block |
||
| 685 | 685 | |
| 686 | 686 | }); |
| 687 | 687 | |
| 688 | - it("throws an exception when the host does not match", function () { |
|
| 688 | + it("throws an exception when the host does not match", function() { |
|
| 689 | 689 | |
| 690 | - $closure = function () { |
|
| 690 | + $closure = function() { |
|
| 691 | 691 | $r = $this->router; |
| 692 | 692 | $route = $r->route('http://bar.hello.foo/foo/bar/baz', 'GET'); |
| 693 | 693 | }; |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | $r = $this->router; |
| 704 | 704 | $r->group('foo', ['scheme' => 'http'], function($r) { |
| 705 | 705 | $r->group('bar', function($r) { |
| 706 | - $r->bind('{var1}', function () {}); |
|
| 706 | + $r->bind('{var1}', function() {}); |
|
| 707 | 707 | }); |
| 708 | 708 | }); |
| 709 | 709 | |
@@ -719,9 +719,9 @@ discard block |
||
| 719 | 719 | |
| 720 | 720 | }); |
| 721 | 721 | |
| 722 | - it("throws an exception when route is not found", function () { |
|
| 722 | + it("throws an exception when route is not found", function() { |
|
| 723 | 723 | |
| 724 | - $closure = function () { |
|
| 724 | + $closure = function() { |
|
| 725 | 725 | $r = $this->router; |
| 726 | 726 | $route = $r->route('https://domain.com/foo/bar/baz', 'GET'); |
| 727 | 727 | }; |
@@ -735,7 +735,7 @@ discard block |
||
| 735 | 735 | $r = $this->router; |
| 736 | 736 | $r->group('foo', ['namespace' => 'My'], function($r) { |
| 737 | 737 | $r->group('bar', ['namespace' => 'Name'], function($r) { |
| 738 | - $r->bind('{var1}', ['namespace' => 'Space'], function () {}); |
|
| 738 | + $r->bind('{var1}', ['namespace' => 'Space'], function() {}); |
|
| 739 | 739 | }); |
| 740 | 740 | }); |
| 741 | 741 | |
@@ -764,10 +764,10 @@ discard block |
||
| 764 | 764 | $r = $this->router; |
| 765 | 765 | |
| 766 | 766 | $mw1 = function($request, $response, $next) { |
| 767 | - return '1' . $next() . '1'; |
|
| 767 | + return '1'.$next().'1'; |
|
| 768 | 768 | }; |
| 769 | 769 | $mw2 = function($request, $response, $next) { |
| 770 | - return '2' . $next() . '2'; |
|
| 770 | + return '2'.$next().'2'; |
|
| 771 | 771 | }; |
| 772 | 772 | |
| 773 | 773 | $r->apply($mw1, $mw2); |
@@ -794,9 +794,9 @@ discard block |
||
| 794 | 794 | $r = $this->router; |
| 795 | 795 | |
| 796 | 796 | $r->apply(function($request, $response, $next) { |
| 797 | - return '1' . $next() . '1'; |
|
| 797 | + return '1'.$next().'1'; |
|
| 798 | 798 | })->apply(function($request, $response, $next) { |
| 799 | - return '2' . $next() . '2'; |
|
| 799 | + return '2'.$next().'2'; |
|
| 800 | 800 | }); |
| 801 | 801 | |
| 802 | 802 | $route = $r->bind('/foo/bar', function($route) { |
@@ -815,19 +815,19 @@ discard block |
||
| 815 | 815 | $r = $this->router; |
| 816 | 816 | |
| 817 | 817 | $r->apply(function($request, $response, $next) { |
| 818 | - return '1' . $next() . '1'; |
|
| 818 | + return '1'.$next().'1'; |
|
| 819 | 819 | }); |
| 820 | 820 | |
| 821 | - $r->bind('foo/{foo}', ['name' => 'foo'], function () { |
|
| 821 | + $r->bind('foo/{foo}', ['name' => 'foo'], function() { |
|
| 822 | 822 | return 'A'; |
| 823 | 823 | }); |
| 824 | 824 | |
| 825 | 825 | $r->group('bar', function($r) { |
| 826 | - $r->bind('{bar}', ['name' => 'bar'], function () { |
|
| 826 | + $r->bind('{bar}', ['name' => 'bar'], function() { |
|
| 827 | 827 | return 'A'; |
| 828 | 828 | }); |
| 829 | 829 | })->apply(function($request, $response, $next) { |
| 830 | - return '2' . $next() . '2'; |
|
| 830 | + return '2'.$next().'2'; |
|
| 831 | 831 | }); |
| 832 | 832 | |
| 833 | 833 | $route = $r->route('foo/foo'); |