1 | <?php |
||
13 | class Router |
||
14 | { |
||
15 | protected $routeCollector; |
||
16 | protected $redirects = []; |
||
17 | |||
18 | 4 | public function __construct(RouteCollector $routeCollector) |
|
19 | { |
||
20 | 4 | $this->routeCollector = $routeCollector; |
|
21 | 4 | } |
|
22 | |||
23 | 2 | public function get(string $url, string $controller): Router |
|
24 | { |
||
25 | 2 | $this->routeCollector->addRoute('GET', $url, [$controller, 'handle']); |
|
26 | |||
27 | 2 | return $this; |
|
28 | } |
||
29 | |||
30 | public function put(string $url, string $controller): Router |
||
31 | { |
||
32 | $this->routeCollector->addRoute('PUT', $url, [$controller, 'handle']); |
||
33 | |||
34 | return $this; |
||
35 | } |
||
36 | |||
37 | public function post(string $url, string $controller): Router |
||
38 | { |
||
39 | $this->routeCollector->addRoute('POST', $url, [$controller, 'handle']); |
||
40 | |||
41 | return $this; |
||
42 | } |
||
43 | |||
44 | public function patch(string $url, string $controller): Router |
||
45 | { |
||
46 | $this->routeCollector->addRoute('PATCH', $url, [$controller, 'handle']); |
||
47 | |||
48 | return $this; |
||
49 | } |
||
50 | |||
51 | public function delete(string $url, string $controller): Router |
||
52 | { |
||
53 | $this->routeCollector->addRoute('DELETE', $url, [$controller, 'handle']); |
||
54 | |||
55 | return $this; |
||
56 | } |
||
57 | |||
58 | 1 | public function redirect(string $url, string $targetUrl): Router |
|
64 | |||
65 | public function getRedirectForUrl(string $url): ?string |
||
66 | { |
||
67 | return $this->redirects[$url] ?? null; |
||
68 | } |
||
69 | |||
70 | 1 | public function dispatch(Request $request): ?Response |
|
71 | { |
||
88 | |||
89 | 1 | protected function resolveHandler(array $callback): array |
|
103 | } |
||
104 |