1 | <?php |
||
20 | final class RouteLoader extends Loader |
||
21 | { |
||
22 | private $directories; |
||
23 | private $routeFactory; |
||
24 | private $imported = false; |
||
25 | |||
26 | 16 | public function __construct( |
|
27 | MapInterface $directories, |
||
28 | RouteFactory $routeFactory |
||
29 | ) { |
||
30 | if ( |
||
31 | 16 | (string) $directories->keyType() !== 'string' || |
|
32 | 16 | (string) $directories->valueType() !== Directory::class |
|
33 | ) { |
||
34 | 2 | throw new \TypeError(sprintf( |
|
35 | 2 | 'Argument 1 must be of type MapInterface<string, %s>', |
|
36 | 2 | Directory::class |
|
37 | )); |
||
38 | } |
||
39 | |||
40 | 16 | $this->directories = $directories; |
|
41 | 16 | $this->routeFactory = $routeFactory; |
|
42 | 16 | } |
|
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | 8 | public function load($resource, $type = null) |
|
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | 2 | public function supports($resource, $type = null) |
|
86 | |||
87 | 8 | private function buildDirectoryRoutes(Directory $directory): RouteCollection |
|
88 | { |
||
89 | return $directory |
||
90 | 8 | ->flatten() |
|
91 | 8 | ->reduce( |
|
92 | 8 | new RouteCollection, |
|
93 | 8 | function(RouteCollection $routes, string $name, HttpResource $definition) { |
|
94 | 8 | $routes->addCollection( |
|
95 | 8 | $this->buildResourceRoutes($name, $definition) |
|
96 | ); |
||
97 | |||
98 | 8 | return $routes; |
|
99 | 8 | } |
|
100 | ); |
||
101 | } |
||
102 | |||
103 | 8 | private function buildResourceRoutes( |
|
127 | } |
||
128 |