Proof в Laravel CommandBus не смог определить CommandHandler

У меня есть приложение Laravel 5.7, где я хочу добавить Proof для источников событий. Я следую инструкциям, но получаю эту ошибку:

Prooph\ServiceBus\Exception\RuntimeException: CommandBus was not able to identify a CommandHandler for command App\src\Prooph\Model\Procedure\Command\ChangeProcedureState in /var/www/html/vendor/prooph/service-bus/src/CommandBus.php:58

Это мой файл config / prooph.php

return [
'event_store' => [
'adapter' => [
'type' => \Prooph\EventStore\Pdo\MySqlEventStore::class,
'options' => [
'connection_alias' => 'laravel.connections.pdo',
],
],
'plugins' => [
\Prooph\EventStoreBusBridge\EventPublisher::class,
\Prooph\EventStoreBusBridge\TransactionManager::class,
],
'procedure_collection' => [
'repository_class' => App\src\Prooph\Infrastructure\Repository\EventStoreProcedureCollection::class,
'aggregate_type' => App\src\Prooph\Model\Procedure\Procedure::class,
],
],
'service_bus' => [
'command_bus' => [
'router' => [
'type' => \Prooph\ServiceBus\Plugin\Router\CommandRouter::class,
'routes' => [
// list of commands with corresponding command handler
\App\src\Prooph\Model\Procedure\Command\ChangeProcedureState::class => App\src\Prooph\Model\Procedure\Handler\ChangeProcedureStateHandler::class,
],
],
],
'event_bus' => [
'plugins' => [
\Prooph\ServiceBus\Plugin\InvokeStrategy\OnEventStrategy::class,
],
'router' => [
'routes' => [
// list of events with a list of projectors
],
],
],
/*'event_bus' => [
'router' => [
'routes' => [
// list of events with a list of projectors
App\src\Prooph\ProophessorDo\Model\User\Event\UserWasRegistered::class => [
\App\src\Prooph\ProophessorDo\Projection\User\UserProjector::class
],
],
],
],*/
],
];

Это мой сервис, который отправляет команду

class ProcedureRetrieveStateChanged
{
/** @var \FluentProceduresRepository $procedureRepository */
private $procedureRepository;
/**
* @var CommandBus
*/
private $commandBus;

public function __construct(\FluentProceduresRepository $procedureRepository, CommandBus $commandBus)
{
$this->procedureRepository = $procedureRepository;
$this->commandBus = $commandBus;
}

public function execute($procedureId, array $groups)
{
$procedure = $this->procedureRepository->find($procedureId);

if (null === $procedure) {
return false;
}

foreach ($groups as $group) {
$actualState = $procedure->getStatebyGroup($group['pivot']['group_id']);

if ($actualState !== $group['pivot']['state']) {
$command = new ChangeProcedureState(
[
'procedure_id' => $procedureId,
'group_id' => $group['pivot']['group_id'],
'old_state' => $actualState,
'new_state' => $group['pivot']['state'],
]
);

$this->commandBus->dispatch($command);

}
}
}
}

Это моя команда

final class ChangeProcedureState extends Command implements PayloadConstructable
{
use PayloadTrait;

public function procedureId(): ProcedureId
{
return ProcedureId::fromString($this->payload['procedure_id']);
}

public function state(): string
{
return $this->payload['state'];
}

protected function setPayload(array $payload): void
{
Assertion::keyExists($payload, 'procedure_id');
Assertion::keyExists($payload, 'group_id');
Assertion::keyExists($payload, 'old_state');
Assertion::keyExists($payload, 'new_state');

$this->payload = $payload;
}
}

И это мой обработчик

class ChangeProcedureStateHandler
{
/**
* @var ProcedureCollection
*/
private $procedureCollection;

public function __construct(ProcedureCollection $procedureCollection)
{
$this->procedureCollection = $procedureCollection;
}

public function __invoke(ChangeProcedureState $command): void
{
$procedure = $this->procedureCollection->get($command->procedureId());
$procedure->changeState($command->state());

$this->procedureCollection->save($procedure);
}
}

Может кто-нибудь помочь мне с этой проблемой?

0

Решение

Чтобы использовать обработчики в качестве строки, вам нужно использовать ServiceLocatorPlugin, но перед этим вам нужно зарегистрировать все обработчики в контейнере laravel, например, $ app-> singletor … или $ app-> bind.

Приветствия.

0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]