src/Infrastructure/Shared/Bus/Command/MessengerCommandBus.php line 23

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Infrastructure\Shared\Bus\Command;
  4. use Symfony\Component\Messenger\Exception\HandlerFailedException;
  5. use Symfony\Component\Messenger\HandleTrait;
  6. use Symfony\Component\Messenger\MessageBusInterface;
  7. final class MessengerCommandBus implements CommandBusInterface
  8. {
  9.     use HandleTrait;
  10.     public function __construct(MessageBusInterface $commandBus)
  11.     {
  12.         $this->messageBus $commandBus;
  13.     }
  14.     public function dispatch(CommandInterface $command): mixed
  15.     {
  16.         try {
  17.             return $this->handle($command);
  18.         } catch (HandlerFailedException $exception) {
  19.             $exceptions $exception->getNestedExceptions();
  20.             throw current($exceptions);
  21.         }
  22.     }
  23. }