vendor/crehler/inspirations/src/Subscriber/ProductDeleteSubscriber.php line 42

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  * @copyright 2020 Crehler Sp. z o. o. <https://crehler.com>
  4.  *
  5.  * @author    Jakub MedyƄski <jme@crehler.com>
  6.  * @support   Crehler <support@crehler.com>
  7.  * @created   25 wrz 2020
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Crehler\Inspirations\Subscriber;
  13. use Crehler\Inspirations\Message\DeleteInspirationProductMessage;
  14. use Crehler\MojeBambinoEngine\Service\CrehlerContextService;
  15. use Enqueue\MessengerAdapter\EnvelopeItem\TransportConfiguration;
  16. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  17. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  18. use Symfony\Component\HttpKernel\KernelEvents;
  19. use Symfony\Component\Messenger\MessageBusInterface;
  20. class ProductDeleteSubscriber implements EventSubscriberInterface
  21. {
  22.     private MessageBusInterface $messageBus;
  23.     private CrehlerContextService $crehlerContext;
  24.     public function __construct(MessageBusInterface $messageBusCrehlerContextService $crehlerContext)
  25.     {
  26.         $this->messageBus $messageBus;
  27.         $this->crehlerContext $crehlerContext;
  28.     }
  29.     public static function getSubscribedEvents(): array
  30.     {
  31.         return [
  32.             KernelEvents::RESPONSE => 'onKernelResponse',
  33.         ];
  34.     }
  35.     public function onKernelResponse(ResponseEvent $event)
  36.     {
  37.         $uri $event->getRequest()->getRequestUri();
  38.         $method $event->getRequest()->getMethod();
  39.         if('DELETE' == $method)
  40.         {
  41.             $uri explode("/"$uri);
  42.             if (in_array('api'$uri) && in_array('inspiration'$uri) && in_array('inspiration-products'$uri))
  43.             {
  44.                 $inspiration $uri[4];
  45.                 $context $event->getRequest()->attributes->get('sw-context');
  46.                 $message = new DeleteInspirationProductMessage();
  47.                 $message->withContext($context);
  48.                 $message->setInspirationId($inspiration);
  49.                 $this->messageBus->dispatch($message, [new TransportConfiguration(['topic' => 'crehlerinspirations'])]);
  50.             }
  51.         }
  52.     }
  53. }