@@ -214,37 +214,37 @@ |
||
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 | - $patternKey = md5($options['pattern'] . '-' . $options['name']); |
|
228 | + $patternKey = md5($options['pattern'] . '-' . $options['name']); |
|
229 | 229 | |
230 | - if (isset($this->_pattern[$scheme][$host][$patternKey])) { |
|
231 | - $route = $this->_pattern[$scheme][$host][$patternKey]; |
|
232 | - } else { |
|
233 | - $this->_hosts[$scheme][$host] = $route->getHost(); |
|
234 | - } |
|
230 | + if (isset($this->_pattern[$scheme][$host][$patternKey])) { |
|
231 | + $route = $this->_pattern[$scheme][$host][$patternKey]; |
|
232 | + } else { |
|
233 | + $this->_hosts[$scheme][$host] = $route->getHost(); |
|
234 | + } |
|
235 | 235 | |
236 | - if (!isset($this->_pattern[$scheme][$host][$patternKey])) { |
|
237 | - $this->_pattern[$scheme][$host][$patternKey] = $route; |
|
238 | - } |
|
236 | + if (!isset($this->_pattern[$scheme][$host][$patternKey])) { |
|
237 | + $this->_pattern[$scheme][$host][$patternKey] = $route; |
|
238 | + } |
|
239 | 239 | |
240 | - $methods = $route->getMethods(); |
|
241 | - foreach ($methods as $method) { |
|
242 | - $this->_routes[$scheme][$host][strtoupper($method)][] = $route; |
|
243 | - } |
|
240 | + $methods = $route->getMethods(); |
|
241 | + foreach ($methods as $method) { |
|
242 | + $this->_routes[$scheme][$host][strtoupper($method)][] = $route; |
|
243 | + } |
|
244 | 244 | |
245 | - $this->_data[$route->getName()] = $route; |
|
245 | + $this->_data[$route->getName()] = $route; |
|
246 | 246 | |
247 | - return $this; |
|
247 | + return $this; |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -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 | } |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | $options['host'] = $this->_hosts[$scheme][$host]; |
226 | 226 | } |
227 | 227 | |
228 | - $patternKey = md5($options['pattern'] . '-' . $options['name']); |
|
228 | + $patternKey = md5($options['pattern'].'-'.$options['name']); |
|
229 | 229 | |
230 | 230 | if (isset($this->_pattern[$scheme][$host][$patternKey])) { |
231 | 231 | $route = $this->_pattern[$scheme][$host][$patternKey]; |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | $options['host'] = $this->_hosts[$scheme][$host]; |
290 | 290 | } |
291 | 291 | |
292 | - $patternKey = md5($options['pattern'] . '-' . $options['name']); |
|
292 | + $patternKey = md5($options['pattern'].'-'.$options['name']); |
|
293 | 293 | |
294 | 294 | if (isset($this->_pattern[$scheme][$host][$patternKey])) { |
295 | 295 | $instance = $this->_pattern[$scheme][$host][$patternKey]; |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | $this->_pattern[$scheme][$host][$patternKey] = $instance; |
304 | 304 | } |
305 | 305 | |
306 | - $methods = $options['methods'] ? (array)$options['methods'] : []; |
|
306 | + $methods = $options['methods'] ? (array) $options['methods'] : []; |
|
307 | 307 | |
308 | 308 | $instance->allow($methods); |
309 | 309 | |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | $request = $parsed + $request; |
431 | 431 | } |
432 | 432 | |
433 | - $request['path'] = (ltrim((string)strtok($request['path'], '?'), '/')); |
|
433 | + $request['path'] = (ltrim((string) strtok($request['path'], '?'), '/')); |
|
434 | 434 | $request['method'] = strtoupper($request['method']); |
435 | 435 | |
436 | 436 | 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']); |
@@ -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']); |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | |
107 | 107 | it("matches on same path different methods", function() { |
108 | 108 | $r = $this->router; |
109 | - $r->bind('foo/bar', ['name' => 'foo', 'methods' => ['POST']], function () {}); |
|
110 | - $r->bind('foo/bar', ['name' => 'bar', 'methods' => ['PUT']], function () {}); |
|
109 | + $r->bind('foo/bar', ['name' => 'foo', 'methods' => ['POST']], function() {}); |
|
110 | + $r->bind('foo/bar', ['name' => 'bar', 'methods' => ['PUT']], function() {}); |
|
111 | 111 | |
112 | 112 | $route = $r->route('foo/bar', 'POST'); |
113 | 113 | expect($route->name)->toBe('foo'); |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | $r->basePath('app'); |
149 | 149 | |
150 | 150 | $r->group(['host' => 'www.{domain}.com', 'scheme' => 'https'], function($r) { |
151 | - $r->bind('foo/{bar}', ['name' => 'foo'], function () {}); |
|
151 | + $r->bind('foo/{bar}', ['name' => 'foo'], function() {}); |
|
152 | 152 | }); |
153 | 153 | |
154 | 154 | $link = $r->link('foo', [ |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | $r = $this->router; |
165 | 165 | $r->group('foo', ['name' => 'foz'], function($r) { |
166 | 166 | $r->group('bar', ['name' => 'baz'], function($r) { |
167 | - $r->bind('{var1}', ['name' => 'quz'], function () {}); |
|
167 | + $r->bind('{var1}', ['name' => 'quz'], function() {}); |
|
168 | 168 | }); |
169 | 169 | }); |
170 | 170 | |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | |
178 | 178 | $r = $this->router; |
179 | 179 | $r->group('{locale:en|fr}', ['persist' => 'locale'], function($r) { |
180 | - $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function () {}); |
|
180 | + $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function() {}); |
|
181 | 181 | }); |
182 | 182 | |
183 | 183 | $r->route('fr/post/index'); |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | |
203 | 203 | $r = $this->router; |
204 | 204 | $r->group('{locale:en|fr}', ['persist' => 'locale'], function($r) { |
205 | - $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function () {}); |
|
205 | + $r->bind('{controller}/{action}[/{id}]', ['name' => 'controller'], function() {}); |
|
206 | 206 | }); |
207 | 207 | |
208 | 208 | $r->route('fr/post/index'); |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | it("routes on a simple route", function() { |
234 | 234 | |
235 | 235 | $r = $this->router; |
236 | - $r->bind('foo/bar', function () {}); |
|
236 | + $r->bind('foo/bar', function() {}); |
|
237 | 237 | |
238 | 238 | $route = $r->route('foo/bar', 'GET'); |
239 | 239 | expect($this->export($route->request))->toEqual([ |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | it("routes on a named route", function() { |
254 | 254 | |
255 | 255 | $r = $this->router; |
256 | - $r->bind('foo/bar', ['name' => 'foo'], function () {}); |
|
256 | + $r->bind('foo/bar', ['name' => 'foo'], function() {}); |
|
257 | 257 | |
258 | 258 | $route = $r->route('foo/bar', 'GET'); |
259 | 259 | expect($route->name)->toBe('foo'); |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | it("supports empty as index route", function() { |
269 | 269 | |
270 | 270 | $r = $this->router; |
271 | - $r->bind('', function () {}); |
|
271 | + $r->bind('', function() {}); |
|
272 | 272 | |
273 | 273 | $route = $r->route('', 'GET'); |
274 | 274 | expect($this->export($route->request))->toEqual([ |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | it("supports a slash as indes route", function() { |
284 | 284 | |
285 | 285 | $r = $this->router; |
286 | - $r->bind('/', function () {}); |
|
286 | + $r->bind('/', function() {}); |
|
287 | 287 | |
288 | 288 | $route = $r->route('', 'GET'); |
289 | 289 | expect($this->export($route->request))->toEqual([ |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | $r->get('foo/{var1:\d+}', ['host' => '{subdomain:foo}.{domain}.bar'], function() {}); |
426 | 426 | |
427 | 427 | $route = $r->route('foo/25', 'GET', 'foo.biz.bar'); |
428 | - expect($route->params)->toBe([ 'subdomain' => 'foo', 'domain' => 'biz', 'var1' => '25']); |
|
428 | + expect($route->params)->toBe(['subdomain' => 'foo', 'domain' => 'biz', 'var1' => '25']); |
|
429 | 429 | |
430 | 430 | try { |
431 | 431 | $route = $r->route('foo/bar', 'GET', 'foo.biz.bar'); |
@@ -453,13 +453,13 @@ discard block |
||
453 | 453 | it("supports RESTful routes", function() { |
454 | 454 | |
455 | 455 | $r = $this->router; |
456 | - $r->get('foo/bar', function () {}); |
|
457 | - $r->head('foo/bar', function () {}); |
|
458 | - $r->post('foo/bar', function () {}); |
|
459 | - $r->put('foo/bar', function () {}); |
|
460 | - $r->patch('foo/bar', function () {}); |
|
461 | - $r->delete('foo/bar', function () {}); |
|
462 | - $r->options('foo/bar', function () {}); |
|
456 | + $r->get('foo/bar', function() {}); |
|
457 | + $r->head('foo/bar', function() {}); |
|
458 | + $r->post('foo/bar', function() {}); |
|
459 | + $r->put('foo/bar', function() {}); |
|
460 | + $r->patch('foo/bar', function() {}); |
|
461 | + $r->delete('foo/bar', function() {}); |
|
462 | + $r->options('foo/bar', function() {}); |
|
463 | 463 | |
464 | 464 | $methods = ['OPTIONS', 'DELETE', 'PATCH', 'PUT', 'POST', 'HEAD', 'GET']; |
465 | 465 | |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | it("matches relationships based routes", function() { |
490 | 490 | |
491 | 491 | $r = $this->router; |
492 | - $r->get('[/{relations:[^/]+/[^/:][^/]*}]*/comment[/{id:[^/:][^/]*}][/:{action}]', function () {}); |
|
492 | + $r->get('[/{relations:[^/]+/[^/:][^/]*}]*/comment[/{id:[^/:][^/]*}][/:{action}]', function() {}); |
|
493 | 493 | |
494 | 494 | $route = $r->route('blog/1/post/22/comment/:show', 'GET'); |
495 | 495 | expect($route->params)->toBe([ |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | it("dispatches HEAD requests on matching GET routes if the HEAD routes are missing", function() { |
507 | 507 | |
508 | 508 | $r = $this->router; |
509 | - $r->get('foo/bar', function () { return 'GET'; }); |
|
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']); |
@@ -517,8 +517,8 @@ discard block |
||
517 | 517 | |
518 | 518 | $r = $this->router; |
519 | 519 | |
520 | - $r->head('foo/bar', function () { return 'HEAD'; }); |
|
521 | - $r->get('foo/bar', function () { return 'GET'; }); |
|
520 | + $r->head('foo/bar', function() { return 'HEAD'; }); |
|
521 | + $r->get('foo/bar', function() { return 'GET'; }); |
|
522 | 522 | |
523 | 523 | $route = $r->route('foo/bar', 'HEAD'); |
524 | 524 | expect($route->getMethods())->toBe(['GET', 'HEAD']); |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | it("supports requests as a list of arguments", function() { |
529 | 529 | |
530 | 530 | $r = $this->router; |
531 | - $r->bind('foo/bar', function () {}); |
|
531 | + $r->bind('foo/bar', function() {}); |
|
532 | 532 | |
533 | 533 | $route = $r->route('foo/bar', 'GET'); |
534 | 534 | expect($this->export($route->request))->toEqual([ |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | |
543 | 543 | it("supports requests as an object", function() { |
544 | 544 | $r = $this->router; |
545 | - $r->bind('foo/bar', function () {}); |
|
545 | + $r->bind('foo/bar', function() {}); |
|
546 | 546 | |
547 | 547 | $request = Double::instance(['implements' => ServerRequestInterface::class]); |
548 | 548 | $uri = Double::instance(['implements' => UriInterface::class]); |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | it("supports requests as an array", function() { |
563 | 563 | |
564 | 564 | $r = $this->router; |
565 | - $r->bind('foo/bar', function () {}); |
|
565 | + $r->bind('foo/bar', function() {}); |
|
566 | 566 | |
567 | 567 | $route = $r->route(['path' =>'foo/bar'], 'GET'); |
568 | 568 | expect($this->export($route->request))->toEqual([ |
@@ -610,7 +610,7 @@ discard block |
||
610 | 610 | |
611 | 611 | $r = $this->router; |
612 | 612 | $r->group('foo', function($r) { |
613 | - $r->bind('{var1}', function () {}); |
|
613 | + $r->bind('{var1}', function() {}); |
|
614 | 614 | }); |
615 | 615 | |
616 | 616 | }); |
@@ -623,9 +623,9 @@ discard block |
||
623 | 623 | |
624 | 624 | }); |
625 | 625 | |
626 | - it("throws an exception when the prefix does not match", function () { |
|
626 | + it("throws an exception when the prefix does not match", function() { |
|
627 | 627 | |
628 | - $closure = function () { |
|
628 | + $closure = function() { |
|
629 | 629 | $r = $this->router; |
630 | 630 | $route = $r->route('bar/foo', 'GET'); |
631 | 631 | }; |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | |
641 | 641 | $r = $this->router; |
642 | 642 | $r->group('foo', function($r) { |
643 | - $r->bind('[{var1}]', function () {}); |
|
643 | + $r->bind('[{var1}]', function() {}); |
|
644 | 644 | }); |
645 | 645 | |
646 | 646 | }); |
@@ -653,9 +653,9 @@ discard block |
||
653 | 653 | |
654 | 654 | }); |
655 | 655 | |
656 | - it("throws an exception when the prefix does not match", function () { |
|
656 | + it("throws an exception when the prefix does not match", function() { |
|
657 | 657 | |
658 | - $closure = function () { |
|
658 | + $closure = function() { |
|
659 | 659 | $r = $this->router; |
660 | 660 | $route = $r->route('bar/foo', 'GET'); |
661 | 661 | }; |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | $r = $this->router; |
672 | 672 | $r->group('foo', ['host' => 'foo.{domain}.bar'], function($r) { |
673 | 673 | $r->group('bar', function($r) { |
674 | - $r->bind('{var1}', function () {}); |
|
674 | + $r->bind('{var1}', function() {}); |
|
675 | 675 | }); |
676 | 676 | }); |
677 | 677 | |
@@ -688,9 +688,9 @@ discard block |
||
688 | 688 | |
689 | 689 | }); |
690 | 690 | |
691 | - it("throws an exception when the host does not match", function () { |
|
691 | + it("throws an exception when the host does not match", function() { |
|
692 | 692 | |
693 | - $closure = function () { |
|
693 | + $closure = function() { |
|
694 | 694 | $r = $this->router; |
695 | 695 | $route = $r->route('http://bar.hello.foo/foo/bar/baz', 'GET'); |
696 | 696 | }; |
@@ -706,7 +706,7 @@ discard block |
||
706 | 706 | $r = $this->router; |
707 | 707 | $r->group('foo', ['scheme' => 'http'], function($r) { |
708 | 708 | $r->group('bar', function($r) { |
709 | - $r->bind('{var1}', function () {}); |
|
709 | + $r->bind('{var1}', function() {}); |
|
710 | 710 | }); |
711 | 711 | }); |
712 | 712 | |
@@ -722,9 +722,9 @@ discard block |
||
722 | 722 | |
723 | 723 | }); |
724 | 724 | |
725 | - it("throws an exception when route is not found", function () { |
|
725 | + it("throws an exception when route is not found", function() { |
|
726 | 726 | |
727 | - $closure = function () { |
|
727 | + $closure = function() { |
|
728 | 728 | $r = $this->router; |
729 | 729 | $route = $r->route('https://domain.com/foo/bar/baz', 'GET'); |
730 | 730 | }; |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | $r = $this->router; |
739 | 739 | $r->group('foo', ['namespace' => 'My'], function($r) { |
740 | 740 | $r->group('bar', ['namespace' => 'Name'], function($r) { |
741 | - $r->bind('{var1}', ['namespace' => 'Space'], function () {}); |
|
741 | + $r->bind('{var1}', ['namespace' => 'Space'], function() {}); |
|
742 | 742 | }); |
743 | 743 | }); |
744 | 744 | |
@@ -767,10 +767,10 @@ discard block |
||
767 | 767 | $r = $this->router; |
768 | 768 | |
769 | 769 | $mw1 = function($request, $response, $next) { |
770 | - return '1' . $next() . '1'; |
|
770 | + return '1'.$next().'1'; |
|
771 | 771 | }; |
772 | 772 | $mw2 = function($request, $response, $next) { |
773 | - return '2' . $next() . '2'; |
|
773 | + return '2'.$next().'2'; |
|
774 | 774 | }; |
775 | 775 | |
776 | 776 | $r->apply($mw1, $mw2); |
@@ -797,9 +797,9 @@ discard block |
||
797 | 797 | $r = $this->router; |
798 | 798 | |
799 | 799 | $r->apply(function($request, $response, $next) { |
800 | - return '1' . $next() . '1'; |
|
800 | + return '1'.$next().'1'; |
|
801 | 801 | })->apply(function($request, $response, $next) { |
802 | - return '2' . $next() . '2'; |
|
802 | + return '2'.$next().'2'; |
|
803 | 803 | }); |
804 | 804 | |
805 | 805 | $route = $r->bind('/foo/bar', function($route) { |
@@ -818,19 +818,19 @@ discard block |
||
818 | 818 | $r = $this->router; |
819 | 819 | |
820 | 820 | $r->apply(function($request, $response, $next) { |
821 | - return '1' . $next() . '1'; |
|
821 | + return '1'.$next().'1'; |
|
822 | 822 | }); |
823 | 823 | |
824 | - $r->bind('foo/{foo}', ['name' => 'foo'], function () { |
|
824 | + $r->bind('foo/{foo}', ['name' => 'foo'], function() { |
|
825 | 825 | return 'A'; |
826 | 826 | }); |
827 | 827 | |
828 | 828 | $r->group('bar', function($r) { |
829 | - $r->bind('{bar}', ['name' => 'bar'], function () { |
|
829 | + $r->bind('{bar}', ['name' => 'bar'], function() { |
|
830 | 830 | return 'A'; |
831 | 831 | }); |
832 | 832 | })->apply(function($request, $response, $next) { |
833 | - return '2' . $next() . '2'; |
|
833 | + return '2'.$next().'2'; |
|
834 | 834 | }); |
835 | 835 | |
836 | 836 | $route = $r->route('foo/foo'); |