1 | <?php |
||
30 | class RouteCollection implements RouteCollectionInterface |
||
31 | { |
||
32 | /** |
||
33 | * |
||
34 | * Controller::Method delimiter. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $delimiter = '::'; |
||
39 | |||
40 | /** |
||
41 | * RouteInterfaces |
||
42 | * |
||
43 | * @var array. |
||
44 | */ |
||
45 | protected $collection = []; |
||
46 | /** |
||
47 | * Route group context. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $group = []; |
||
52 | /** |
||
53 | * Route group names. |
||
54 | * |
||
55 | * @var array |
||
56 | */ |
||
57 | protected $groupNames = []; |
||
58 | /** |
||
59 | * Namespaces for Controller::Method handler. |
||
60 | * |
||
61 | * @var array |
||
62 | */ |
||
63 | protected $namespace = []; |
||
64 | /** |
||
65 | * Global Collection route names. |
||
66 | * |
||
67 | * @var array |
||
68 | */ |
||
69 | protected $globalRouteNames = []; |
||
70 | /** |
||
71 | * Is grouped callback flag. |
||
72 | * |
||
73 | * @var bool |
||
74 | */ |
||
75 | private $_isGrouped = false; |
||
76 | |||
77 | /** |
||
78 | * Add Namespace to Route Collection. |
||
79 | * |
||
80 | * @param string $namespace Controller Namespace. |
||
81 | */ |
||
82 | public function addNamespace(string $namespace) |
||
86 | |||
87 | /** |
||
88 | * @param array $names |
||
89 | */ |
||
90 | public function addGlobalNames(array $names) |
||
96 | |||
97 | /** |
||
98 | * @inheritdoc |
||
99 | */ |
||
100 | public function group($path = '', callable $routeCallback, array $names = []) |
||
110 | |||
111 | /** |
||
112 | * @inheritdoc |
||
113 | * |
||
114 | * @throws \Rs\Router\Exceptions\UniqueRouteException |
||
115 | */ |
||
116 | public function addRoute($method, $pattern, $handler, $name = []) |
||
138 | |||
139 | /** |
||
140 | * Add Namespace to handler. |
||
141 | * |
||
142 | * @param mixed $handler |
||
143 | * |
||
144 | * @return mixed |
||
145 | */ |
||
146 | private function _findHandlerNamespace($handler) |
||
162 | |||
163 | /** |
||
164 | * Check that the Route is unique before adding it (again). |
||
165 | * |
||
166 | * @param $method |
||
167 | * @param $pattern |
||
168 | * @return bool |
||
169 | * @throws UniqueRouteException |
||
170 | */ |
||
171 | private function _isUnique($method, $pattern) |
||
183 | |||
184 | /** |
||
185 | * Get Collection global route names. |
||
186 | * |
||
187 | * @param array $names Routes names to merge with globals. |
||
188 | * |
||
189 | * @return array |
||
190 | */ |
||
191 | private function _getRouteGlobals(array $names) |
||
199 | |||
200 | /** |
||
201 | * Merge Route Names with group. |
||
202 | * |
||
203 | * @param array $names Route names to be added to group. |
||
204 | * |
||
205 | * @return array |
||
206 | */ |
||
207 | private function _mergeGroupNames(array $names) |
||
217 | |||
218 | /** |
||
219 | * Format Route Pattern and return with grouped directory is necessary. |
||
220 | * |
||
221 | * @param $pattern |
||
222 | * @return string |
||
223 | */ |
||
224 | public function formatRoutePattern($pattern) |
||
241 | |||
242 | /** |
||
243 | * @inheritdoc |
||
244 | */ |
||
245 | public function mergeCollection(RouteCollectionInterface $collection, bool $throw = true) |
||
266 | |||
267 | /** |
||
268 | * @inheritdoc |
||
269 | */ |
||
270 | public function getRoutes() |
||
274 | |||
275 | /** |
||
276 | * Returns current route. |
||
277 | * |
||
278 | * @return RouteInterface |
||
279 | */ |
||
280 | public function current() |
||
284 | |||
285 | /** |
||
286 | * Returns next route. |
||
287 | * |
||
288 | * @return RouteInterface |
||
289 | */ |
||
290 | public function next() |
||
294 | |||
295 | /** |
||
296 | * Returns current route index. |
||
297 | * |
||
298 | * @return mixed |
||
299 | */ |
||
300 | public function key() |
||
304 | |||
305 | /** |
||
306 | * If last route not reached. |
||
307 | * |
||
308 | * @return bool |
||
309 | */ |
||
310 | public function valid() |
||
315 | |||
316 | /** |
||
317 | * Return to and return first route. |
||
318 | * |
||
319 | * @return RouteInterface |
||
320 | */ |
||
321 | public function rewind() |
||
325 | |||
326 | /** |
||
327 | * Get total routes in collection. |
||
328 | * |
||
329 | * @return int |
||
330 | */ |
||
331 | public function count() |
||
335 | } |
||
336 |