Hi, I’m trying to autowire routes as suggested in the docs here.
My config provider class is as follows.
class ConfigProvider
{
public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
'templates' => $this->getTemplates(),
];
}
public function getDependencies(): array
{
return [
'invokables' => [
Handler\PingHandler::class => Handler\PingHandler::class,
],
'factories' => [
Handler\HomePageHandler::class => Handler\HomePageHandlerFactory::class,
],
'delegators' => [
\Mezzio\Application::class => [
\LrphptMenu\Factory\PipelineAndRoutesDelegator::class,
],
],
];
}
public function getTemplates(): array
{
return [
'paths' => [
'lrphpt-menu' => [__DIR__ . '/../templates/'],
],
];
}
}
Code as mentioned in PipelineAndRoutesDelegator.
class PipelineAndRoutesDelegator
{
public function __invoke(
ContainerInterface $container,
string $serviceName,
callable $callback
) : Application {
/** @var $app Application */
$app = $callback();
// Setup routes:
$app->get('/lrphpt-menu', \LrphptMenu\Handler\HomePageHandler::class, 'lrphpt-menu');
return $app;
}
}
Thanks!