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