<?php
namespace App\EventListener\PostDelete;
use ApiPlatform\Core\EventListener\EventPriorities;
use App\Service\Media\MediaQueueRemover;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class PopupPostDeleteListener implements EventSubscriberInterface
{
private $mediaQueueRemover;
public function __construct(MediaQueueRemover $mediaQueueRemover)
{
$this->mediaQueueRemover = $mediaQueueRemover;
}
public static function getSubscribedEvents()
{
return [
KernelEvents::VIEW => ['postDelete', EventPriorities::POST_WRITE],
];
}
public function postDelete(ViewEvent $event)
{
if ($event->getRequest()->getMethod() !== Request::METHOD_DELETE
|| $event->getRequest()->attributes->get('_route') !== 'api_popups_delete_item') {
return;
}
$this->mediaQueueRemover->removeFromQueue();
}
}