diff --git a/src/Command/CommandBusInterface.php b/src/Command/CommandBusInterface.php index cac9264..f1d4c13 100644 --- a/src/Command/CommandBusInterface.php +++ b/src/Command/CommandBusInterface.php @@ -14,5 +14,5 @@ namespace Zapoyok\CQRSBundle\Command; interface CommandBusInterface { - public function dispatch(CommandInterface $command): void; + public function dispatch(CommandInterface $command): mixed; } diff --git a/src/Command/MessengerCommandBus.php b/src/Command/MessengerCommandBus.php index 1e8f994..d690d32 100644 --- a/src/Command/MessengerCommandBus.php +++ b/src/Command/MessengerCommandBus.php @@ -12,19 +12,24 @@ declare(strict_types=1); namespace Zapoyok\CQRSBundle\Command; +use Symfony\Component\Messenger\HandleTrait; use Symfony\Component\Messenger\MessageBusInterface; +use Symfony\Component\Messenger\Stamp\HandledStamp; final class MessengerCommandBus implements CommandBusInterface { - private MessageBusInterface $commandBus; - public function __construct(MessageBusInterface $commandBus) - { - $this->commandBus = $commandBus; + use HandleTrait; + + public function __construct( MessageBusInterface $commandBus, ) { + $this->messageBus = $commandBus; } - public function dispatch(CommandInterface $command): void + public function dispatch(CommandInterface $command): mixed { - $this->commandBus->dispatch($command); + $envelope = $this->messageBus->dispatch($command); + return $envelope->last(HandledStamp::class)->getResult(); + +// $this->commandBus->dispatch($command); } } diff --git a/src/Query/MessengerQueryBus.php b/src/Query/MessengerQueryBus.php index 3e724a3..bcf1466 100644 --- a/src/Query/MessengerQueryBus.php +++ b/src/Query/MessengerQueryBus.php @@ -17,17 +17,15 @@ use Symfony\Component\Messenger\MessageBusInterface; final class MessengerQueryBus implements QueryBusInterface { - use HandleTrait { - handle as handleQuery; - } + use HandleTrait ; - public function __construct(MessageBusInterface $queryBus) - { + + public function __construct( MessageBusInterface $queryBus, ) { $this->messageBus = $queryBus; } public function ask(QueryInterface $query): mixed { - return $this->handleQuery($query); + return $this->handle($query); } } diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index 557b85a..1eacda4 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -25,6 +25,7 @@ return static function (ContainerConfigurator $containerConfigurator): void { ->exclude([ __DIR__, __DIR__.'/../../../src/ZapoyokCQRSBundle.php', + __DIR__.'/../../../src/MessageId.php', __DIR__.'/../../../src/{DependencyInjection}', ]) ;