Total Complexity | 4 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
9 | class RouteCollection implements Countable, IteratorAggregate |
||
10 | { |
||
11 | /** |
||
12 | * An array of the routes keyed by method. |
||
13 | * |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $routes = []; |
||
17 | |||
18 | /** |
||
19 | * Add a Route instance to the collection. |
||
20 | * |
||
21 | * @param \Controlabs\Routify\Route $route |
||
22 | * |
||
23 | * @return \Controlabs\Routify\Route |
||
24 | */ |
||
25 | public function add(Route $route) |
||
26 | { |
||
27 | // $this->routes[$route->method()][$route->uri()] = $route; |
||
28 | $this->routes[$route->method().$route->route()] = $route; |
||
29 | return $route; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Get all routes. |
||
34 | * |
||
35 | * @return array |
||
36 | */ |
||
37 | public function get() |
||
38 | { |
||
39 | return array_values($this->routes); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Get an iterator for the items. |
||
44 | * |
||
45 | * @return \ArrayIterator |
||
46 | */ |
||
47 | public function getIterator() |
||
48 | { |
||
49 | return new ArrayIterator($this->get()); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Count the number of items in the collection. |
||
54 | * |
||
55 | * @return int |
||
56 | */ |
||
57 | public function count() |
||
60 | } |
||
61 | } |
||
62 |