Passed
Branch release/v2.0.0 (caca50)
by Anatoly
04:53
created
tests/RouterTest.php 1 patch
Indentation   +341 added lines, -341 removed lines patch added patch discarded remove patch
@@ -28,345 +28,345 @@
 block discarded – undo
28 28
 class RouterTest extends TestCase
29 29
 {
30 30
 
31
-    /**
32
-     * @return void
33
-     */
34
-    public function testConstructor() : void
35
-    {
36
-        $router = new Router();
37
-
38
-        $this->assertInstanceOf(RouteCollection::class, $router);
39
-        $this->assertInstanceOf(MiddlewareInterface::class, $router);
40
-        $this->assertInstanceOf(RequestHandlerInterface::class, $router);
41
-    }
42
-
43
-    /**
44
-     * @return void
45
-     */
46
-    public function testGetRoute() : void
47
-    {
48
-        $routes = [
49
-            new Fixture\TestRoute(),
50
-            new Fixture\TestRoute(),
51
-            new Fixture\TestRoute(),
52
-        ];
53
-
54
-        $router = new Router();
55
-        $router->addRoutes(...$routes);
56
-
57
-        $this->assertSame($routes[0], $router->getRoute($routes[0]->getName()));
58
-        $this->assertSame($routes[1], $router->getRoute($routes[1]->getName()));
59
-        $this->assertSame($routes[2], $router->getRoute($routes[2]->getName()));
60
-    }
61
-
62
-    /**
63
-     * @return void
64
-     */
65
-    public function testGetUndefinedRoute() : void
66
-    {
67
-        $router = new Router();
68
-
69
-        $this->expectException(RouteNotFoundException::class);
70
-        $router->getRoute('foo');
71
-    }
72
-
73
-    /**
74
-     * @return void
75
-     */
76
-    public function testMatch() : void
77
-    {
78
-        $routes = [
79
-            new Fixture\TestRoute(),
80
-            new Fixture\TestRoute(),
81
-            new Fixture\TestRoute(),
82
-            new Fixture\TestRoute(),
83
-            new Fixture\TestRoute(),
84
-        ];
85
-
86
-        $router = new Router();
87
-        $router->addRoutes(...$routes);
88
-
89
-        $request = (new ServerRequestFactory)
90
-            ->createServerRequest(
91
-                $routes[2]->getMethods()[1],
92
-                $routes[2]->getPath()
93
-            );
94
-
95
-        $foundRoute = $router->match($request);
96
-
97
-        $this->assertSame($routes[2]->getName(), $foundRoute->getName());
98
-    }
99
-
100
-    /**
101
-     * @return void
102
-     */
103
-    public function testMatchForUnallowedMethod() : void
104
-    {
105
-        $routes = [
106
-            new Fixture\TestRoute(),
107
-            new Fixture\TestRoute(),
108
-            new Fixture\TestRoute(),
109
-        ];
110
-
111
-        $router = new Router();
112
-        $router->addRoutes(...$routes);
113
-
114
-        $request = (new ServerRequestFactory)
115
-            ->createServerRequest('GET', '/');
116
-
117
-        $this->expectException(MethodNotAllowedException::class);
118
-
119
-        try {
120
-            $router->match($request);
121
-        } catch (MethodNotAllowedException $e) {
122
-            $allowedMethods = array_merge(
123
-                $routes[0]->getMethods(),
124
-                $routes[1]->getMethods(),
125
-                $routes[2]->getMethods()
126
-            );
127
-
128
-            $this->assertSame($allowedMethods, $e->getAllowedMethods());
129
-
130
-            throw $e;
131
-        }
132
-    }
133
-
134
-    /**
135
-     * @return void
136
-     */
137
-    public function testMatchForUndefinedRoute() : void
138
-    {
139
-        $routes = [
140
-            new Fixture\TestRoute(),
141
-            new Fixture\TestRoute(),
142
-            new Fixture\TestRoute(),
143
-        ];
144
-
145
-        $router = new Router();
146
-        $router->addRoutes(...$routes);
147
-
148
-        $request = (new ServerRequestFactory)
149
-            ->createServerRequest($routes[0]->getMethods()[0], '/');
150
-
151
-        $this->expectException(RouteNotFoundException::class);
152
-        $router->match($request);
153
-    }
154
-
155
-    /**
156
-     * @return void
157
-     */
158
-    public function testHandle() : void
159
-    {
160
-        $routes = [
161
-            new Fixture\TestRoute(),
162
-            new Fixture\TestRoute(),
163
-            new Fixture\TestRoute(),
164
-            new Fixture\TestRoute(),
165
-            new Fixture\TestRoute(),
166
-        ];
167
-
168
-        $router = new Router();
169
-        $router->addRoutes(...$routes);
170
-
171
-        $request = (new ServerRequestFactory)
172
-            ->createServerRequest(
173
-                $routes[2]->getMethods()[1],
174
-                $routes[2]->getPath()
175
-            );
176
-
177
-        $router->handle($request);
178
-
179
-        $this->assertTrue($routes[2]->getRequestHandler()->isRunned());
180
-    }
181
-
182
-    /**
183
-     * @return void
184
-     */
185
-    public function testHandleForUnallowedMethod() : void
186
-    {
187
-        $routes = [
188
-            new Fixture\TestRoute(),
189
-            new Fixture\TestRoute(),
190
-            new Fixture\TestRoute(),
191
-        ];
192
-
193
-        $router = new Router();
194
-        $router->addRoutes(...$routes);
195
-
196
-        $request = (new ServerRequestFactory)
197
-            ->createServerRequest('GET', '/');
198
-
199
-        $this->expectException(MethodNotAllowedException::class);
200
-
201
-        try {
202
-            $router->handle($request);
203
-        } catch (MethodNotAllowedException $e) {
204
-            $allowedMethods = array_merge(
205
-                $routes[0]->getMethods(),
206
-                $routes[1]->getMethods(),
207
-                $routes[2]->getMethods()
208
-            );
209
-
210
-            $this->assertSame($allowedMethods, $e->getAllowedMethods());
211
-
212
-            throw $e;
213
-        }
214
-    }
215
-
216
-    /**
217
-     * @return void
218
-     */
219
-    public function testHandleForUndefinedRoute() : void
220
-    {
221
-        $routes = [
222
-            new Fixture\TestRoute(),
223
-            new Fixture\TestRoute(),
224
-            new Fixture\TestRoute(),
225
-        ];
226
-
227
-        $router = new Router();
228
-        $router->addRoutes(...$routes);
229
-
230
-        $request = (new ServerRequestFactory)
231
-            ->createServerRequest($routes[0]->getMethods()[0], '/');
232
-
233
-        $this->expectException(RouteNotFoundException::class);
234
-        $router->handle($request);
235
-    }
236
-
237
-    /**
238
-     * @return void
239
-     */
240
-    public function testProcess() : void
241
-    {
242
-        $routes = [
243
-            new Fixture\TestRoute(),
244
-            new Fixture\TestRoute(),
245
-            new Fixture\TestRoute(),
246
-            new Fixture\TestRoute(),
247
-            new Fixture\TestRoute(),
248
-        ];
249
-
250
-        $router = new Router();
251
-        $router->addRoutes(...$routes);
252
-
253
-        $request = (new ServerRequestFactory)
254
-            ->createServerRequest(
255
-                $routes[2]->getMethods()[1],
256
-                $routes[2]->getPath()
257
-            );
258
-
259
-        $fallback = new Fixture\BlankRequestHandler();
260
-
261
-        $router->process($request, $fallback);
262
-
263
-        $this->assertTrue($routes[2]->getRequestHandler()->isRunned());
264
-        $this->assertFalse($fallback->isRunned());
265
-    }
266
-
267
-    /**
268
-     * @return void
269
-     */
270
-    public function testProcessForUnallowedMethod() : void
271
-    {
272
-        $routes = [
273
-            new Fixture\TestRoute(),
274
-            new Fixture\TestRoute(),
275
-            new Fixture\TestRoute(),
276
-        ];
277
-
278
-        $router = new Router();
279
-        $router->addRoutes(...$routes);
280
-
281
-        $request = (new ServerRequestFactory)
282
-            ->createServerRequest('GET', '/');
283
-
284
-        $fallback = new Fixture\BlankRequestHandler();
285
-
286
-        $router->process($request, $fallback);
287
-
288
-        $this->assertInstanceOf(
289
-            MethodNotAllowedException::class,
290
-            $fallback->getAttribute(Router::ATTR_NAME_FOR_ROUTING_ERROR)
291
-        );
292
-
293
-        $this->assertTrue($fallback->isRunned());
294
-    }
295
-
296
-    /**
297
-     * @return void
298
-     */
299
-    public function testProcessForUndefinedRoute() : void
300
-    {
301
-        $routes = [
302
-            new Fixture\TestRoute(),
303
-            new Fixture\TestRoute(),
304
-            new Fixture\TestRoute(),
305
-        ];
306
-
307
-        $router = new Router();
308
-        $router->addRoutes(...$routes);
309
-
310
-        $request = (new ServerRequestFactory)
311
-            ->createServerRequest($routes[0]->getMethods()[0], '/');
312
-
313
-        $fallback = new Fixture\BlankRequestHandler();
314
-
315
-        $router->process($request, $fallback);
316
-
317
-        $this->assertInstanceOf(
318
-            RouteNotFoundException::class,
319
-            $fallback->getAttribute(Router::ATTR_NAME_FOR_ROUTING_ERROR)
320
-        );
321
-
322
-        $this->assertTrue($fallback->isRunned());
323
-    }
324
-
325
-    /**
326
-     * @return void
327
-     */
328
-    public function testMatchPatterns() : void
329
-    {
330
-        $router = new Router();
331
-        $router->get('test', '/{foo<[0-9]+>}/{bar<[a-zA-Z]+>}(/{baz<.*?>})', new Fixture\BlankRequestHandler());
332
-
333
-        $route = $this->discoverRoute($router, 'GET', '/1990/Surgut/Tyumen');
334
-        $this->assertEquals($route->getAttributes(), [
335
-            'foo' => '1990',
336
-            'bar' => 'Surgut',
337
-            'baz' => 'Tyumen',
338
-        ]);
339
-
340
-        $route = $this->discoverRoute($router, 'GET', '/1990/Surgut/Tyumen/Moscow');
341
-        $this->assertEquals($route->getAttributes(), [
342
-            'foo' => '1990',
343
-            'bar' => 'Surgut',
344
-            'baz' => 'Tyumen/Moscow',
345
-        ]);
346
-
347
-        $route = $this->discoverRoute($router, 'GET', '/Oops/Surgut/Tyumen/Moscow');
348
-        $this->assertNull($route);
349
-
350
-        $route = $this->discoverRoute($router, 'GET', '/1990/2018/Moscow');
351
-        $this->assertNull($route);
352
-    }
353
-
354
-    /**
355
-     * @param Router $router
356
-     * @param string $method
357
-     * @param string $uri
358
-     *
359
-     * @return null|RouteInterface
360
-     */
361
-    private function discoverRoute(Router $router, string $method, string $uri) : ?RouteInterface
362
-    {
363
-        $request = (new ServerRequestFactory)
364
-        ->createServerRequest($method, $uri);
365
-
366
-        try {
367
-            return $router->match($request);
368
-        } catch (ExceptionInterface $e) {
369
-            return null;
370
-        }
371
-    }
31
+	/**
32
+	 * @return void
33
+	 */
34
+	public function testConstructor() : void
35
+	{
36
+		$router = new Router();
37
+
38
+		$this->assertInstanceOf(RouteCollection::class, $router);
39
+		$this->assertInstanceOf(MiddlewareInterface::class, $router);
40
+		$this->assertInstanceOf(RequestHandlerInterface::class, $router);
41
+	}
42
+
43
+	/**
44
+	 * @return void
45
+	 */
46
+	public function testGetRoute() : void
47
+	{
48
+		$routes = [
49
+			new Fixture\TestRoute(),
50
+			new Fixture\TestRoute(),
51
+			new Fixture\TestRoute(),
52
+		];
53
+
54
+		$router = new Router();
55
+		$router->addRoutes(...$routes);
56
+
57
+		$this->assertSame($routes[0], $router->getRoute($routes[0]->getName()));
58
+		$this->assertSame($routes[1], $router->getRoute($routes[1]->getName()));
59
+		$this->assertSame($routes[2], $router->getRoute($routes[2]->getName()));
60
+	}
61
+
62
+	/**
63
+	 * @return void
64
+	 */
65
+	public function testGetUndefinedRoute() : void
66
+	{
67
+		$router = new Router();
68
+
69
+		$this->expectException(RouteNotFoundException::class);
70
+		$router->getRoute('foo');
71
+	}
72
+
73
+	/**
74
+	 * @return void
75
+	 */
76
+	public function testMatch() : void
77
+	{
78
+		$routes = [
79
+			new Fixture\TestRoute(),
80
+			new Fixture\TestRoute(),
81
+			new Fixture\TestRoute(),
82
+			new Fixture\TestRoute(),
83
+			new Fixture\TestRoute(),
84
+		];
85
+
86
+		$router = new Router();
87
+		$router->addRoutes(...$routes);
88
+
89
+		$request = (new ServerRequestFactory)
90
+			->createServerRequest(
91
+				$routes[2]->getMethods()[1],
92
+				$routes[2]->getPath()
93
+			);
94
+
95
+		$foundRoute = $router->match($request);
96
+
97
+		$this->assertSame($routes[2]->getName(), $foundRoute->getName());
98
+	}
99
+
100
+	/**
101
+	 * @return void
102
+	 */
103
+	public function testMatchForUnallowedMethod() : void
104
+	{
105
+		$routes = [
106
+			new Fixture\TestRoute(),
107
+			new Fixture\TestRoute(),
108
+			new Fixture\TestRoute(),
109
+		];
110
+
111
+		$router = new Router();
112
+		$router->addRoutes(...$routes);
113
+
114
+		$request = (new ServerRequestFactory)
115
+			->createServerRequest('GET', '/');
116
+
117
+		$this->expectException(MethodNotAllowedException::class);
118
+
119
+		try {
120
+			$router->match($request);
121
+		} catch (MethodNotAllowedException $e) {
122
+			$allowedMethods = array_merge(
123
+				$routes[0]->getMethods(),
124
+				$routes[1]->getMethods(),
125
+				$routes[2]->getMethods()
126
+			);
127
+
128
+			$this->assertSame($allowedMethods, $e->getAllowedMethods());
129
+
130
+			throw $e;
131
+		}
132
+	}
133
+
134
+	/**
135
+	 * @return void
136
+	 */
137
+	public function testMatchForUndefinedRoute() : void
138
+	{
139
+		$routes = [
140
+			new Fixture\TestRoute(),
141
+			new Fixture\TestRoute(),
142
+			new Fixture\TestRoute(),
143
+		];
144
+
145
+		$router = new Router();
146
+		$router->addRoutes(...$routes);
147
+
148
+		$request = (new ServerRequestFactory)
149
+			->createServerRequest($routes[0]->getMethods()[0], '/');
150
+
151
+		$this->expectException(RouteNotFoundException::class);
152
+		$router->match($request);
153
+	}
154
+
155
+	/**
156
+	 * @return void
157
+	 */
158
+	public function testHandle() : void
159
+	{
160
+		$routes = [
161
+			new Fixture\TestRoute(),
162
+			new Fixture\TestRoute(),
163
+			new Fixture\TestRoute(),
164
+			new Fixture\TestRoute(),
165
+			new Fixture\TestRoute(),
166
+		];
167
+
168
+		$router = new Router();
169
+		$router->addRoutes(...$routes);
170
+
171
+		$request = (new ServerRequestFactory)
172
+			->createServerRequest(
173
+				$routes[2]->getMethods()[1],
174
+				$routes[2]->getPath()
175
+			);
176
+
177
+		$router->handle($request);
178
+
179
+		$this->assertTrue($routes[2]->getRequestHandler()->isRunned());
180
+	}
181
+
182
+	/**
183
+	 * @return void
184
+	 */
185
+	public function testHandleForUnallowedMethod() : void
186
+	{
187
+		$routes = [
188
+			new Fixture\TestRoute(),
189
+			new Fixture\TestRoute(),
190
+			new Fixture\TestRoute(),
191
+		];
192
+
193
+		$router = new Router();
194
+		$router->addRoutes(...$routes);
195
+
196
+		$request = (new ServerRequestFactory)
197
+			->createServerRequest('GET', '/');
198
+
199
+		$this->expectException(MethodNotAllowedException::class);
200
+
201
+		try {
202
+			$router->handle($request);
203
+		} catch (MethodNotAllowedException $e) {
204
+			$allowedMethods = array_merge(
205
+				$routes[0]->getMethods(),
206
+				$routes[1]->getMethods(),
207
+				$routes[2]->getMethods()
208
+			);
209
+
210
+			$this->assertSame($allowedMethods, $e->getAllowedMethods());
211
+
212
+			throw $e;
213
+		}
214
+	}
215
+
216
+	/**
217
+	 * @return void
218
+	 */
219
+	public function testHandleForUndefinedRoute() : void
220
+	{
221
+		$routes = [
222
+			new Fixture\TestRoute(),
223
+			new Fixture\TestRoute(),
224
+			new Fixture\TestRoute(),
225
+		];
226
+
227
+		$router = new Router();
228
+		$router->addRoutes(...$routes);
229
+
230
+		$request = (new ServerRequestFactory)
231
+			->createServerRequest($routes[0]->getMethods()[0], '/');
232
+
233
+		$this->expectException(RouteNotFoundException::class);
234
+		$router->handle($request);
235
+	}
236
+
237
+	/**
238
+	 * @return void
239
+	 */
240
+	public function testProcess() : void
241
+	{
242
+		$routes = [
243
+			new Fixture\TestRoute(),
244
+			new Fixture\TestRoute(),
245
+			new Fixture\TestRoute(),
246
+			new Fixture\TestRoute(),
247
+			new Fixture\TestRoute(),
248
+		];
249
+
250
+		$router = new Router();
251
+		$router->addRoutes(...$routes);
252
+
253
+		$request = (new ServerRequestFactory)
254
+			->createServerRequest(
255
+				$routes[2]->getMethods()[1],
256
+				$routes[2]->getPath()
257
+			);
258
+
259
+		$fallback = new Fixture\BlankRequestHandler();
260
+
261
+		$router->process($request, $fallback);
262
+
263
+		$this->assertTrue($routes[2]->getRequestHandler()->isRunned());
264
+		$this->assertFalse($fallback->isRunned());
265
+	}
266
+
267
+	/**
268
+	 * @return void
269
+	 */
270
+	public function testProcessForUnallowedMethod() : void
271
+	{
272
+		$routes = [
273
+			new Fixture\TestRoute(),
274
+			new Fixture\TestRoute(),
275
+			new Fixture\TestRoute(),
276
+		];
277
+
278
+		$router = new Router();
279
+		$router->addRoutes(...$routes);
280
+
281
+		$request = (new ServerRequestFactory)
282
+			->createServerRequest('GET', '/');
283
+
284
+		$fallback = new Fixture\BlankRequestHandler();
285
+
286
+		$router->process($request, $fallback);
287
+
288
+		$this->assertInstanceOf(
289
+			MethodNotAllowedException::class,
290
+			$fallback->getAttribute(Router::ATTR_NAME_FOR_ROUTING_ERROR)
291
+		);
292
+
293
+		$this->assertTrue($fallback->isRunned());
294
+	}
295
+
296
+	/**
297
+	 * @return void
298
+	 */
299
+	public function testProcessForUndefinedRoute() : void
300
+	{
301
+		$routes = [
302
+			new Fixture\TestRoute(),
303
+			new Fixture\TestRoute(),
304
+			new Fixture\TestRoute(),
305
+		];
306
+
307
+		$router = new Router();
308
+		$router->addRoutes(...$routes);
309
+
310
+		$request = (new ServerRequestFactory)
311
+			->createServerRequest($routes[0]->getMethods()[0], '/');
312
+
313
+		$fallback = new Fixture\BlankRequestHandler();
314
+
315
+		$router->process($request, $fallback);
316
+
317
+		$this->assertInstanceOf(
318
+			RouteNotFoundException::class,
319
+			$fallback->getAttribute(Router::ATTR_NAME_FOR_ROUTING_ERROR)
320
+		);
321
+
322
+		$this->assertTrue($fallback->isRunned());
323
+	}
324
+
325
+	/**
326
+	 * @return void
327
+	 */
328
+	public function testMatchPatterns() : void
329
+	{
330
+		$router = new Router();
331
+		$router->get('test', '/{foo<[0-9]+>}/{bar<[a-zA-Z]+>}(/{baz<.*?>})', new Fixture\BlankRequestHandler());
332
+
333
+		$route = $this->discoverRoute($router, 'GET', '/1990/Surgut/Tyumen');
334
+		$this->assertEquals($route->getAttributes(), [
335
+			'foo' => '1990',
336
+			'bar' => 'Surgut',
337
+			'baz' => 'Tyumen',
338
+		]);
339
+
340
+		$route = $this->discoverRoute($router, 'GET', '/1990/Surgut/Tyumen/Moscow');
341
+		$this->assertEquals($route->getAttributes(), [
342
+			'foo' => '1990',
343
+			'bar' => 'Surgut',
344
+			'baz' => 'Tyumen/Moscow',
345
+		]);
346
+
347
+		$route = $this->discoverRoute($router, 'GET', '/Oops/Surgut/Tyumen/Moscow');
348
+		$this->assertNull($route);
349
+
350
+		$route = $this->discoverRoute($router, 'GET', '/1990/2018/Moscow');
351
+		$this->assertNull($route);
352
+	}
353
+
354
+	/**
355
+	 * @param Router $router
356
+	 * @param string $method
357
+	 * @param string $uri
358
+	 *
359
+	 * @return null|RouteInterface
360
+	 */
361
+	private function discoverRoute(Router $router, string $method, string $uri) : ?RouteInterface
362
+	{
363
+		$request = (new ServerRequestFactory)
364
+		->createServerRequest($method, $uri);
365
+
366
+		try {
367
+			return $router->match($request);
368
+		} catch (ExceptionInterface $e) {
369
+			return null;
370
+		}
371
+	}
372 372
 }
Please login to merge, or discard this patch.
src/RouteInterface.php 1 patch
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -23,127 +23,127 @@
 block discarded – undo
23 23
 interface RouteInterface
24 24
 {
25 25
 
26
-    /**
27
-     * Gets the route name
28
-     *
29
-     * @return string
30
-     */
31
-    public function getName() : string;
32
-
33
-    /**
34
-     * Gets the route path
35
-     *
36
-     * @return string
37
-     */
38
-    public function getPath() : string;
39
-
40
-    /**
41
-     * Gets the route methods
42
-     *
43
-     * @return string[]
44
-     */
45
-    public function getMethods() : array;
46
-
47
-    /**
48
-     * Gets the route request handler
49
-     *
50
-     * @return RequestHandlerInterface
51
-     */
52
-    public function getRequestHandler() : RequestHandlerInterface;
53
-
54
-    /**
55
-     * Gets the route middlewares
56
-     *
57
-     * @return MiddlewareInterface[]
58
-     */
59
-    public function getMiddlewares() : array;
60
-
61
-    /**
62
-     * Gets the route attributes
63
-     *
64
-     * @return array
65
-     */
66
-    public function getAttributes() : array;
67
-
68
-    /**
69
-     * Sets the given name to the route
70
-     *
71
-     * @param string $name
72
-     *
73
-     * @return RouteInterface
74
-     */
75
-    public function setName(string $name) : RouteInterface;
76
-
77
-    /**
78
-     * Sets the given path to the route
79
-     *
80
-     * @param string $path
81
-     *
82
-     * @return RouteInterface
83
-     */
84
-    public function setPath(string $path) : RouteInterface;
85
-
86
-    /**
87
-     * Sets the given method(s) to the route
88
-     *
89
-     * @param string ...$methods
90
-     *
91
-     * @return RouteInterface
92
-     */
93
-    public function setMethods(string ...$methods) : RouteInterface;
94
-
95
-    /**
96
-     * Sets the given request handler to the route
97
-     *
98
-     * @param RequestHandlerInterface $requestHandler
99
-     *
100
-     * @return RouteInterface
101
-     */
102
-    public function setRequestHandler(RequestHandlerInterface $requestHandler) : RouteInterface;
103
-
104
-    /**
105
-     * Sets the given middleware(s) to the route
106
-     *
107
-     * @param MiddlewareInterface ...$middlewares
108
-     *
109
-     * @return RouteInterface
110
-     */
111
-    public function setMiddlewares(MiddlewareInterface ...$middlewares) : RouteInterface;
112
-
113
-    /**
114
-     * Sets the given attributes to the route
115
-     *
116
-     * @param array $attributes
117
-     *
118
-     * @return RouteInterface
119
-     */
120
-    public function setAttributes(array $attributes) : RouteInterface;
121
-
122
-    /**
123
-     * Returns the route clone with the given attributes
124
-     *
125
-     * This method MUST NOT change the state of the object.
126
-     *
127
-     * @param array $attributes
128
-     *
129
-     * @return RouteInterface
130
-     */
131
-    public function withAddedAttributes(array $attributes) : RouteInterface;
132
-
133
-    /**
134
-     * Builds the route path
135
-     *
136
-     * @param array $attributes
137
-     * @param bool $strict
138
-     *
139
-     * @return string
140
-     */
141
-    public function buildPath(array $attributes, bool $strict) : string;
142
-
143
-    /**
144
-     * Builds the route regex
145
-     *
146
-     * @return string
147
-     */
148
-    public function buildRegex() : string;
26
+	/**
27
+	 * Gets the route name
28
+	 *
29
+	 * @return string
30
+	 */
31
+	public function getName() : string;
32
+
33
+	/**
34
+	 * Gets the route path
35
+	 *
36
+	 * @return string
37
+	 */
38
+	public function getPath() : string;
39
+
40
+	/**
41
+	 * Gets the route methods
42
+	 *
43
+	 * @return string[]
44
+	 */
45
+	public function getMethods() : array;
46
+
47
+	/**
48
+	 * Gets the route request handler
49
+	 *
50
+	 * @return RequestHandlerInterface
51
+	 */
52
+	public function getRequestHandler() : RequestHandlerInterface;
53
+
54
+	/**
55
+	 * Gets the route middlewares
56
+	 *
57
+	 * @return MiddlewareInterface[]
58
+	 */
59
+	public function getMiddlewares() : array;
60
+
61
+	/**
62
+	 * Gets the route attributes
63
+	 *
64
+	 * @return array
65
+	 */
66
+	public function getAttributes() : array;
67
+
68
+	/**
69
+	 * Sets the given name to the route
70
+	 *
71
+	 * @param string $name
72
+	 *
73
+	 * @return RouteInterface
74
+	 */
75
+	public function setName(string $name) : RouteInterface;
76
+
77
+	/**
78
+	 * Sets the given path to the route
79
+	 *
80
+	 * @param string $path
81
+	 *
82
+	 * @return RouteInterface
83
+	 */
84
+	public function setPath(string $path) : RouteInterface;
85
+
86
+	/**
87
+	 * Sets the given method(s) to the route
88
+	 *
89
+	 * @param string ...$methods
90
+	 *
91
+	 * @return RouteInterface
92
+	 */
93
+	public function setMethods(string ...$methods) : RouteInterface;
94
+
95
+	/**
96
+	 * Sets the given request handler to the route
97
+	 *
98
+	 * @param RequestHandlerInterface $requestHandler
99
+	 *
100
+	 * @return RouteInterface
101
+	 */
102
+	public function setRequestHandler(RequestHandlerInterface $requestHandler) : RouteInterface;
103
+
104
+	/**
105
+	 * Sets the given middleware(s) to the route
106
+	 *
107
+	 * @param MiddlewareInterface ...$middlewares
108
+	 *
109
+	 * @return RouteInterface
110
+	 */
111
+	public function setMiddlewares(MiddlewareInterface ...$middlewares) : RouteInterface;
112
+
113
+	/**
114
+	 * Sets the given attributes to the route
115
+	 *
116
+	 * @param array $attributes
117
+	 *
118
+	 * @return RouteInterface
119
+	 */
120
+	public function setAttributes(array $attributes) : RouteInterface;
121
+
122
+	/**
123
+	 * Returns the route clone with the given attributes
124
+	 *
125
+	 * This method MUST NOT change the state of the object.
126
+	 *
127
+	 * @param array $attributes
128
+	 *
129
+	 * @return RouteInterface
130
+	 */
131
+	public function withAddedAttributes(array $attributes) : RouteInterface;
132
+
133
+	/**
134
+	 * Builds the route path
135
+	 *
136
+	 * @param array $attributes
137
+	 * @param bool $strict
138
+	 *
139
+	 * @return string
140
+	 */
141
+	public function buildPath(array $attributes, bool $strict) : string;
142
+
143
+	/**
144
+	 * Builds the route regex
145
+	 *
146
+	 * @return string
147
+	 */
148
+	public function buildRegex() : string;
149 149
 }
Please login to merge, or discard this patch.
src/Annotation/AnnotationRouteLoader.php 1 patch
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -35,133 +35,133 @@
 block discarded – undo
35 35
 class AnnotationRouteLoader
36 36
 {
37 37
 
38
-    /**
39
-     * @var SimpleAnnotationReader
40
-     */
41
-    private $annotationReader;
42
-
43
-    /**
44
-     * @var SplPriorityQueue
45
-     */
46
-    private $discoveredAnnotations;
47
-
48
-    /**
49
-     * Constructor of the class
50
-     */
51
-    public function __construct()
52
-    {
53
-        $this->annotationReader = new SimpleAnnotationReader();
54
-        $this->annotationReader->addNamespace(__NAMESPACE__);
55
-
56
-        $this->discoveredAnnotations = new SplPriorityQueue();
57
-    }
58
-
59
-    /**
60
-     * Builds discovered routes
61
-     *
62
-     * @param null|callable $objectCreator
63
-     *
64
-     * @return array
65
-     */
66
-    public function buildRoutes(callable $objectCreator = null) : array
67
-    {
68
-        $routes = [];
69
-        foreach ($this->discoveredAnnotations as $annotation) {
70
-            $requestHandlerClass = $annotation->source->getName();
71
-            $requestHandler = $objectCreator ? $objectCreator($requestHandlerClass) : new $requestHandlerClass;
72
-
73
-            $middlewares = [];
74
-            foreach ($annotation->middlewares as $middlewareClass) {
75
-                $middlewares[] = $objectCreator ? $objectCreator($middlewareClass) : new $middlewareClass;
76
-            }
77
-
78
-            $routes[] = new BaseRoute(
79
-                $annotation->name,
80
-                $annotation->path,
81
-                $annotation->methods,
82
-                $requestHandler,
83
-                $middlewares,
84
-                $annotation->attributes
85
-            );
86
-        }
87
-
88
-        return $routes;
89
-    }
90
-
91
-    /**
92
-     * Discovers routes in the given destination
93
-     *
94
-     * @param string $destination
95
-     *
96
-     * @return void
97
-     */
98
-    public function discover(string $destination) : void
99
-    {
100
-        $annotations = $this->findAnnotations($destination, Route::class);
101
-
102
-        foreach ($annotations as $annotation) {
103
-            $this->discoveredAnnotations->insert($annotation, $annotation->priority);
104
-        }
105
-    }
106
-
107
-    /**
108
-     * Finds annotations in the given destination
109
-     *
110
-     * @param string $destination
111
-     * @param string $name
112
-     *
113
-     * @return array
114
-     */
115
-    private function findAnnotations(string $destination, string $name) : array
116
-    {
117
-        $classes = $this->findClasses($destination);
118
-        $annotations = [];
119
-
120
-        foreach ($classes as $class) {
121
-            $class = new ReflectionClass($class);
122
-            $annotation = $this->annotationReader->getClassAnnotation($class, $name);
123
-
124
-            if ($annotation instanceof $name) {
125
-                $annotation->source = $class;
126
-                $annotations[] = $annotation;
127
-            }
128
-        }
129
-
130
-        return $annotations;
131
-    }
132
-
133
-    /**
134
-     * Finds classes in the given destination
135
-     *
136
-     * @param string $destination
137
-     *
138
-     * @return array
139
-     */
140
-    private function findClasses(string $destination) : array
141
-    {
142
-        $files = $this->findFiles($destination);
143
-        $classes = get_declared_classes();
144
-
145
-        foreach ($files as $file) {
146
-            require_once $file->getRealPath();
147
-        }
148
-
149
-        return array_diff(get_declared_classes(), $classes);
150
-    }
151
-
152
-    /**
153
-     * Finds files in the given destination
154
-     *
155
-     * @param string $destination
156
-     *
157
-     * @return array
158
-     */
159
-    private function findFiles(string $destination) : array
160
-    {
161
-        $directory = new RecursiveDirectoryIterator($destination);
162
-        $iterator = new RecursiveIteratorIterator($directory);
163
-        $files = new RegexIterator($iterator, '/\.php$/');
164
-
165
-        return iterator_to_array($files);
166
-    }
38
+	/**
39
+	 * @var SimpleAnnotationReader
40
+	 */
41
+	private $annotationReader;
42
+
43
+	/**
44
+	 * @var SplPriorityQueue
45
+	 */
46
+	private $discoveredAnnotations;
47
+
48
+	/**
49
+	 * Constructor of the class
50
+	 */
51
+	public function __construct()
52
+	{
53
+		$this->annotationReader = new SimpleAnnotationReader();
54
+		$this->annotationReader->addNamespace(__NAMESPACE__);
55
+
56
+		$this->discoveredAnnotations = new SplPriorityQueue();
57
+	}
58
+
59
+	/**
60
+	 * Builds discovered routes
61
+	 *
62
+	 * @param null|callable $objectCreator
63
+	 *
64
+	 * @return array
65
+	 */
66
+	public function buildRoutes(callable $objectCreator = null) : array
67
+	{
68
+		$routes = [];
69
+		foreach ($this->discoveredAnnotations as $annotation) {
70
+			$requestHandlerClass = $annotation->source->getName();
71
+			$requestHandler = $objectCreator ? $objectCreator($requestHandlerClass) : new $requestHandlerClass;
72
+
73
+			$middlewares = [];
74
+			foreach ($annotation->middlewares as $middlewareClass) {
75
+				$middlewares[] = $objectCreator ? $objectCreator($middlewareClass) : new $middlewareClass;
76
+			}
77
+
78
+			$routes[] = new BaseRoute(
79
+				$annotation->name,
80
+				$annotation->path,
81
+				$annotation->methods,
82
+				$requestHandler,
83
+				$middlewares,
84
+				$annotation->attributes
85
+			);
86
+		}
87
+
88
+		return $routes;
89
+	}
90
+
91
+	/**
92
+	 * Discovers routes in the given destination
93
+	 *
94
+	 * @param string $destination
95
+	 *
96
+	 * @return void
97
+	 */
98
+	public function discover(string $destination) : void
99
+	{
100
+		$annotations = $this->findAnnotations($destination, Route::class);
101
+
102
+		foreach ($annotations as $annotation) {
103
+			$this->discoveredAnnotations->insert($annotation, $annotation->priority);
104
+		}
105
+	}
106
+
107
+	/**
108
+	 * Finds annotations in the given destination
109
+	 *
110
+	 * @param string $destination
111
+	 * @param string $name
112
+	 *
113
+	 * @return array
114
+	 */
115
+	private function findAnnotations(string $destination, string $name) : array
116
+	{
117
+		$classes = $this->findClasses($destination);
118
+		$annotations = [];
119
+
120
+		foreach ($classes as $class) {
121
+			$class = new ReflectionClass($class);
122
+			$annotation = $this->annotationReader->getClassAnnotation($class, $name);
123
+
124
+			if ($annotation instanceof $name) {
125
+				$annotation->source = $class;
126
+				$annotations[] = $annotation;
127
+			}
128
+		}
129
+
130
+		return $annotations;
131
+	}
132
+
133
+	/**
134
+	 * Finds classes in the given destination
135
+	 *
136
+	 * @param string $destination
137
+	 *
138
+	 * @return array
139
+	 */
140
+	private function findClasses(string $destination) : array
141
+	{
142
+		$files = $this->findFiles($destination);
143
+		$classes = get_declared_classes();
144
+
145
+		foreach ($files as $file) {
146
+			require_once $file->getRealPath();
147
+		}
148
+
149
+		return array_diff(get_declared_classes(), $classes);
150
+	}
151
+
152
+	/**
153
+	 * Finds files in the given destination
154
+	 *
155
+	 * @param string $destination
156
+	 *
157
+	 * @return array
158
+	 */
159
+	private function findFiles(string $destination) : array
160
+	{
161
+		$directory = new RecursiveDirectoryIterator($destination);
162
+		$iterator = new RecursiveIteratorIterator($directory);
163
+		$files = new RegexIterator($iterator, '/\.php$/');
164
+
165
+		return iterator_to_array($files);
166
+	}
167 167
 }
Please login to merge, or discard this patch.
src/Annotation/Route.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -33,93 +33,93 @@
 block discarded – undo
33 33
 final class Route
34 34
 {
35 35
 
36
-    /**
37
-     * @var object
38
-     */
39
-    public $source;
40
-
41
-    /**
42
-     * @var string
43
-     */
44
-    public $name;
45
-
46
-    /**
47
-     * @var string
48
-     */
49
-    public $path;
50
-
51
-    /**
52
-     * @var array
53
-     */
54
-    public $methods;
55
-
56
-    /**
57
-     * @var array
58
-     */
59
-    public $middlewares = [];
60
-
61
-    /**
62
-     * @var array
63
-     */
64
-    public $attributes = [];
65
-
66
-    /**
67
-     * @var int
68
-     */
69
-    public $priority = 0;
70
-
71
-    /**
72
-     * @param array $params
73
-     *
74
-     * @throws InvalidArgumentException
75
-     */
76
-    public function __construct(array $params)
77
-    {
78
-        if (empty($params['name']) || !is_string($params['name'])) {
79
-            throw new InvalidArgumentException('@Route.name must be not an empty string.');
80
-        }
81
-        if (empty($params['path']) || !is_string($params['path'])) {
82
-            throw new InvalidArgumentException('@Route.path must be not an empty string.');
83
-        }
84
-        if (empty($params['methods']) || !is_array($params['methods'])) {
85
-            throw new InvalidArgumentException('@Route.methods must be not an empty array.');
86
-        }
87
-        if (isset($params['middlewares']) && !is_array($params['middlewares'])) {
88
-            throw new InvalidArgumentException('@Route.middlewares must be an array.');
89
-        }
90
-        if (isset($params['attributes']) && !is_array($params['attributes'])) {
91
-            throw new InvalidArgumentException('@Route.attributes must be an array.');
92
-        }
93
-        if (isset($params['priority']) && !is_int($params['priority'])) {
94
-            throw new InvalidArgumentException('@Route.priority must be an integer.');
95
-        }
96
-
97
-        foreach ($params['methods'] as $v) {
98
-            if (!is_string($v)) {
99
-                throw new InvalidArgumentException('@Route.methods must contain only strings.');
100
-            }
101
-        }
102
-
103
-        if (isset($params['middlewares'])) {
104
-            foreach ($params['middlewares'] as $v) {
105
-                if (!is_string($v) || !class_exists($v) || !is_subclass_of($v, MiddlewareInterface::class)) {
106
-                    throw new InvalidArgumentException('@Route.middlewares must contain only middlewares.');
107
-                }
108
-            }
109
-        }
110
-
111
-        $this->name = $params['name'];
112
-        $this->path = $params['path'];
113
-        $this->methods = $params['methods'];
114
-
115
-        if (isset($params['middlewares'])) {
116
-            $this->middlewares = $params['middlewares'];
117
-        }
118
-        if (isset($params['attributes'])) {
119
-            $this->attributes = $params['attributes'];
120
-        }
121
-        if (isset($params['priority'])) {
122
-            $this->priority = $params['priority'];
123
-        }
124
-    }
36
+	/**
37
+	 * @var object
38
+	 */
39
+	public $source;
40
+
41
+	/**
42
+	 * @var string
43
+	 */
44
+	public $name;
45
+
46
+	/**
47
+	 * @var string
48
+	 */
49
+	public $path;
50
+
51
+	/**
52
+	 * @var array
53
+	 */
54
+	public $methods;
55
+
56
+	/**
57
+	 * @var array
58
+	 */
59
+	public $middlewares = [];
60
+
61
+	/**
62
+	 * @var array
63
+	 */
64
+	public $attributes = [];
65
+
66
+	/**
67
+	 * @var int
68
+	 */
69
+	public $priority = 0;
70
+
71
+	/**
72
+	 * @param array $params
73
+	 *
74
+	 * @throws InvalidArgumentException
75
+	 */
76
+	public function __construct(array $params)
77
+	{
78
+		if (empty($params['name']) || !is_string($params['name'])) {
79
+			throw new InvalidArgumentException('@Route.name must be not an empty string.');
80
+		}
81
+		if (empty($params['path']) || !is_string($params['path'])) {
82
+			throw new InvalidArgumentException('@Route.path must be not an empty string.');
83
+		}
84
+		if (empty($params['methods']) || !is_array($params['methods'])) {
85
+			throw new InvalidArgumentException('@Route.methods must be not an empty array.');
86
+		}
87
+		if (isset($params['middlewares']) && !is_array($params['middlewares'])) {
88
+			throw new InvalidArgumentException('@Route.middlewares must be an array.');
89
+		}
90
+		if (isset($params['attributes']) && !is_array($params['attributes'])) {
91
+			throw new InvalidArgumentException('@Route.attributes must be an array.');
92
+		}
93
+		if (isset($params['priority']) && !is_int($params['priority'])) {
94
+			throw new InvalidArgumentException('@Route.priority must be an integer.');
95
+		}
96
+
97
+		foreach ($params['methods'] as $v) {
98
+			if (!is_string($v)) {
99
+				throw new InvalidArgumentException('@Route.methods must contain only strings.');
100
+			}
101
+		}
102
+
103
+		if (isset($params['middlewares'])) {
104
+			foreach ($params['middlewares'] as $v) {
105
+				if (!is_string($v) || !class_exists($v) || !is_subclass_of($v, MiddlewareInterface::class)) {
106
+					throw new InvalidArgumentException('@Route.middlewares must contain only middlewares.');
107
+				}
108
+			}
109
+		}
110
+
111
+		$this->name = $params['name'];
112
+		$this->path = $params['path'];
113
+		$this->methods = $params['methods'];
114
+
115
+		if (isset($params['middlewares'])) {
116
+			$this->middlewares = $params['middlewares'];
117
+		}
118
+		if (isset($params['attributes'])) {
119
+			$this->attributes = $params['attributes'];
120
+		}
121
+		if (isset($params['priority'])) {
122
+			$this->priority = $params['priority'];
123
+		}
124
+	}
125 125
 }
Please login to merge, or discard this patch.
src/RequestHandler/RoutableRequestHandler.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -25,45 +25,45 @@
 block discarded – undo
25 25
 class RoutableRequestHandler implements RequestHandlerInterface
26 26
 {
27 27
 
28
-    /**
29
-     * Server Request attribute name for a route name
30
-     *
31
-     * @var string
32
-     */
33
-    public const ATTR_NAME_FOR_ROUTE_NAME = '@route-name';
28
+	/**
29
+	 * Server Request attribute name for a route name
30
+	 *
31
+	 * @var string
32
+	 */
33
+	public const ATTR_NAME_FOR_ROUTE_NAME = '@route-name';
34 34
 
35
-    /**
36
-     * The request handler route
37
-     *
38
-     * @var RouteInterface
39
-     */
40
-    private $route;
35
+	/**
36
+	 * The request handler route
37
+	 *
38
+	 * @var RouteInterface
39
+	 */
40
+	private $route;
41 41
 
42
-    /**
43
-     * Constructor of the class
44
-     *
45
-     * @param RouteInterface $route
46
-     */
47
-    public function __construct(RouteInterface $route)
48
-    {
49
-        $this->route = $route;
50
-    }
42
+	/**
43
+	 * Constructor of the class
44
+	 *
45
+	 * @param RouteInterface $route
46
+	 */
47
+	public function __construct(RouteInterface $route)
48
+	{
49
+		$this->route = $route;
50
+	}
51 51
 
52
-    /**
53
-     * {@inheritDoc}
54
-     */
55
-    public function handle(ServerRequestInterface $request) : ResponseInterface
56
-    {
57
-        $request = $request->withAttribute(self::ATTR_NAME_FOR_ROUTE_NAME, $this->route->getName());
52
+	/**
53
+	 * {@inheritDoc}
54
+	 */
55
+	public function handle(ServerRequestInterface $request) : ResponseInterface
56
+	{
57
+		$request = $request->withAttribute(self::ATTR_NAME_FOR_ROUTE_NAME, $this->route->getName());
58 58
 
59
-        foreach ($this->route->getAttributes() as $key => $value) {
60
-            $request = $request->withAttribute($key, $value);
61
-        }
59
+		foreach ($this->route->getAttributes() as $key => $value) {
60
+			$request = $request->withAttribute($key, $value);
61
+		}
62 62
 
63
-        $handler = new QueueableRequestHandler($this->route->getRequestHandler());
63
+		$handler = new QueueableRequestHandler($this->route->getRequestHandler());
64 64
 
65
-        $handler->add(...$this->route->getMiddlewares());
65
+		$handler->add(...$this->route->getMiddlewares());
66 66
 
67
-        return $handler->handle($request);
68
-    }
67
+		return $handler->handle($request);
68
+	}
69 69
 }
Please login to merge, or discard this patch.
src/RequestHandler/CallableRequestHandler.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -24,28 +24,28 @@
 block discarded – undo
24 24
 class CallableRequestHandler implements RequestHandlerInterface
25 25
 {
26 26
 
27
-    /**
28
-     * The request handler callback
29
-     *
30
-     * @var callable
31
-     */
32
-    private $callback;
27
+	/**
28
+	 * The request handler callback
29
+	 *
30
+	 * @var callable
31
+	 */
32
+	private $callback;
33 33
 
34
-    /**
35
-     * Constructor of the class
36
-     *
37
-     * @param callable $callback
38
-     */
39
-    public function __construct(callable $callback)
40
-    {
41
-        $this->callback = $callback;
42
-    }
34
+	/**
35
+	 * Constructor of the class
36
+	 *
37
+	 * @param callable $callback
38
+	 */
39
+	public function __construct(callable $callback)
40
+	{
41
+		$this->callback = $callback;
42
+	}
43 43
 
44
-    /**
45
-     * {@inheritDoc}
46
-     */
47
-    public function handle(ServerRequestInterface $request) : ResponseInterface
48
-    {
49
-        return ($this->callback)($request);
50
-    }
44
+	/**
45
+	 * {@inheritDoc}
46
+	 */
47
+	public function handle(ServerRequestInterface $request) : ResponseInterface
48
+	{
49
+		return ($this->callback)($request);
50
+	}
51 51
 }
Please login to merge, or discard this patch.
src/Route.php 1 patch
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -28,215 +28,215 @@
 block discarded – undo
28 28
 class Route implements RouteInterface
29 29
 {
30 30
 
31
-    /**
32
-     * The route name
33
-     *
34
-     * @var string
35
-     */
36
-    private $name;
37
-
38
-    /**
39
-     * The route path
40
-     *
41
-     * @var string
42
-     */
43
-    private $path;
44
-
45
-    /**
46
-     * The route methods
47
-     *
48
-     * @var string[]
49
-     */
50
-    private $methods;
51
-
52
-    /**
53
-     * The route request handler
54
-     *
55
-     * @var RequestHandlerInterface
56
-     */
57
-    private $requestHandler;
58
-
59
-    /**
60
-     * The route middlewares
61
-     *
62
-     * @var MiddlewareInterface[]
63
-     */
64
-    private $middlewares = [];
65
-
66
-    /**
67
-     * The route attributes
68
-     *
69
-     * @var array
70
-     */
71
-    private $attributes = [];
72
-
73
-    /**
74
-     * Constructor of the class
75
-     *
76
-     * @param string $name
77
-     * @param string $path
78
-     * @param string[] $methods
79
-     * @param RequestHandlerInterface $requestHandler
80
-     * @param MiddlewareInterface[] $middlewares
81
-     * @param array $attributes
82
-     */
83
-    public function __construct(
84
-        string $name,
85
-        string $path,
86
-        array $methods,
87
-        RequestHandlerInterface $requestHandler,
88
-        array $middlewares = [],
89
-        array $attributes = []
90
-    ) {
91
-        $this->setName($name);
92
-        $this->setPath($path);
93
-        $this->setMethods(...$methods);
94
-        $this->setRequestHandler($requestHandler);
95
-        $this->setMiddlewares(...$middlewares);
96
-        $this->setAttributes($attributes);
97
-    }
98
-
99
-    /**
100
-     * {@inheritDoc}
101
-     */
102
-    public function getName() : string
103
-    {
104
-        return $this->name;
105
-    }
106
-
107
-    /**
108
-     * {@inheritDoc}
109
-     */
110
-    public function getPath() : string
111
-    {
112
-        return $this->path;
113
-    }
114
-
115
-    /**
116
-     * {@inheritDoc}
117
-     */
118
-    public function getMethods() : array
119
-    {
120
-        return $this->methods;
121
-    }
122
-
123
-    /**
124
-     * {@inheritDoc}
125
-     */
126
-    public function getRequestHandler() : RequestHandlerInterface
127
-    {
128
-        return $this->requestHandler;
129
-    }
130
-
131
-    /**
132
-     * {@inheritDoc}
133
-     */
134
-    public function getMiddlewares() : array
135
-    {
136
-        return $this->middlewares;
137
-    }
138
-
139
-    /**
140
-     * {@inheritDoc}
141
-     */
142
-    public function getAttributes() : array
143
-    {
144
-        return $this->attributes;
145
-    }
146
-
147
-    /**
148
-     * {@inheritDoc}
149
-     */
150
-    public function setName(string $name) : RouteInterface
151
-    {
152
-        $this->name = $name;
153
-
154
-        return $this;
155
-    }
156
-
157
-    /**
158
-     * {@inheritDoc}
159
-     */
160
-    public function setPath(string $path) : RouteInterface
161
-    {
162
-        $this->path = $path;
163
-
164
-        return $this;
165
-    }
166
-
167
-    /**
168
-     * {@inheritDoc}
169
-     */
170
-    public function setMethods(string ...$methods) : RouteInterface
171
-    {
172
-        foreach ($methods as &$method) {
173
-            $method = strtoupper($method);
174
-        }
175
-
176
-        $this->methods = $methods;
177
-
178
-        return $this;
179
-    }
180
-
181
-    /**
182
-     * {@inheritDoc}
183
-     */
184
-    public function setRequestHandler(RequestHandlerInterface $requestHandler) : RouteInterface
185
-    {
186
-        $this->requestHandler = $requestHandler;
187
-
188
-        return $this;
189
-    }
190
-
191
-    /**
192
-     * {@inheritDoc}
193
-     */
194
-    public function setMiddlewares(MiddlewareInterface ...$middlewares) : RouteInterface
195
-    {
196
-        $this->middlewares = $middlewares;
197
-
198
-        return $this;
199
-    }
200
-
201
-    /**
202
-     * {@inheritDoc}
203
-     */
204
-    public function setAttributes(array $attributes) : RouteInterface
205
-    {
206
-        $this->attributes = $attributes;
207
-
208
-        return $this;
209
-    }
210
-
211
-    /**
212
-     * {@inheritDoc}
213
-     */
214
-    public function withAddedAttributes(array $attributes) : RouteInterface
215
-    {
216
-        $clone = clone $this;
217
-
218
-        foreach ($attributes as $key => $value) {
219
-            $clone->attributes[$key] = $value;
220
-        }
221
-
222
-        return $clone;
223
-    }
224
-
225
-    /**
226
-     * {@inheritDoc}
227
-     */
228
-    public function buildPath(array $attributes = [], bool $strict = false) : string
229
-    {
230
-        $attributes += $this->attributes;
231
-
232
-        return path_build($this->path, $attributes, $strict);
233
-    }
234
-
235
-    /**
236
-     * {@inheritDoc}
237
-     */
238
-    public function buildRegex() : string
239
-    {
240
-        return path_regex($this->path);
241
-    }
31
+	/**
32
+	 * The route name
33
+	 *
34
+	 * @var string
35
+	 */
36
+	private $name;
37
+
38
+	/**
39
+	 * The route path
40
+	 *
41
+	 * @var string
42
+	 */
43
+	private $path;
44
+
45
+	/**
46
+	 * The route methods
47
+	 *
48
+	 * @var string[]
49
+	 */
50
+	private $methods;
51
+
52
+	/**
53
+	 * The route request handler
54
+	 *
55
+	 * @var RequestHandlerInterface
56
+	 */
57
+	private $requestHandler;
58
+
59
+	/**
60
+	 * The route middlewares
61
+	 *
62
+	 * @var MiddlewareInterface[]
63
+	 */
64
+	private $middlewares = [];
65
+
66
+	/**
67
+	 * The route attributes
68
+	 *
69
+	 * @var array
70
+	 */
71
+	private $attributes = [];
72
+
73
+	/**
74
+	 * Constructor of the class
75
+	 *
76
+	 * @param string $name
77
+	 * @param string $path
78
+	 * @param string[] $methods
79
+	 * @param RequestHandlerInterface $requestHandler
80
+	 * @param MiddlewareInterface[] $middlewares
81
+	 * @param array $attributes
82
+	 */
83
+	public function __construct(
84
+		string $name,
85
+		string $path,
86
+		array $methods,
87
+		RequestHandlerInterface $requestHandler,
88
+		array $middlewares = [],
89
+		array $attributes = []
90
+	) {
91
+		$this->setName($name);
92
+		$this->setPath($path);
93
+		$this->setMethods(...$methods);
94
+		$this->setRequestHandler($requestHandler);
95
+		$this->setMiddlewares(...$middlewares);
96
+		$this->setAttributes($attributes);
97
+	}
98
+
99
+	/**
100
+	 * {@inheritDoc}
101
+	 */
102
+	public function getName() : string
103
+	{
104
+		return $this->name;
105
+	}
106
+
107
+	/**
108
+	 * {@inheritDoc}
109
+	 */
110
+	public function getPath() : string
111
+	{
112
+		return $this->path;
113
+	}
114
+
115
+	/**
116
+	 * {@inheritDoc}
117
+	 */
118
+	public function getMethods() : array
119
+	{
120
+		return $this->methods;
121
+	}
122
+
123
+	/**
124
+	 * {@inheritDoc}
125
+	 */
126
+	public function getRequestHandler() : RequestHandlerInterface
127
+	{
128
+		return $this->requestHandler;
129
+	}
130
+
131
+	/**
132
+	 * {@inheritDoc}
133
+	 */
134
+	public function getMiddlewares() : array
135
+	{
136
+		return $this->middlewares;
137
+	}
138
+
139
+	/**
140
+	 * {@inheritDoc}
141
+	 */
142
+	public function getAttributes() : array
143
+	{
144
+		return $this->attributes;
145
+	}
146
+
147
+	/**
148
+	 * {@inheritDoc}
149
+	 */
150
+	public function setName(string $name) : RouteInterface
151
+	{
152
+		$this->name = $name;
153
+
154
+		return $this;
155
+	}
156
+
157
+	/**
158
+	 * {@inheritDoc}
159
+	 */
160
+	public function setPath(string $path) : RouteInterface
161
+	{
162
+		$this->path = $path;
163
+
164
+		return $this;
165
+	}
166
+
167
+	/**
168
+	 * {@inheritDoc}
169
+	 */
170
+	public function setMethods(string ...$methods) : RouteInterface
171
+	{
172
+		foreach ($methods as &$method) {
173
+			$method = strtoupper($method);
174
+		}
175
+
176
+		$this->methods = $methods;
177
+
178
+		return $this;
179
+	}
180
+
181
+	/**
182
+	 * {@inheritDoc}
183
+	 */
184
+	public function setRequestHandler(RequestHandlerInterface $requestHandler) : RouteInterface
185
+	{
186
+		$this->requestHandler = $requestHandler;
187
+
188
+		return $this;
189
+	}
190
+
191
+	/**
192
+	 * {@inheritDoc}
193
+	 */
194
+	public function setMiddlewares(MiddlewareInterface ...$middlewares) : RouteInterface
195
+	{
196
+		$this->middlewares = $middlewares;
197
+
198
+		return $this;
199
+	}
200
+
201
+	/**
202
+	 * {@inheritDoc}
203
+	 */
204
+	public function setAttributes(array $attributes) : RouteInterface
205
+	{
206
+		$this->attributes = $attributes;
207
+
208
+		return $this;
209
+	}
210
+
211
+	/**
212
+	 * {@inheritDoc}
213
+	 */
214
+	public function withAddedAttributes(array $attributes) : RouteInterface
215
+	{
216
+		$clone = clone $this;
217
+
218
+		foreach ($attributes as $key => $value) {
219
+			$clone->attributes[$key] = $value;
220
+		}
221
+
222
+		return $clone;
223
+	}
224
+
225
+	/**
226
+	 * {@inheritDoc}
227
+	 */
228
+	public function buildPath(array $attributes = [], bool $strict = false) : string
229
+	{
230
+		$attributes += $this->attributes;
231
+
232
+		return path_build($this->path, $attributes, $strict);
233
+	}
234
+
235
+	/**
236
+	 * {@inheritDoc}
237
+	 */
238
+	public function buildRegex() : string
239
+	{
240
+		return path_regex($this->path);
241
+	}
242 242
 }
Please login to merge, or discard this patch.
src/Exception/MethodNotAllowedException.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -23,35 +23,35 @@
 block discarded – undo
23 23
 class MethodNotAllowedException extends RuntimeException implements ExceptionInterface
24 24
 {
25 25
 
26
-    /**
27
-     * Allowed HTTP methods
28
-     *
29
-     * @var string[]
30
-     */
31
-    private $allowedMethods;
32
-
33
-    /**
34
-     * Constructor of the class
35
-     *
36
-     * @param string[]  $allowedMethods
37
-     * @param string    $message
38
-     * @param int       $code
39
-     * @param Throwable $previous
40
-     */
41
-    public function __construct(array $allowedMethods, string $message = '', int $code = 0, Throwable $previous = null)
42
-    {
43
-        $this->allowedMethods = $allowedMethods;
44
-
45
-        parent::__construct($message, $code, $previous);
46
-    }
47
-
48
-    /**
49
-     * Gets allowed HTTP methods
50
-     *
51
-     * @return string[]
52
-     */
53
-    public function getAllowedMethods() : array
54
-    {
55
-        return $this->allowedMethods;
56
-    }
26
+	/**
27
+	 * Allowed HTTP methods
28
+	 *
29
+	 * @var string[]
30
+	 */
31
+	private $allowedMethods;
32
+
33
+	/**
34
+	 * Constructor of the class
35
+	 *
36
+	 * @param string[]  $allowedMethods
37
+	 * @param string    $message
38
+	 * @param int       $code
39
+	 * @param Throwable $previous
40
+	 */
41
+	public function __construct(array $allowedMethods, string $message = '', int $code = 0, Throwable $previous = null)
42
+	{
43
+		$this->allowedMethods = $allowedMethods;
44
+
45
+		parent::__construct($message, $code, $previous);
46
+	}
47
+
48
+	/**
49
+	 * Gets allowed HTTP methods
50
+	 *
51
+	 * @return string[]
52
+	 */
53
+	public function getAllowedMethods() : array
54
+	{
55
+		return $this->allowedMethods;
56
+	}
57 57
 }
Please login to merge, or discard this patch.
src/RouteCollectionInterface.php 1 patch
Indentation   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -23,205 +23,205 @@
 block discarded – undo
23 23
 interface RouteCollectionInterface
24 24
 {
25 25
 
26
-    /**
27
-     * Gets the collection prefix
28
-     *
29
-     * @return null|string
30
-     */
31
-    public function getPrefix() : ?string;
32
-
33
-    /**
34
-     * Gets the collection middlewares
35
-     *
36
-     * @return MiddlewareInterface[]
37
-     */
38
-    public function getMiddlewares() : array;
39
-
40
-    /**
41
-     * Gets the collection routes
42
-     *
43
-     * @return RouteInterface[]
44
-     */
45
-    public function getRoutes() : array;
46
-
47
-    /**
48
-     * Sets the given prefix to the collection
49
-     *
50
-     * @param string $prefix
51
-     *
52
-     * @return RouteCollectionInterface
53
-     */
54
-    public function setPrefix(string $prefix) : RouteCollectionInterface;
55
-
56
-    /**
57
-     * Adds the given middleware(s) to the collection
58
-     *
59
-     * @param MiddlewareInterface ...$middlewares
60
-     *
61
-     * @return RouteCollectionInterface
62
-     */
63
-    public function addMiddlewares(MiddlewareInterface ...$middlewares) : RouteCollectionInterface;
64
-
65
-    /**
66
-     * Adds the given route(s) to the collection
67
-     *
68
-     * @param RouteInterface ...$routes
69
-     *
70
-     * @return RouteCollectionInterface
71
-     */
72
-    public function addRoutes(RouteInterface ...$routes) : RouteCollectionInterface;
73
-
74
-    /**
75
-     * Makes a new route from the given parameters
76
-     *
77
-     * @param string $name
78
-     * @param string $path
79
-     * @param string[] $methods
80
-     * @param RequestHandlerInterface $requestHandler
81
-     * @param MiddlewareInterface[] $middlewares
82
-     * @param array $attributes
83
-     *
84
-     * @return RouteInterface
85
-     */
86
-    public function route(
87
-        string $name,
88
-        string $path,
89
-        array $methods,
90
-        RequestHandlerInterface $requestHandler,
91
-        array $middlewares,
92
-        array $attributes
93
-    ) : RouteInterface;
94
-
95
-    /**
96
-     * Makes a new route that will respond to HEAD requests
97
-     *
98
-     * @param string $name
99
-     * @param string $path
100
-     * @param RequestHandlerInterface $requestHandler
101
-     * @param MiddlewareInterface[] $middlewares
102
-     * @param array $attributes
103
-     *
104
-     * @return RouteInterface
105
-     */
106
-    public function head(
107
-        string $name,
108
-        string $path,
109
-        RequestHandlerInterface $requestHandler,
110
-        array $middlewares,
111
-        array $attributes
112
-    ) : RouteInterface;
113
-
114
-    /**
115
-     * Makes a new route that will respond to GET requests
116
-     *
117
-     * @param string $name
118
-     * @param string $path
119
-     * @param RequestHandlerInterface $requestHandler
120
-     * @param MiddlewareInterface[] $middlewares
121
-     * @param array $attributes
122
-     *
123
-     * @return RouteInterface
124
-     */
125
-    public function get(
126
-        string $name,
127
-        string $path,
128
-        RequestHandlerInterface $requestHandler,
129
-        array $middlewares,
130
-        array $attributes
131
-    ) : RouteInterface;
132
-
133
-    /**
134
-     * Makes a new route that will respond to POST requests
135
-     *
136
-     * @param string $name
137
-     * @param string $path
138
-     * @param RequestHandlerInterface $requestHandler
139
-     * @param MiddlewareInterface[] $middlewares
140
-     * @param array $attributes
141
-     *
142
-     * @return RouteInterface
143
-     */
144
-    public function post(
145
-        string $name,
146
-        string $path,
147
-        RequestHandlerInterface $requestHandler,
148
-        array $middlewares,
149
-        array $attributes
150
-    ) : RouteInterface;
151
-
152
-    /**
153
-     * Makes a new route that will respond to PUT requests
154
-     *
155
-     * @param string $name
156
-     * @param string $path
157
-     * @param RequestHandlerInterface $requestHandler
158
-     * @param MiddlewareInterface[] $middlewares
159
-     * @param array $attributes
160
-     *
161
-     * @return RouteInterface
162
-     */
163
-    public function put(
164
-        string $name,
165
-        string $path,
166
-        RequestHandlerInterface $requestHandler,
167
-        array $middlewares,
168
-        array $attributes
169
-    ) : RouteInterface;
170
-
171
-    /**
172
-     * Makes a new route that will respond to PATCH requests
173
-     *
174
-     * @param string $name
175
-     * @param string $path
176
-     * @param RequestHandlerInterface $requestHandler
177
-     * @param MiddlewareInterface[] $middlewares
178
-     * @param array $attributes
179
-     *
180
-     * @return RouteInterface
181
-     */
182
-    public function patch(
183
-        string $name,
184
-        string $path,
185
-        RequestHandlerInterface $requestHandler,
186
-        array $middlewares,
187
-        array $attributes
188
-    ) : RouteInterface;
189
-
190
-    /**
191
-     * Makes a new route that will respond to DELETE requests
192
-     *
193
-     * @param string $name
194
-     * @param string $path
195
-     * @param RequestHandlerInterface $requestHandler
196
-     * @param MiddlewareInterface[] $middlewares
197
-     * @param array $attributes
198
-     *
199
-     * @return RouteInterface
200
-     */
201
-    public function delete(
202
-        string $name,
203
-        string $path,
204
-        RequestHandlerInterface $requestHandler,
205
-        array $middlewares,
206
-        array $attributes
207
-    ) : RouteInterface;
208
-
209
-    /**
210
-     * Makes a new route that will respond to PURGE requests
211
-     *
212
-     * @param string $name
213
-     * @param string $path
214
-     * @param RequestHandlerInterface $requestHandler
215
-     * @param MiddlewareInterface[] $middlewares
216
-     * @param array $attributes
217
-     *
218
-     * @return RouteInterface
219
-     */
220
-    public function purge(
221
-        string $name,
222
-        string $path,
223
-        RequestHandlerInterface $requestHandler,
224
-        array $middlewares,
225
-        array $attributes
226
-    ) : RouteInterface;
26
+	/**
27
+	 * Gets the collection prefix
28
+	 *
29
+	 * @return null|string
30
+	 */
31
+	public function getPrefix() : ?string;
32
+
33
+	/**
34
+	 * Gets the collection middlewares
35
+	 *
36
+	 * @return MiddlewareInterface[]
37
+	 */
38
+	public function getMiddlewares() : array;
39
+
40
+	/**
41
+	 * Gets the collection routes
42
+	 *
43
+	 * @return RouteInterface[]
44
+	 */
45
+	public function getRoutes() : array;
46
+
47
+	/**
48
+	 * Sets the given prefix to the collection
49
+	 *
50
+	 * @param string $prefix
51
+	 *
52
+	 * @return RouteCollectionInterface
53
+	 */
54
+	public function setPrefix(string $prefix) : RouteCollectionInterface;
55
+
56
+	/**
57
+	 * Adds the given middleware(s) to the collection
58
+	 *
59
+	 * @param MiddlewareInterface ...$middlewares
60
+	 *
61
+	 * @return RouteCollectionInterface
62
+	 */
63
+	public function addMiddlewares(MiddlewareInterface ...$middlewares) : RouteCollectionInterface;
64
+
65
+	/**
66
+	 * Adds the given route(s) to the collection
67
+	 *
68
+	 * @param RouteInterface ...$routes
69
+	 *
70
+	 * @return RouteCollectionInterface
71
+	 */
72
+	public function addRoutes(RouteInterface ...$routes) : RouteCollectionInterface;
73
+
74
+	/**
75
+	 * Makes a new route from the given parameters
76
+	 *
77
+	 * @param string $name
78
+	 * @param string $path
79
+	 * @param string[] $methods
80
+	 * @param RequestHandlerInterface $requestHandler
81
+	 * @param MiddlewareInterface[] $middlewares
82
+	 * @param array $attributes
83
+	 *
84
+	 * @return RouteInterface
85
+	 */
86
+	public function route(
87
+		string $name,
88
+		string $path,
89
+		array $methods,
90
+		RequestHandlerInterface $requestHandler,
91
+		array $middlewares,
92
+		array $attributes
93
+	) : RouteInterface;
94
+
95
+	/**
96
+	 * Makes a new route that will respond to HEAD requests
97
+	 *
98
+	 * @param string $name
99
+	 * @param string $path
100
+	 * @param RequestHandlerInterface $requestHandler
101
+	 * @param MiddlewareInterface[] $middlewares
102
+	 * @param array $attributes
103
+	 *
104
+	 * @return RouteInterface
105
+	 */
106
+	public function head(
107
+		string $name,
108
+		string $path,
109
+		RequestHandlerInterface $requestHandler,
110
+		array $middlewares,
111
+		array $attributes
112
+	) : RouteInterface;
113
+
114
+	/**
115
+	 * Makes a new route that will respond to GET requests
116
+	 *
117
+	 * @param string $name
118
+	 * @param string $path
119
+	 * @param RequestHandlerInterface $requestHandler
120
+	 * @param MiddlewareInterface[] $middlewares
121
+	 * @param array $attributes
122
+	 *
123
+	 * @return RouteInterface
124
+	 */
125
+	public function get(
126
+		string $name,
127
+		string $path,
128
+		RequestHandlerInterface $requestHandler,
129
+		array $middlewares,
130
+		array $attributes
131
+	) : RouteInterface;
132
+
133
+	/**
134
+	 * Makes a new route that will respond to POST requests
135
+	 *
136
+	 * @param string $name
137
+	 * @param string $path
138
+	 * @param RequestHandlerInterface $requestHandler
139
+	 * @param MiddlewareInterface[] $middlewares
140
+	 * @param array $attributes
141
+	 *
142
+	 * @return RouteInterface
143
+	 */
144
+	public function post(
145
+		string $name,
146
+		string $path,
147
+		RequestHandlerInterface $requestHandler,
148
+		array $middlewares,
149
+		array $attributes
150
+	) : RouteInterface;
151
+
152
+	/**
153
+	 * Makes a new route that will respond to PUT requests
154
+	 *
155
+	 * @param string $name
156
+	 * @param string $path
157
+	 * @param RequestHandlerInterface $requestHandler
158
+	 * @param MiddlewareInterface[] $middlewares
159
+	 * @param array $attributes
160
+	 *
161
+	 * @return RouteInterface
162
+	 */
163
+	public function put(
164
+		string $name,
165
+		string $path,
166
+		RequestHandlerInterface $requestHandler,
167
+		array $middlewares,
168
+		array $attributes
169
+	) : RouteInterface;
170
+
171
+	/**
172
+	 * Makes a new route that will respond to PATCH requests
173
+	 *
174
+	 * @param string $name
175
+	 * @param string $path
176
+	 * @param RequestHandlerInterface $requestHandler
177
+	 * @param MiddlewareInterface[] $middlewares
178
+	 * @param array $attributes
179
+	 *
180
+	 * @return RouteInterface
181
+	 */
182
+	public function patch(
183
+		string $name,
184
+		string $path,
185
+		RequestHandlerInterface $requestHandler,
186
+		array $middlewares,
187
+		array $attributes
188
+	) : RouteInterface;
189
+
190
+	/**
191
+	 * Makes a new route that will respond to DELETE requests
192
+	 *
193
+	 * @param string $name
194
+	 * @param string $path
195
+	 * @param RequestHandlerInterface $requestHandler
196
+	 * @param MiddlewareInterface[] $middlewares
197
+	 * @param array $attributes
198
+	 *
199
+	 * @return RouteInterface
200
+	 */
201
+	public function delete(
202
+		string $name,
203
+		string $path,
204
+		RequestHandlerInterface $requestHandler,
205
+		array $middlewares,
206
+		array $attributes
207
+	) : RouteInterface;
208
+
209
+	/**
210
+	 * Makes a new route that will respond to PURGE requests
211
+	 *
212
+	 * @param string $name
213
+	 * @param string $path
214
+	 * @param RequestHandlerInterface $requestHandler
215
+	 * @param MiddlewareInterface[] $middlewares
216
+	 * @param array $attributes
217
+	 *
218
+	 * @return RouteInterface
219
+	 */
220
+	public function purge(
221
+		string $name,
222
+		string $path,
223
+		RequestHandlerInterface $requestHandler,
224
+		array $middlewares,
225
+		array $attributes
226
+	) : RouteInterface;
227 227
 }
Please login to merge, or discard this patch.