src/EventListener/GoodWorkflowListener.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Service\Bus\Publisher\ProductPublisher;
  4. use Symfony\Component\Workflow\Event\TransitionEvent;
  5. class GoodWorkflowListener
  6. {
  7.     private ProductPublisher $goodsPublisher;
  8.     public function __construct(ProductPublisher $goodsPublisher)
  9.     {
  10.         $this->goodsPublisher $goodsPublisher;
  11.     }
  12.     public function onTransition(TransitionEvent $ev)
  13.     {
  14.         $method $ev->getTransition()->getName();
  15.         if (method_exists($this$method)) {
  16.             $this->$method($ev);
  17.         } else {
  18.             // Log
  19.         }
  20.     }
  21.     // transitions handle
  22.     private function initToMedia(TransitionEvent $ev)
  23.     {
  24.         return true;
  25.     }
  26.     //При публикации продукта отправляем его в шину формируя релиз для фронтов
  27.     /**
  28.      * @throws \Exception
  29.      */
  30.     private function moderationToPublished(TransitionEvent $ev): void
  31.     {
  32.         $this->goodsPublisher->create($ev->getSubject());
  33.     }
  34. }