1 | <?php |
||
8 | class RouteCollection implements \Countable, \IteratorAggregate |
||
9 | { |
||
10 | use RouteBuilderTrait; |
||
11 | |||
12 | /** |
||
13 | * Array of routes |
||
14 | * @var Route[] |
||
15 | */ |
||
16 | protected $routes = []; |
||
17 | |||
18 | /** |
||
19 | * Array of route names |
||
20 | * @var Route[] |
||
21 | */ |
||
22 | protected $names = []; |
||
23 | |||
24 | /** |
||
25 | * Array of route actions |
||
26 | * @var Route[] |
||
27 | */ |
||
28 | protected $actions = []; |
||
29 | |||
30 | protected static $defaultOptions = [ |
||
31 | 'prefix' => null, |
||
32 | 'host' => null, |
||
33 | 'methods' => [], |
||
34 | 'schemes' => [], |
||
35 | 'requirements' => [], |
||
36 | 'defaults' => [] |
||
37 | ]; |
||
38 | |||
39 | public function __construct(array $routes = []) |
||
45 | |||
46 | /** |
||
47 | * Add a route to the collection |
||
48 | * @param Route $route |
||
49 | */ |
||
50 | public function add(Route $route) |
||
61 | |||
62 | /** |
||
63 | * Finds the route by the given name |
||
64 | * @param string $name |
||
65 | * @return Route|null |
||
66 | */ |
||
67 | public function getByName($name) |
||
71 | |||
72 | /** |
||
73 | * Finds the route by the given action |
||
74 | * @param string $action |
||
75 | * @return Route|null |
||
76 | */ |
||
77 | public function getByAction($action) |
||
81 | |||
82 | /** |
||
83 | * Gets all named routes |
||
84 | * @return Route[] |
||
85 | */ |
||
86 | public function getNamedRoutes() |
||
90 | |||
91 | /** |
||
92 | * Creates a sub collection routes |
||
93 | * @param string|array $options |
||
94 | * @param \Closure $callback |
||
95 | */ |
||
96 | public function group($options, \Closure $callback) |
||
105 | |||
106 | /** |
||
107 | * Merges routes from an route collection |
||
108 | * @param RouteCollection $collection |
||
109 | * @param array $options |
||
110 | */ |
||
111 | protected function mergeSubCollection(RouteCollection $collection, $options = []) |
||
135 | |||
136 | /** |
||
137 | * Gets all routes |
||
138 | * @return Route[] |
||
139 | */ |
||
140 | public function all() |
||
144 | |||
145 | /** |
||
146 | * {@inheritdoc} |
||
147 | */ |
||
148 | public function count() |
||
152 | |||
153 | /** |
||
154 | * {@inheritdoc} |
||
155 | */ |
||
156 | public function getIterator() |
||
160 | } |