<?php
namespace Aqarmap\Bundle\ListingBundle\EventListener;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
/**
* SoftDeleteListener.
*/
class SoftDeleteEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
{
/** @var EntityManagerInterface */
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function onKernelController(ControllerEvent $event): void
{
// preg_match should store the name of the bundle at the second index of the array
$softdeletableRoutes = [
'listing_slug',
'listing_view',
'listing_undelete',
'aqarmap_api_undelete_listing',
'admin_listing_choose_rejections',
'aqarmap_admin_listing_pending',
'listing_review',
'aqarmap_listing_relist',
'admin_listing_delete',
'neighborhood_discussion_comments',
];
if (\in_array($event->getRequest()->attributes->get('_route'), $softdeletableRoutes)) {
$controller = $event->getController();
$em = $this->em;
if ($em->getFilters()->isEnabled('softdeleteable')) {
$em->getFilters()->disable('softdeleteable');
}
}
}
/**
* @return array<string, mixed>
*/
public static function getSubscribedEvents(): array
{
return [\Symfony\Component\HttpKernel\KernelEvents::CONTROLLER => 'onKernelController'];
}
}