1 | <?php |
||
8 | abstract class AbstractRouter { |
||
9 | |||
10 | /** |
||
11 | * Application instance |
||
12 | * |
||
13 | * @var Application |
||
14 | */ |
||
15 | private $application; |
||
16 | |||
17 | 3 | public function setApplication(Application $application) |
|
24 | |||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | private $routes; |
||
29 | |||
30 | 3 | public function addRoute(string $name, AbstractController $controller) |
|
34 | |||
35 | /** |
||
36 | * Checks wether a route exists |
||
37 | * |
||
38 | * @param string $name |
||
39 | * @return bool |
||
40 | */ |
||
41 | 3 | public function hasRoute(string $name) |
|
45 | |||
46 | /** |
||
47 | * |
||
48 | * @param string $name |
||
49 | * @throws RouterException |
||
50 | * @return AbstractController |
||
51 | */ |
||
52 | 2 | private function getRoute(string $name) |
|
60 | |||
61 | /** |
||
62 | * Route the existing request into a new controller |
||
63 | * |
||
64 | * @param string $name The name of route |
||
65 | * @param Request $request The existing request instance |
||
66 | * @return \Nkey\Caribu\Mvc\Controller\AbstractController |
||
67 | */ |
||
68 | 2 | public function route(string $name, Request $request) |
|
91 | } |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: