vendor/bluue/sales-bundle/src/EventSubscriber/DocumentValidationSubscriber.php line 72

Open in your IDE?
  1. <?php
  2. /**
  3.  * @author Thomas HERISSON (contact@scaledev.fr)
  4.  * @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
  5.  * @license commercial
  6.  */
  7. declare(strict_types=1);
  8. namespace Bluue\SalesBundle\EventSubscriber;
  9. use Bluue\SalesBundle\Event\CreditNoteMovementsEvent;
  10. use Bluue\SalesBundle\Event\InvoiceMovementsEvent;
  11. use Bluue\SalesBundle\Event\OrderMovementsEvent;
  12. use Bluue\SalesBundle\Event\QuotationMovementsEvent;
  13. use Bluue\SalesBundle\Message\DocumentValidationMessage;
  14. use Symfony\Component\Messenger\MessageBusInterface;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class DocumentValidationSubscriber implements EventSubscriberInterface
  17. {
  18.     /**
  19.      * @var MessageBusInterface
  20.      */
  21.     private MessageBusInterface $messageBus;
  22.     /**
  23.      * @param MessageBusInterface $messageBus
  24.      */
  25.     public function __construct(
  26.         MessageBusInterface $messageBus
  27.     ) {
  28.         $this->messageBus $messageBus;
  29.     }
  30.     /**
  31.      * @return string[]
  32.      */
  33.     public static function getSubscribedEvents(): array
  34.     {
  35.         return [
  36.             QuotationMovementsEvent::VALIDATE => 'quotationValidation',
  37.             OrderMovementsEvent::VALIDATE_ORDER => 'orderValidation',
  38.             InvoiceMovementsEvent::VALIDATE => 'invoiceValidation',
  39.             CreditNoteMovementsEvent::VALIDATE => 'creditNoteValidation'
  40.         ];
  41.     }
  42.     /**
  43.      * @param QuotationMovementsEvent $event
  44.      * @return void
  45.      */
  46.     public function quotationValidation(QuotationMovementsEvent $event): void
  47.     {
  48.         $this->dispatchMessage($event->getQuotation());
  49.     }
  50.     /**
  51.      * @param OrderMovementsEvent $event
  52.      * @return void
  53.      */
  54.     public function orderValidation(OrderMovementsEvent $event): void
  55.     {
  56.         $this->dispatchMessage($event->getOrder());
  57.     }
  58.     /**
  59.      * @param InvoiceMovementsEvent $event
  60.      * @return void
  61.      */
  62.     public function invoiceValidation(InvoiceMovementsEvent $event): void
  63.     {
  64.         $this->dispatchMessage($event->getInvoice());
  65.     }
  66.     /**
  67.      * @param CreditNoteMovementsEvent $event
  68.      * @return void
  69.      */
  70.     public function creditNoteValidation(CreditNoteMovementsEvent $event): void
  71.     {
  72.         $this->dispatchMessage($event->getCreditNote());
  73.     }
  74.     /**
  75.      * @param $entity
  76.      * @return void
  77.      */
  78.     private function dispatchMessage($entity): void
  79.     {
  80.         $documentType explode('\\'get_class($entity));
  81.         $this->messageBus->dispatch(
  82.             new DocumentValidationMessage($entity->getId(), array_pop($documentType))
  83.         );
  84.     }
  85. }