This commit is contained in:
2026-01-15 07:06:28 +01:00
parent ab6ee3715b
commit 9e5d534cd5
4 changed files with 17 additions and 13 deletions

View File

@@ -14,5 +14,5 @@ namespace Zapoyok\CQRSBundle\Command;
interface CommandBusInterface interface CommandBusInterface
{ {
public function dispatch(CommandInterface $command): void; public function dispatch(CommandInterface $command): mixed;
} }

View File

@@ -12,19 +12,24 @@ declare(strict_types=1);
namespace Zapoyok\CQRSBundle\Command; namespace Zapoyok\CQRSBundle\Command;
use Symfony\Component\Messenger\HandleTrait;
use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Stamp\HandledStamp;
final class MessengerCommandBus implements CommandBusInterface final class MessengerCommandBus implements CommandBusInterface
{ {
private MessageBusInterface $commandBus;
public function __construct(MessageBusInterface $commandBus) use HandleTrait;
{
$this->commandBus = $commandBus; 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);
} }
} }

View File

@@ -17,17 +17,15 @@ use Symfony\Component\Messenger\MessageBusInterface;
final class MessengerQueryBus implements QueryBusInterface final class MessengerQueryBus implements QueryBusInterface
{ {
use HandleTrait { use HandleTrait ;
handle as handleQuery;
}
public function __construct(MessageBusInterface $queryBus)
{ public function __construct( MessageBusInterface $queryBus, ) {
$this->messageBus = $queryBus; $this->messageBus = $queryBus;
} }
public function ask(QueryInterface $query): mixed public function ask(QueryInterface $query): mixed
{ {
return $this->handleQuery($query); return $this->handle($query);
} }
} }

View File

@@ -25,6 +25,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
->exclude([ ->exclude([
__DIR__, __DIR__,
__DIR__.'/../../../src/ZapoyokCQRSBundle.php', __DIR__.'/../../../src/ZapoyokCQRSBundle.php',
__DIR__.'/../../../src/MessageId.php',
__DIR__.'/../../../src/{DependencyInjection}', __DIR__.'/../../../src/{DependencyInjection}',
]) ])
; ;