| Total Complexity | 9 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | class RouterCollection implements RouterInterface |
||
| 17 | { |
||
| 18 | private const ROUTE_NOT_FOUND = 'page://self/__route_not_found'; |
||
| 19 | |||
| 20 | /** @param RouterInterface[] $routers */ |
||
| 21 | public function __construct( |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * {@inheritDoc} |
||
| 28 | */ |
||
| 29 | public function match(array $globals, array $server) |
||
| 30 | { |
||
| 31 | foreach ($this->routers as $route) { |
||
| 32 | try { |
||
| 33 | $match = $route->match($globals, $server); |
||
| 34 | } catch (Throwable $e) { |
||
| 35 | $e = new RouterException($e->getMessage(), (int) $e->getCode(), $e->getPrevious()); |
||
| 36 | /** @noinspection ForgottenDebugOutputInspection */ |
||
| 37 | error_log((string) $e); |
||
| 38 | |||
| 39 | return $this->routeNotFound(); |
||
| 40 | } |
||
| 41 | |||
| 42 | if (! $match instanceof NullMatch) { |
||
| 43 | return $match; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | return $this->routeNotFound(); |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * {@inheritDoc} |
||
| 52 | */ |
||
| 53 | public function generate($name, $data) |
||
| 54 | { |
||
| 55 | foreach ($this->routers as $route) { |
||
| 56 | $uri = $route->generate($name, $data); |
||
| 57 | if (is_string($uri)) { |
||
| 58 | return $uri; |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | return false; |
||
| 63 | } |
||
| 64 | |||
| 65 | private function routeNotFound(): RouterMatch |
||
| 68 | } |
||
| 69 | } |
||
| 70 |