src/EventListener/PostDelete/PopupPostDeleteListener.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\EventListener\PostDelete;
  3. use ApiPlatform\Core\EventListener\EventPriorities;
  4. use App\Service\Media\MediaQueueRemover;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpKernel\Event\ViewEvent;
  8. use Symfony\Component\HttpKernel\KernelEvents;
  9. class PopupPostDeleteListener implements EventSubscriberInterface
  10. {
  11.     private $mediaQueueRemover;
  12.     public function __construct(MediaQueueRemover $mediaQueueRemover)
  13.     {
  14.         $this->mediaQueueRemover $mediaQueueRemover;
  15.     }
  16.     public static function getSubscribedEvents()
  17.     {
  18.         return [
  19.             KernelEvents::VIEW => ['postDelete'EventPriorities::POST_WRITE],
  20.         ];
  21.     }
  22.     public function postDelete(ViewEvent $event)
  23.     {
  24.         if ($event->getRequest()->getMethod() !== Request::METHOD_DELETE
  25.             || $event->getRequest()->attributes->get('_route') !== 'api_popups_delete_item') {
  26.             return;
  27.         }
  28.         $this->mediaQueueRemover->removeFromQueue();
  29.     }
  30. }