<?php
declare(strict_types=1);
namespace App\Infrastructure\Shared\Bus\Command;
use Symfony\Component\Messenger\Exception\HandlerFailedException;
use Symfony\Component\Messenger\HandleTrait;
use Symfony\Component\Messenger\MessageBusInterface;
final class MessengerCommandBus implements CommandBusInterface
{
use HandleTrait;
public function __construct(MessageBusInterface $commandBus)
{
$this->messageBus = $commandBus;
}
public function dispatch(CommandInterface $command): mixed
{
try {
return $this->handle($command);
} catch (HandlerFailedException $exception) {
$exceptions = $exception->getNestedExceptions();
throw current($exceptions);
}
}
}