1 | <?php |
||
9 | final class EntityRouteLoader extends Loader |
||
10 | { |
||
11 | const RESOURCE_TYPE = 'cruds_mount'; |
||
12 | /** @var Route[][] */ |
||
13 | private $routes = []; |
||
14 | /** @var bool[] */ |
||
15 | private $loaded = []; |
||
16 | |||
17 | /** {@inheritdoc} */ |
||
18 | 2 | public function load($mount, $type = null) |
|
19 | { |
||
20 | 2 | $this->assertLoaded($mount); |
|
21 | |||
22 | 2 | $collection = new RouteCollection(); |
|
23 | 2 | if (!array_key_exists($mount, $this->routes)) { |
|
24 | return $collection; |
||
25 | } |
||
26 | |||
27 | 2 | foreach ($this->routes[$mount] as $name => $route) { |
|
28 | 2 | $collection->add($name, $route); |
|
29 | } |
||
30 | |||
31 | 2 | $this->loaded[$mount] = true; |
|
32 | |||
33 | 2 | return $collection; |
|
34 | } |
||
35 | |||
36 | /** {@inheritdoc} */ |
||
37 | 2 | public function supports($mount, $type = null): bool |
|
41 | |||
42 | /** |
||
43 | * @param string $mount |
||
44 | * @param string $name |
||
45 | * @param string $path |
||
46 | * @param string $controller |
||
47 | * @param array $methods |
||
48 | * @param array $options |
||
49 | * |
||
50 | * @throws \LogicException |
||
51 | */ |
||
52 | 2 | public function addRoute($mount, $name, $path, $controller, array $methods, array $options = []) |
|
58 | |||
59 | /** |
||
60 | * @param string $mount |
||
61 | * |
||
62 | * @return Route[] |
||
63 | * |
||
64 | * @throws \OutOfBoundsException if mount does not exist |
||
65 | */ |
||
66 | public function getRoutes($mount): array |
||
74 | |||
75 | /** |
||
76 | * @return string[] |
||
77 | */ |
||
78 | public function getMounts(): array |
||
82 | |||
83 | /** |
||
84 | * @param $resource |
||
85 | * |
||
86 | * @throws \LogicException |
||
87 | */ |
||
88 | 2 | private function assertLoaded($resource) |
|
94 | } |
||
95 |