| 1 | <?php |
| 2 | |
| 3 | namespace SomeModule; |
| 4 | |
| 5 | use Mezzio\Router\RouteCollectorInterface; |
| 6 | |
| 7 | class ConfigProvider |
| 8 | { |
| 9 | public function getConfig(): array |
| 10 | { |
| 11 | } |
| 12 | |
| 13 | public function getDependencies(): array |
| 14 | { |
| 15 | return [ |
| 16 | 'delegators' => [ |
| 17 | RouteCollectorInterface::class => [ |
| 18 | RegisterRoutesFactory::class, |
| 19 | ], |
| 20 | ], |
| 21 | ]; |
| 22 | } |
| 23 | } |
matthew / ConfigProvider.php
Last active 1 week ago
An example of attaching a delegator factory to the Mezzio RouteCollectorInterface to automate route registration.
Revision a270f1b9e064c137cc9ab7c0507048c32f35e20b
| 1 | <?php |
| 2 | |
| 3 | namespace SomeModule; |
| 4 | |
| 5 | use Psr\Container\ContainerInterface; |
| 6 | |
| 7 | class RegisterRoutesFactory |
| 8 | { |
| 9 | public function __invoke( |
| 10 | ContainerInterface $container, |
| 11 | string $serviceName, |
| 12 | callable $factory, |
| 13 | ): RouteCollectorInterface { |
| 14 | /** @var RouteCollectorInterface $routes */ |
| 15 | $routes = $factory(); |
| 16 | |
| 17 | $routes->get(...) |
| 18 | |
| 19 | return $routes; |
| 20 | } |
| 21 | } |