@@ -10,140 +10,140 @@ |
||
10 | 10 | |
11 | 11 | class RouterTest extends \PHPUnit\Framework\TestCase |
12 | 12 | { |
13 | - /** @var Router */ |
|
14 | - protected $router; |
|
13 | + /** @var Router */ |
|
14 | + protected $router; |
|
15 | 15 | |
16 | - public function setUp() |
|
17 | - { |
|
16 | + public function setUp() |
|
17 | + { |
|
18 | 18 | if( !class_exists( \Slim\Router::class, false ) ) { |
19 | 19 | $this->markTestSkipped( '\Slim\Router is not available' ); |
20 | 20 | } |
21 | 21 | |
22 | - $this->router = new \Aimeos\Slim\Router; |
|
23 | - } |
|
24 | - |
|
25 | - public function testRelativePathFor() |
|
26 | - { |
|
27 | - $this->router->setBasePath('/base/path'); |
|
28 | - |
|
29 | - $methods = ['GET']; |
|
30 | - $pattern = '/hello/{first:\w+}/{last}'; |
|
31 | - $callable = function ($request, $response, $args) { |
|
32 | - echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
33 | - }; |
|
34 | - $route = $this->router->map($methods, $pattern, $callable); |
|
35 | - $route->setName('foo'); |
|
36 | - |
|
37 | - $this->assertEquals( |
|
38 | - '/hello/josh/lockhart', |
|
39 | - $this->router->relativePathFor('foo', ['first' => 'josh', 'last' => 'lockhart']) |
|
40 | - ); |
|
41 | - } |
|
42 | - |
|
43 | - public function testPathForWithNoBasePath() |
|
44 | - { |
|
45 | - $this->router->setBasePath(''); |
|
46 | - |
|
47 | - $methods = ['GET']; |
|
48 | - $pattern = '/hello/{first:\w+}/{last}'; |
|
49 | - $callable = function ($request, $response, $args) { |
|
50 | - echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
51 | - }; |
|
52 | - $route = $this->router->map($methods, $pattern, $callable); |
|
53 | - $route->setName('foo'); |
|
54 | - |
|
55 | - $this->assertEquals( |
|
56 | - '/hello/josh/lockhart', |
|
57 | - $this->router->pathFor('foo', ['first' => 'josh', 'last' => 'lockhart']) |
|
58 | - ); |
|
59 | - } |
|
60 | - |
|
61 | - public function testPathForWithBasePath() |
|
62 | - { |
|
63 | - $methods = ['GET']; |
|
64 | - $pattern = '/hello/{first:\w+}/{last}'; |
|
65 | - $callable = function ($request, $response, $args) { |
|
66 | - echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
67 | - }; |
|
68 | - $this->router->setBasePath('/base/path'); |
|
69 | - $route = $this->router->map($methods, $pattern, $callable); |
|
70 | - $route->setName('foo'); |
|
71 | - |
|
72 | - $this->assertEquals( |
|
73 | - '/base/path/hello/josh/lockhart', |
|
74 | - $this->router->pathFor('foo', ['first' => 'josh', 'last' => 'lockhart']) |
|
75 | - ); |
|
76 | - } |
|
77 | - |
|
78 | - public function testPathForWithOptionalParameters() |
|
79 | - { |
|
80 | - $methods = ['GET']; |
|
81 | - $pattern = '/archive/{year}[/{month:[\d:{2}]}[/d/{day}]]'; |
|
82 | - $callable = function ($request, $response, $args) { |
|
83 | - return $response; |
|
84 | - }; |
|
85 | - $route = $this->router->map($methods, $pattern, $callable); |
|
86 | - $route->setName('foo'); |
|
87 | - |
|
88 | - $this->assertEquals( |
|
89 | - '/archive/2015', |
|
90 | - $this->router->pathFor('foo', ['year' => '2015']) |
|
91 | - ); |
|
92 | - $this->assertEquals( |
|
93 | - '/archive/2015/07', |
|
94 | - $this->router->pathFor('foo', ['year' => '2015', 'month' => '07']) |
|
95 | - ); |
|
96 | - $this->assertEquals( |
|
97 | - '/archive/2015/07/d/19', |
|
98 | - $this->router->pathFor('foo', ['year' => '2015', 'month' => '07', 'day' => '19']) |
|
99 | - ); |
|
100 | - } |
|
101 | - |
|
102 | - public function testPathForWithSurplusRouteParameters() |
|
103 | - { |
|
104 | - $methods = ['GET']; |
|
105 | - $pattern = '/hello/{name}'; |
|
106 | - $callable = function ($request, $response, $args) { |
|
107 | - echo sprintf('Hello %s', $args['name']); |
|
108 | - }; |
|
109 | - $route = $this->router->map($methods, $pattern, $callable); |
|
110 | - $route->setName('foo'); |
|
111 | - |
|
112 | - $this->assertEquals( |
|
113 | - '/hello/josh?a=b', |
|
114 | - $this->router->pathFor('foo', ['name' => 'josh', 'a' => 'b']) |
|
115 | - ); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @expectedException \InvalidArgumentException |
|
120 | - */ |
|
121 | - public function testPathForWithMissingSegmentData() |
|
122 | - { |
|
123 | - $methods = ['GET']; |
|
124 | - $pattern = '/hello/{first}/{last}'; |
|
125 | - $callable = function ($request, $response, $args) { |
|
126 | - echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
127 | - }; |
|
128 | - $route = $this->router->map($methods, $pattern, $callable); |
|
129 | - $route->setName('foo'); |
|
130 | - |
|
131 | - $this->router->pathFor('foo', ['last' => 'lockhart']); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * @expectedException \RuntimeException |
|
136 | - */ |
|
137 | - public function testPathForRouteNotExists() |
|
138 | - { |
|
139 | - $methods = ['GET']; |
|
140 | - $pattern = '/hello/{first}/{last}'; |
|
141 | - $callable = function ($request, $response, $args) { |
|
142 | - echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
143 | - }; |
|
144 | - $route = $this->router->map($methods, $pattern, $callable); |
|
145 | - $route->setName('foo'); |
|
146 | - |
|
147 | - $this->router->pathFor('bar', ['first' => 'josh', 'last' => 'lockhart']); |
|
148 | - } |
|
22 | + $this->router = new \Aimeos\Slim\Router; |
|
23 | + } |
|
24 | + |
|
25 | + public function testRelativePathFor() |
|
26 | + { |
|
27 | + $this->router->setBasePath('/base/path'); |
|
28 | + |
|
29 | + $methods = ['GET']; |
|
30 | + $pattern = '/hello/{first:\w+}/{last}'; |
|
31 | + $callable = function ($request, $response, $args) { |
|
32 | + echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
33 | + }; |
|
34 | + $route = $this->router->map($methods, $pattern, $callable); |
|
35 | + $route->setName('foo'); |
|
36 | + |
|
37 | + $this->assertEquals( |
|
38 | + '/hello/josh/lockhart', |
|
39 | + $this->router->relativePathFor('foo', ['first' => 'josh', 'last' => 'lockhart']) |
|
40 | + ); |
|
41 | + } |
|
42 | + |
|
43 | + public function testPathForWithNoBasePath() |
|
44 | + { |
|
45 | + $this->router->setBasePath(''); |
|
46 | + |
|
47 | + $methods = ['GET']; |
|
48 | + $pattern = '/hello/{first:\w+}/{last}'; |
|
49 | + $callable = function ($request, $response, $args) { |
|
50 | + echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
51 | + }; |
|
52 | + $route = $this->router->map($methods, $pattern, $callable); |
|
53 | + $route->setName('foo'); |
|
54 | + |
|
55 | + $this->assertEquals( |
|
56 | + '/hello/josh/lockhart', |
|
57 | + $this->router->pathFor('foo', ['first' => 'josh', 'last' => 'lockhart']) |
|
58 | + ); |
|
59 | + } |
|
60 | + |
|
61 | + public function testPathForWithBasePath() |
|
62 | + { |
|
63 | + $methods = ['GET']; |
|
64 | + $pattern = '/hello/{first:\w+}/{last}'; |
|
65 | + $callable = function ($request, $response, $args) { |
|
66 | + echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
67 | + }; |
|
68 | + $this->router->setBasePath('/base/path'); |
|
69 | + $route = $this->router->map($methods, $pattern, $callable); |
|
70 | + $route->setName('foo'); |
|
71 | + |
|
72 | + $this->assertEquals( |
|
73 | + '/base/path/hello/josh/lockhart', |
|
74 | + $this->router->pathFor('foo', ['first' => 'josh', 'last' => 'lockhart']) |
|
75 | + ); |
|
76 | + } |
|
77 | + |
|
78 | + public function testPathForWithOptionalParameters() |
|
79 | + { |
|
80 | + $methods = ['GET']; |
|
81 | + $pattern = '/archive/{year}[/{month:[\d:{2}]}[/d/{day}]]'; |
|
82 | + $callable = function ($request, $response, $args) { |
|
83 | + return $response; |
|
84 | + }; |
|
85 | + $route = $this->router->map($methods, $pattern, $callable); |
|
86 | + $route->setName('foo'); |
|
87 | + |
|
88 | + $this->assertEquals( |
|
89 | + '/archive/2015', |
|
90 | + $this->router->pathFor('foo', ['year' => '2015']) |
|
91 | + ); |
|
92 | + $this->assertEquals( |
|
93 | + '/archive/2015/07', |
|
94 | + $this->router->pathFor('foo', ['year' => '2015', 'month' => '07']) |
|
95 | + ); |
|
96 | + $this->assertEquals( |
|
97 | + '/archive/2015/07/d/19', |
|
98 | + $this->router->pathFor('foo', ['year' => '2015', 'month' => '07', 'day' => '19']) |
|
99 | + ); |
|
100 | + } |
|
101 | + |
|
102 | + public function testPathForWithSurplusRouteParameters() |
|
103 | + { |
|
104 | + $methods = ['GET']; |
|
105 | + $pattern = '/hello/{name}'; |
|
106 | + $callable = function ($request, $response, $args) { |
|
107 | + echo sprintf('Hello %s', $args['name']); |
|
108 | + }; |
|
109 | + $route = $this->router->map($methods, $pattern, $callable); |
|
110 | + $route->setName('foo'); |
|
111 | + |
|
112 | + $this->assertEquals( |
|
113 | + '/hello/josh?a=b', |
|
114 | + $this->router->pathFor('foo', ['name' => 'josh', 'a' => 'b']) |
|
115 | + ); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @expectedException \InvalidArgumentException |
|
120 | + */ |
|
121 | + public function testPathForWithMissingSegmentData() |
|
122 | + { |
|
123 | + $methods = ['GET']; |
|
124 | + $pattern = '/hello/{first}/{last}'; |
|
125 | + $callable = function ($request, $response, $args) { |
|
126 | + echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
127 | + }; |
|
128 | + $route = $this->router->map($methods, $pattern, $callable); |
|
129 | + $route->setName('foo'); |
|
130 | + |
|
131 | + $this->router->pathFor('foo', ['last' => 'lockhart']); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * @expectedException \RuntimeException |
|
136 | + */ |
|
137 | + public function testPathForRouteNotExists() |
|
138 | + { |
|
139 | + $methods = ['GET']; |
|
140 | + $pattern = '/hello/{first}/{last}'; |
|
141 | + $callable = function ($request, $response, $args) { |
|
142 | + echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
143 | + }; |
|
144 | + $route = $this->router->map($methods, $pattern, $callable); |
|
145 | + $route->setName('foo'); |
|
146 | + |
|
147 | + $this->router->pathFor('bar', ['first' => 'josh', 'last' => 'lockhart']); |
|
148 | + } |
|
149 | 149 | } |
@@ -24,37 +24,37 @@ discard block |
||
24 | 24 | |
25 | 25 | public function testRelativePathFor() |
26 | 26 | { |
27 | - $this->router->setBasePath('/base/path'); |
|
27 | + $this->router->setBasePath( '/base/path' ); |
|
28 | 28 | |
29 | 29 | $methods = ['GET']; |
30 | 30 | $pattern = '/hello/{first:\w+}/{last}'; |
31 | - $callable = function ($request, $response, $args) { |
|
32 | - echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
31 | + $callable = function( $request, $response, $args ) { |
|
32 | + echo sprintf( 'Hello %s %s', $args['first'], $args['last'] ); |
|
33 | 33 | }; |
34 | - $route = $this->router->map($methods, $pattern, $callable); |
|
35 | - $route->setName('foo'); |
|
34 | + $route = $this->router->map( $methods, $pattern, $callable ); |
|
35 | + $route->setName( 'foo' ); |
|
36 | 36 | |
37 | 37 | $this->assertEquals( |
38 | 38 | '/hello/josh/lockhart', |
39 | - $this->router->relativePathFor('foo', ['first' => 'josh', 'last' => 'lockhart']) |
|
39 | + $this->router->relativePathFor( 'foo', ['first' => 'josh', 'last' => 'lockhart'] ) |
|
40 | 40 | ); |
41 | 41 | } |
42 | 42 | |
43 | 43 | public function testPathForWithNoBasePath() |
44 | 44 | { |
45 | - $this->router->setBasePath(''); |
|
45 | + $this->router->setBasePath( '' ); |
|
46 | 46 | |
47 | 47 | $methods = ['GET']; |
48 | 48 | $pattern = '/hello/{first:\w+}/{last}'; |
49 | - $callable = function ($request, $response, $args) { |
|
50 | - echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
49 | + $callable = function( $request, $response, $args ) { |
|
50 | + echo sprintf( 'Hello %s %s', $args['first'], $args['last'] ); |
|
51 | 51 | }; |
52 | - $route = $this->router->map($methods, $pattern, $callable); |
|
53 | - $route->setName('foo'); |
|
52 | + $route = $this->router->map( $methods, $pattern, $callable ); |
|
53 | + $route->setName( 'foo' ); |
|
54 | 54 | |
55 | 55 | $this->assertEquals( |
56 | 56 | '/hello/josh/lockhart', |
57 | - $this->router->pathFor('foo', ['first' => 'josh', 'last' => 'lockhart']) |
|
57 | + $this->router->pathFor( 'foo', ['first' => 'josh', 'last' => 'lockhart'] ) |
|
58 | 58 | ); |
59 | 59 | } |
60 | 60 | |
@@ -62,16 +62,16 @@ discard block |
||
62 | 62 | { |
63 | 63 | $methods = ['GET']; |
64 | 64 | $pattern = '/hello/{first:\w+}/{last}'; |
65 | - $callable = function ($request, $response, $args) { |
|
66 | - echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
65 | + $callable = function( $request, $response, $args ) { |
|
66 | + echo sprintf( 'Hello %s %s', $args['first'], $args['last'] ); |
|
67 | 67 | }; |
68 | - $this->router->setBasePath('/base/path'); |
|
69 | - $route = $this->router->map($methods, $pattern, $callable); |
|
70 | - $route->setName('foo'); |
|
68 | + $this->router->setBasePath( '/base/path' ); |
|
69 | + $route = $this->router->map( $methods, $pattern, $callable ); |
|
70 | + $route->setName( 'foo' ); |
|
71 | 71 | |
72 | 72 | $this->assertEquals( |
73 | 73 | '/base/path/hello/josh/lockhart', |
74 | - $this->router->pathFor('foo', ['first' => 'josh', 'last' => 'lockhart']) |
|
74 | + $this->router->pathFor( 'foo', ['first' => 'josh', 'last' => 'lockhart'] ) |
|
75 | 75 | ); |
76 | 76 | } |
77 | 77 | |
@@ -79,23 +79,23 @@ discard block |
||
79 | 79 | { |
80 | 80 | $methods = ['GET']; |
81 | 81 | $pattern = '/archive/{year}[/{month:[\d:{2}]}[/d/{day}]]'; |
82 | - $callable = function ($request, $response, $args) { |
|
82 | + $callable = function( $request, $response, $args ) { |
|
83 | 83 | return $response; |
84 | 84 | }; |
85 | - $route = $this->router->map($methods, $pattern, $callable); |
|
86 | - $route->setName('foo'); |
|
85 | + $route = $this->router->map( $methods, $pattern, $callable ); |
|
86 | + $route->setName( 'foo' ); |
|
87 | 87 | |
88 | 88 | $this->assertEquals( |
89 | 89 | '/archive/2015', |
90 | - $this->router->pathFor('foo', ['year' => '2015']) |
|
90 | + $this->router->pathFor( 'foo', ['year' => '2015'] ) |
|
91 | 91 | ); |
92 | 92 | $this->assertEquals( |
93 | 93 | '/archive/2015/07', |
94 | - $this->router->pathFor('foo', ['year' => '2015', 'month' => '07']) |
|
94 | + $this->router->pathFor( 'foo', ['year' => '2015', 'month' => '07'] ) |
|
95 | 95 | ); |
96 | 96 | $this->assertEquals( |
97 | 97 | '/archive/2015/07/d/19', |
98 | - $this->router->pathFor('foo', ['year' => '2015', 'month' => '07', 'day' => '19']) |
|
98 | + $this->router->pathFor( 'foo', ['year' => '2015', 'month' => '07', 'day' => '19'] ) |
|
99 | 99 | ); |
100 | 100 | } |
101 | 101 | |
@@ -103,15 +103,15 @@ discard block |
||
103 | 103 | { |
104 | 104 | $methods = ['GET']; |
105 | 105 | $pattern = '/hello/{name}'; |
106 | - $callable = function ($request, $response, $args) { |
|
107 | - echo sprintf('Hello %s', $args['name']); |
|
106 | + $callable = function( $request, $response, $args ) { |
|
107 | + echo sprintf( 'Hello %s', $args['name'] ); |
|
108 | 108 | }; |
109 | - $route = $this->router->map($methods, $pattern, $callable); |
|
110 | - $route->setName('foo'); |
|
109 | + $route = $this->router->map( $methods, $pattern, $callable ); |
|
110 | + $route->setName( 'foo' ); |
|
111 | 111 | |
112 | 112 | $this->assertEquals( |
113 | 113 | '/hello/josh?a=b', |
114 | - $this->router->pathFor('foo', ['name' => 'josh', 'a' => 'b']) |
|
114 | + $this->router->pathFor( 'foo', ['name' => 'josh', 'a' => 'b'] ) |
|
115 | 115 | ); |
116 | 116 | } |
117 | 117 | |
@@ -122,13 +122,13 @@ discard block |
||
122 | 122 | { |
123 | 123 | $methods = ['GET']; |
124 | 124 | $pattern = '/hello/{first}/{last}'; |
125 | - $callable = function ($request, $response, $args) { |
|
126 | - echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
125 | + $callable = function( $request, $response, $args ) { |
|
126 | + echo sprintf( 'Hello %s %s', $args['first'], $args['last'] ); |
|
127 | 127 | }; |
128 | - $route = $this->router->map($methods, $pattern, $callable); |
|
129 | - $route->setName('foo'); |
|
128 | + $route = $this->router->map( $methods, $pattern, $callable ); |
|
129 | + $route->setName( 'foo' ); |
|
130 | 130 | |
131 | - $this->router->pathFor('foo', ['last' => 'lockhart']); |
|
131 | + $this->router->pathFor( 'foo', ['last' => 'lockhart'] ); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | { |
139 | 139 | $methods = ['GET']; |
140 | 140 | $pattern = '/hello/{first}/{last}'; |
141 | - $callable = function ($request, $response, $args) { |
|
142 | - echo sprintf('Hello %s %s', $args['first'], $args['last']); |
|
141 | + $callable = function( $request, $response, $args ) { |
|
142 | + echo sprintf( 'Hello %s %s', $args['first'], $args['last'] ); |
|
143 | 143 | }; |
144 | - $route = $this->router->map($methods, $pattern, $callable); |
|
145 | - $route->setName('foo'); |
|
144 | + $route = $this->router->map( $methods, $pattern, $callable ); |
|
145 | + $route->setName( 'foo' ); |
|
146 | 146 | |
147 | - $this->router->pathFor('bar', ['first' => 'josh', 'last' => 'lockhart']); |
|
147 | + $this->router->pathFor( 'bar', ['first' => 'josh', 'last' => 'lockhart'] ); |
|
148 | 148 | } |
149 | 149 | } |
@@ -28,7 +28,8 @@ discard block |
||
28 | 28 | |
29 | 29 | $methods = ['GET']; |
30 | 30 | $pattern = '/hello/{first:\w+}/{last}'; |
31 | - $callable = function ($request, $response, $args) { |
|
31 | + $callable = function ($request, $response, $args) |
|
32 | + { |
|
32 | 33 | echo sprintf('Hello %s %s', $args['first'], $args['last']); |
33 | 34 | }; |
34 | 35 | $route = $this->router->map($methods, $pattern, $callable); |
@@ -46,7 +47,8 @@ discard block |
||
46 | 47 | |
47 | 48 | $methods = ['GET']; |
48 | 49 | $pattern = '/hello/{first:\w+}/{last}'; |
49 | - $callable = function ($request, $response, $args) { |
|
50 | + $callable = function ($request, $response, $args) |
|
51 | + { |
|
50 | 52 | echo sprintf('Hello %s %s', $args['first'], $args['last']); |
51 | 53 | }; |
52 | 54 | $route = $this->router->map($methods, $pattern, $callable); |
@@ -62,7 +64,8 @@ discard block |
||
62 | 64 | { |
63 | 65 | $methods = ['GET']; |
64 | 66 | $pattern = '/hello/{first:\w+}/{last}'; |
65 | - $callable = function ($request, $response, $args) { |
|
67 | + $callable = function ($request, $response, $args) |
|
68 | + { |
|
66 | 69 | echo sprintf('Hello %s %s', $args['first'], $args['last']); |
67 | 70 | }; |
68 | 71 | $this->router->setBasePath('/base/path'); |
@@ -79,7 +82,8 @@ discard block |
||
79 | 82 | { |
80 | 83 | $methods = ['GET']; |
81 | 84 | $pattern = '/archive/{year}[/{month:[\d:{2}]}[/d/{day}]]'; |
82 | - $callable = function ($request, $response, $args) { |
|
85 | + $callable = function ($request, $response, $args) |
|
86 | + { |
|
83 | 87 | return $response; |
84 | 88 | }; |
85 | 89 | $route = $this->router->map($methods, $pattern, $callable); |
@@ -103,7 +107,8 @@ discard block |
||
103 | 107 | { |
104 | 108 | $methods = ['GET']; |
105 | 109 | $pattern = '/hello/{name}'; |
106 | - $callable = function ($request, $response, $args) { |
|
110 | + $callable = function ($request, $response, $args) |
|
111 | + { |
|
107 | 112 | echo sprintf('Hello %s', $args['name']); |
108 | 113 | }; |
109 | 114 | $route = $this->router->map($methods, $pattern, $callable); |
@@ -122,7 +127,8 @@ discard block |
||
122 | 127 | { |
123 | 128 | $methods = ['GET']; |
124 | 129 | $pattern = '/hello/{first}/{last}'; |
125 | - $callable = function ($request, $response, $args) { |
|
130 | + $callable = function ($request, $response, $args) |
|
131 | + { |
|
126 | 132 | echo sprintf('Hello %s %s', $args['first'], $args['last']); |
127 | 133 | }; |
128 | 134 | $route = $this->router->map($methods, $pattern, $callable); |
@@ -138,7 +144,8 @@ discard block |
||
138 | 144 | { |
139 | 145 | $methods = ['GET']; |
140 | 146 | $pattern = '/hello/{first}/{last}'; |
141 | - $callable = function ($request, $response, $args) { |
|
147 | + $callable = function ($request, $response, $args) |
|
148 | + { |
|
142 | 149 | echo sprintf('Hello %s %s', $args['first'], $args['last']); |
143 | 150 | }; |
144 | 151 | $route = $this->router->map($methods, $pattern, $callable); |
@@ -34,29 +34,29 @@ discard block |
||
34 | 34 | * @throws RuntimeException If named route does not exist |
35 | 35 | * @throws InvalidArgumentException If required data not provided |
36 | 36 | */ |
37 | - public function relativePathFor($name, array $data = [], array $queryParams = []) |
|
37 | + public function relativePathFor( $name, array $data = [], array $queryParams = [] ) |
|
38 | 38 | { |
39 | - $route = $this->getNamedRoute($name); |
|
39 | + $route = $this->getNamedRoute( $name ); |
|
40 | 40 | $pattern = $route->getPattern(); |
41 | 41 | |
42 | - $routeDatas = $this->routeParser->parse($pattern); |
|
42 | + $routeDatas = $this->routeParser->parse( $pattern ); |
|
43 | 43 | // $routeDatas is an array of all possible routes that can be made. There is |
44 | 44 | // one routedata for each optional parameter plus one for no optional parameters. |
45 | 45 | // |
46 | 46 | // The most specific is last, so we look for that first. |
47 | - $routeDatas = array_reverse($routeDatas); |
|
47 | + $routeDatas = array_reverse( $routeDatas ); |
|
48 | 48 | |
49 | 49 | $segments = $segmentKeys = []; |
50 | - foreach ($routeDatas as $routeData) { |
|
51 | - foreach ($routeData as $item) { |
|
52 | - if (is_string($item)) { |
|
50 | + foreach( $routeDatas as $routeData ) { |
|
51 | + foreach( $routeData as $item ) { |
|
52 | + if( is_string( $item ) ) { |
|
53 | 53 | // this segment is a static string |
54 | 54 | $segments[] = $item; |
55 | 55 | continue; |
56 | 56 | } |
57 | 57 | |
58 | 58 | // This segment has a parameter: first element is the name |
59 | - if (!array_key_exists($item[0], $data)) { |
|
59 | + if( !array_key_exists( $item[0], $data ) ) { |
|
60 | 60 | // we don't have a data element for this segment: cancel |
61 | 61 | // testing this routeData item, so that we can try a less |
62 | 62 | // specific routeData item. |
@@ -67,21 +67,21 @@ discard block |
||
67 | 67 | $segments[] = $data[$item[0]]; |
68 | 68 | $segmentKeys[$item[0]] = true; |
69 | 69 | } |
70 | - if (!empty($segments)) { |
|
70 | + if( !empty( $segments ) ) { |
|
71 | 71 | // we found all the parameters for this route data, no need to check |
72 | 72 | // less specific ones |
73 | 73 | break; |
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
77 | - if (empty($segments)) { |
|
78 | - throw new InvalidArgumentException('Missing data for URL segment: ' . $segmentName); |
|
77 | + if( empty( $segments ) ) { |
|
78 | + throw new InvalidArgumentException( 'Missing data for URL segment: ' . $segmentName ); |
|
79 | 79 | } |
80 | - $url = implode('', $segments); |
|
80 | + $url = implode( '', $segments ); |
|
81 | 81 | |
82 | - $params = array_merge(array_diff_key($data, $segmentKeys), $queryParams); |
|
83 | - if ($params) { |
|
84 | - $url .= '?' . http_build_query($params); |
|
82 | + $params = array_merge( array_diff_key( $data, $segmentKeys ), $queryParams ); |
|
83 | + if( $params ) { |
|
84 | + $url .= '?' . http_build_query( $params ); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | return $url; |
@@ -4,16 +4,16 @@ |
||
4 | 4 | * Set error reporting to maximum |
5 | 5 | */ |
6 | 6 | error_reporting( -1 ); |
7 | -ini_set('display_errors', '1'); |
|
7 | +ini_set( 'display_errors', '1' ); |
|
8 | 8 | |
9 | 9 | |
10 | 10 | /* |
11 | 11 | * Set locale settings to reasonable defaults |
12 | 12 | */ |
13 | -setlocale(LC_ALL, 'en_US.UTF-8'); |
|
14 | -setlocale(LC_NUMERIC, 'POSIX'); |
|
15 | -setlocale(LC_CTYPE, 'en_US.UTF-8'); |
|
16 | -setlocale(LC_TIME, 'POSIX'); |
|
13 | +setlocale( LC_ALL, 'en_US.UTF-8' ); |
|
14 | +setlocale( LC_NUMERIC, 'POSIX' ); |
|
15 | +setlocale( LC_CTYPE, 'en_US.UTF-8' ); |
|
16 | +setlocale( LC_TIME, 'POSIX' ); |
|
17 | 17 | |
18 | 18 | |
19 | 19 | require_once 'TestHelper.php'; |