Last active 1765310259

An example of attaching a delegator factory to the Mezzio RouteCollectorInterface to automate route registration.

Revision a270f1b9e064c137cc9ab7c0507048c32f35e20b

ConfigProvider.php Raw
1<?php
2
3namespace SomeModule;
4
5use Mezzio\Router\RouteCollectorInterface;
6
7class 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}
RegisterRoutesFactory.php Raw
1<?php
2
3namespace SomeModule;
4
5use Psr\Container\ContainerInterface;
6
7class 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}