@@ -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']); |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | it("supports lowercase method names", function() { |
90 | 90 | |
91 | 91 | $r = $this->router; |
92 | - $r->bind('foo/bar', ['methods' => ['POST', 'PUT']], function () {}); |
|
92 | + $r->bind('foo/bar', ['methods' => ['POST', 'PUT']], function() {}); |
|
93 | 93 | |
94 | 94 | $route = $r->route('foo/bar', 'post'); |
95 | 95 | expect($route->getMethods())->toBe(['POST', 'PUT']); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $r->basePath('app'); |
137 | 137 | |
138 | 138 | $r->group(['host' => 'www.{domain}.com', 'scheme' => 'https'], function($r) { |
139 | - $r->bind('foo/{bar}', ['name' => 'foo'], function () {}); |
|
139 | + $r->bind('foo/{bar}', ['name' => 'foo'], function() {}); |
|
140 | 140 | }); |
141 | 141 | |
142 | 142 | $link = $r->link('foo', [ |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | $r = $this->router; |
153 | 153 | $r->group('foo', ['name' => 'foz'], function($r) { |
154 | 154 | $r->group('bar', ['name' => 'baz'], function($r) { |
155 | - $r->bind('{var1}', ['name' => 'quz'], function () {}); |
|
155 | + $r->bind('{var1}', ['name' => 'quz'], function() {}); |
|
156 | 156 | }); |
157 | 157 | }); |
158 | 158 | |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | |
166 | 166 | $r = $this->router; |
167 | 167 | $r->group('{locale:en|fr}', ['persist' => 'locale'], function($r) { |
168 | - $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function () {}); |
|
168 | + $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function() {}); |
|
169 | 169 | }); |
170 | 170 | |
171 | 171 | $r->route('fr/post/index'); |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | |
191 | 191 | $r = $this->router; |
192 | 192 | $r->group('{locale:en|fr}', ['persist' => 'locale'], function($r) { |
193 | - $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function () {}); |
|
193 | + $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function() {}); |
|
194 | 194 | }); |
195 | 195 | |
196 | 196 | $r->route('fr/post/index'); |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | it("routes on a simple route", function() { |
222 | 222 | |
223 | 223 | $r = $this->router; |
224 | - $r->bind('foo/bar', function () {}); |
|
224 | + $r->bind('foo/bar', function() {}); |
|
225 | 225 | |
226 | 226 | $route = $r->route('foo/bar', 'GET'); |
227 | 227 | expect($this->export($route->request))->toEqual([ |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | it("routes on a named route", function() { |
242 | 242 | |
243 | 243 | $r = $this->router; |
244 | - $r->bind('foo/bar', ['name' => 'foo'], function () {}); |
|
244 | + $r->bind('foo/bar', ['name' => 'foo'], function() {}); |
|
245 | 245 | |
246 | 246 | $route = $r->route('foo/bar', 'GET'); |
247 | 247 | expect($route->name)->toBe('foo'); |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | it("supports empty as index route", function() { |
257 | 257 | |
258 | 258 | $r = $this->router; |
259 | - $r->bind('', function () {}); |
|
259 | + $r->bind('', function() {}); |
|
260 | 260 | |
261 | 261 | $route = $r->route('', 'GET'); |
262 | 262 | expect($this->export($route->request))->toEqual([ |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | it("supports a slash as indes route", function() { |
272 | 272 | |
273 | 273 | $r = $this->router; |
274 | - $r->bind('/', function () {}); |
|
274 | + $r->bind('/', function() {}); |
|
275 | 275 | |
276 | 276 | $route = $r->route('', 'GET'); |
277 | 277 | expect($this->export($route->request))->toEqual([ |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | $r->get('foo/{var1:\d+}', ['host' => '{subdomain:foo}.{domain}.bar'], function() {}); |
414 | 414 | |
415 | 415 | $route = $r->route('foo/25', 'GET', 'foo.biz.bar'); |
416 | - expect($route->params)->toBe([ 'subdomain' => 'foo', 'domain' => 'biz', 'var1' => '25']); |
|
416 | + expect($route->params)->toBe(['subdomain' => 'foo', 'domain' => 'biz', 'var1' => '25']); |
|
417 | 417 | |
418 | 418 | try { |
419 | 419 | $route = $r->route('foo/bar', 'GET', 'foo.biz.bar'); |
@@ -441,13 +441,13 @@ discard block |
||
441 | 441 | it("supports RESTful routes", function() { |
442 | 442 | |
443 | 443 | $r = $this->router; |
444 | - $r->get('foo/bar', function () {}); |
|
445 | - $r->head('foo/bar', function () {}); |
|
446 | - $r->post('foo/bar', function () {}); |
|
447 | - $r->put('foo/bar', function () {}); |
|
448 | - $r->patch('foo/bar', function () {}); |
|
449 | - $r->delete('foo/bar', function () {}); |
|
450 | - $r->options('foo/bar', function () {}); |
|
444 | + $r->get('foo/bar', function() {}); |
|
445 | + $r->head('foo/bar', function() {}); |
|
446 | + $r->post('foo/bar', function() {}); |
|
447 | + $r->put('foo/bar', function() {}); |
|
448 | + $r->patch('foo/bar', function() {}); |
|
449 | + $r->delete('foo/bar', function() {}); |
|
450 | + $r->options('foo/bar', function() {}); |
|
451 | 451 | |
452 | 452 | $methods = ['OPTIONS', 'DELETE', 'PATCH', 'PUT', 'POST', 'HEAD', 'GET']; |
453 | 453 | |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | it("matches relationships based routes", function() { |
478 | 478 | |
479 | 479 | $r = $this->router; |
480 | - $r->get('[/{relations:[^/]+/[^/:][^/]*}]*/comment[/{id:[^/:][^/]*}][/:{action}]', function () {}); |
|
480 | + $r->get('[/{relations:[^/]+/[^/:][^/]*}]*/comment[/{id:[^/:][^/]*}][/:{action}]', function() {}); |
|
481 | 481 | |
482 | 482 | $route = $r->route('blog/1/post/22/comment/:show', 'GET'); |
483 | 483 | expect($route->params)->toBe([ |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | it("dispatches HEAD requests on matching GET routes if the HEAD routes are missing", function() { |
495 | 495 | |
496 | 496 | $r = $this->router; |
497 | - $r->get('foo/bar', function () { return 'GET'; }); |
|
497 | + $r->get('foo/bar', function() { return 'GET'; }); |
|
498 | 498 | |
499 | 499 | $route = $r->route('foo/bar', 'HEAD'); |
500 | 500 | expect($route->getMethods())->toBe(['GET']); |
@@ -505,8 +505,8 @@ discard block |
||
505 | 505 | |
506 | 506 | $r = $this->router; |
507 | 507 | |
508 | - $r->head('foo/bar', function () { return 'HEAD'; }); |
|
509 | - $r->get('foo/bar', function () { return 'GET'; }); |
|
508 | + $r->head('foo/bar', function() { return 'HEAD'; }); |
|
509 | + $r->get('foo/bar', function() { return 'GET'; }); |
|
510 | 510 | |
511 | 511 | $route = $r->route('foo/bar', 'HEAD'); |
512 | 512 | expect($route->getMethods())->toBe(['GET', 'HEAD']); |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | it("supports requests as a list of arguments", function() { |
517 | 517 | |
518 | 518 | $r = $this->router; |
519 | - $r->bind('foo/bar', function () {}); |
|
519 | + $r->bind('foo/bar', function() {}); |
|
520 | 520 | |
521 | 521 | $route = $r->route('foo/bar', 'GET'); |
522 | 522 | expect($this->export($route->request))->toEqual([ |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | |
531 | 531 | it("supports requests as an object", function() { |
532 | 532 | $r = $this->router; |
533 | - $r->bind('foo/bar', function () {}); |
|
533 | + $r->bind('foo/bar', function() {}); |
|
534 | 534 | |
535 | 535 | $request = Double::instance(['implements' => ServerRequestInterface::class]); |
536 | 536 | $uri = Double::instance(['implements' => UriInterface::class]); |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | it("supports requests as an array", function() { |
551 | 551 | |
552 | 552 | $r = $this->router; |
553 | - $r->bind('foo/bar', function () {}); |
|
553 | + $r->bind('foo/bar', function() {}); |
|
554 | 554 | |
555 | 555 | $route = $r->route(['path' =>'foo/bar'], 'GET'); |
556 | 556 | expect($this->export($route->request))->toEqual([ |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | |
599 | 599 | $r = $this->router; |
600 | 600 | $r->group('foo', function($r) { |
601 | - $r->bind('{var1}', function () {}); |
|
601 | + $r->bind('{var1}', function() {}); |
|
602 | 602 | }); |
603 | 603 | |
604 | 604 | }); |
@@ -611,9 +611,9 @@ discard block |
||
611 | 611 | |
612 | 612 | }); |
613 | 613 | |
614 | - it("throws an exception when the prefix does not match", function () { |
|
614 | + it("throws an exception when the prefix does not match", function() { |
|
615 | 615 | |
616 | - $closure = function () { |
|
616 | + $closure = function() { |
|
617 | 617 | $r = $this->router; |
618 | 618 | $route = $r->route('bar/foo', 'GET'); |
619 | 619 | }; |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | |
629 | 629 | $r = $this->router; |
630 | 630 | $r->group('foo', function($r) { |
631 | - $r->bind('[{var1}]', function () {}); |
|
631 | + $r->bind('[{var1}]', function() {}); |
|
632 | 632 | }); |
633 | 633 | |
634 | 634 | }); |
@@ -641,9 +641,9 @@ discard block |
||
641 | 641 | |
642 | 642 | }); |
643 | 643 | |
644 | - it("throws an exception when the prefix does not match", function () { |
|
644 | + it("throws an exception when the prefix does not match", function() { |
|
645 | 645 | |
646 | - $closure = function () { |
|
646 | + $closure = function() { |
|
647 | 647 | $r = $this->router; |
648 | 648 | $route = $r->route('bar/foo', 'GET'); |
649 | 649 | }; |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | $r = $this->router; |
660 | 660 | $r->group('foo', ['host' => 'foo.{domain}.bar'], function($r) { |
661 | 661 | $r->group('bar', function($r) { |
662 | - $r->bind('{var1}', function () {}); |
|
662 | + $r->bind('{var1}', function() {}); |
|
663 | 663 | }); |
664 | 664 | }); |
665 | 665 | |
@@ -676,9 +676,9 @@ discard block |
||
676 | 676 | |
677 | 677 | }); |
678 | 678 | |
679 | - it("throws an exception when the host does not match", function () { |
|
679 | + it("throws an exception when the host does not match", function() { |
|
680 | 680 | |
681 | - $closure = function () { |
|
681 | + $closure = function() { |
|
682 | 682 | $r = $this->router; |
683 | 683 | $route = $r->route('http://bar.hello.foo/foo/bar/baz', 'GET'); |
684 | 684 | }; |
@@ -694,7 +694,7 @@ discard block |
||
694 | 694 | $r = $this->router; |
695 | 695 | $r->group('foo', ['scheme' => 'http'], function($r) { |
696 | 696 | $r->group('bar', function($r) { |
697 | - $r->bind('{var1}', function () {}); |
|
697 | + $r->bind('{var1}', function() {}); |
|
698 | 698 | }); |
699 | 699 | }); |
700 | 700 | |
@@ -710,9 +710,9 @@ discard block |
||
710 | 710 | |
711 | 711 | }); |
712 | 712 | |
713 | - it("throws an exception when route is not found", function () { |
|
713 | + it("throws an exception when route is not found", function() { |
|
714 | 714 | |
715 | - $closure = function () { |
|
715 | + $closure = function() { |
|
716 | 716 | $r = $this->router; |
717 | 717 | $route = $r->route('https://domain.com/foo/bar/baz', 'GET'); |
718 | 718 | }; |
@@ -726,7 +726,7 @@ discard block |
||
726 | 726 | $r = $this->router; |
727 | 727 | $r->group('foo', ['namespace' => 'My'], function($r) { |
728 | 728 | $r->group('bar', ['namespace' => 'Name'], function($r) { |
729 | - $r->bind('{var1}', ['namespace' => 'Space'], function () {}); |
|
729 | + $r->bind('{var1}', ['namespace' => 'Space'], function() {}); |
|
730 | 730 | }); |
731 | 731 | }); |
732 | 732 | |
@@ -755,10 +755,10 @@ discard block |
||
755 | 755 | $r = $this->router; |
756 | 756 | |
757 | 757 | $mw1 = function($request, $response, $next) { |
758 | - return '1' . $next() . '1'; |
|
758 | + return '1'.$next().'1'; |
|
759 | 759 | }; |
760 | 760 | $mw2 = function($request, $response, $next) { |
761 | - return '2' . $next() . '2'; |
|
761 | + return '2'.$next().'2'; |
|
762 | 762 | }; |
763 | 763 | |
764 | 764 | $r->apply($mw1, $mw2); |
@@ -785,9 +785,9 @@ discard block |
||
785 | 785 | $r = $this->router; |
786 | 786 | |
787 | 787 | $r->apply(function($request, $response, $next) { |
788 | - return '1' . $next() . '1'; |
|
788 | + return '1'.$next().'1'; |
|
789 | 789 | })->apply(function($request, $response, $next) { |
790 | - return '2' . $next() . '2'; |
|
790 | + return '2'.$next().'2'; |
|
791 | 791 | }); |
792 | 792 | |
793 | 793 | $route = $r->bind('/foo/bar', function($route) { |
@@ -806,19 +806,19 @@ discard block |
||
806 | 806 | $r = $this->router; |
807 | 807 | |
808 | 808 | $r->apply(function($request, $response, $next) { |
809 | - return '1' . $next() . '1'; |
|
809 | + return '1'.$next().'1'; |
|
810 | 810 | }); |
811 | 811 | |
812 | - $r->bind('foo/{foo}', ['name' => 'foo'], function () { |
|
812 | + $r->bind('foo/{foo}', ['name' => 'foo'], function() { |
|
813 | 813 | return 'A'; |
814 | 814 | }); |
815 | 815 | |
816 | 816 | $r->group('bar', function($r) { |
817 | - $r->bind('{bar}', ['name' => 'bar'], function () { |
|
817 | + $r->bind('{bar}', ['name' => 'bar'], function() { |
|
818 | 818 | return 'A'; |
819 | 819 | }); |
820 | 820 | })->apply(function($request, $response, $next) { |
821 | - return '2' . $next() . '2'; |
|
821 | + return '2'.$next().'2'; |
|
822 | 822 | }); |
823 | 823 | |
824 | 824 | $route = $r->route('foo/foo'); |
@@ -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; |