I’m trying to use initializers in my service manager config in module.config.php
. This is my config:
<?php
/**
* @see https://github.com/laminas/laminas-mvc-skeleton for the canonical source repository
*
* @copyright https://github.com/laminas/laminas-mvc-skeleton/blob/master/COPYRIGHT.md
* @license https://github.com/laminas/laminas-mvc-skeleton/blob/master/LICENSE.md New BSD License
*/
declare(strict_types=1);
namespace Worker;
use Laminas\ServiceManager\Factory\InvokableFactory;
use Worker\Command\HelloCommand;
use Worker\Command\PublishCommand;
use Worker\Command\QueueCommandInitializer;
use Worker\Service\ElasticService;
use Worker\Service\ElasticServiceFactory;
use Worker\Service\RabbitmqService;
use Worker\Service\RabbitmqServiceFactory;
return [
'laminas-cli' => [
'commands' => [
'app:hello' => HelloCommand::class,
'app:publish' => PublishCommand::class,
],
],
'service_manager' => [
'factories' => [
HelloCommand::class => InvokableFactory::class,
PublishCommand::class => InvokableFactory::class,
RabbitmqService::class => RabbitmqServiceFactory::class,
ElasticService::class => ElasticServiceFactory::class
],
'initializers' => [
new QueueCommandInitializer()
]
],
];
The QueueCommandInitializer looks like this:
<?php
/**
* @see https://github.com/laminas/laminas-mvc-skeleton for the canonical source repository
*
* @copyright https://github.com/laminas/laminas-mvc-skeleton/blob/master/COPYRIGHT.md
* @license https://github.com/laminas/laminas-mvc-skeleton/blob/master/LICENSE.md New BSD License
*/
declare(strict_types=1);
namespace Worker\Command;
use Laminas\ServiceManager\Initializer\InitializerInterface;
use Psr\Container\ContainerInterface;
use Worker\Service\RabbitmqService;
class QueueCommandInitializer implements InitializerInterface
{
public function __invoke(ContainerInterface $container, HelloCommand $instance)
{
if (!$instance instanceof QueueCommandInterface) {
return;
}
$instance->setQueue($container->get(RabbitmqService::class));
}
}
The QueueCommandInterface
is an empty interface.
When I try to run my app I get the following error:
Fatal error: Uncaught Error: Class "Worker\Command\QueueCommandInitializer" not found in /Users/<redacted>/module/Worker/config/module.config.php:38
And I can’t figure out why. Any ideas?