src/Aqarmap/Bundle/ListingBundle/EventListener/SoftDeleteEventSubscriber.php line 21

Open in your IDE?
  1. <?php
  2. namespace Aqarmap\Bundle\ListingBundle\EventListener;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  5. /**
  6.  * SoftDeleteListener.
  7.  */
  8. class SoftDeleteEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
  9. {
  10.     /** @var EntityManagerInterface */
  11.     protected $em;
  12.     public function __construct(EntityManagerInterface $em)
  13.     {
  14.         $this->em $em;
  15.     }
  16.     public function onKernelController(ControllerEvent $event): void
  17.     {
  18.         // preg_match should store the name of the bundle at the second index of the array
  19.         $softdeletableRoutes = [
  20.             'listing_slug',
  21.             'listing_view',
  22.             'listing_undelete',
  23.             'aqarmap_api_undelete_listing',
  24.             'admin_listing_choose_rejections',
  25.             'aqarmap_admin_listing_pending',
  26.             'listing_review',
  27.             'aqarmap_listing_relist',
  28.             'admin_listing_delete',
  29.             'neighborhood_discussion_comments',
  30.         ];
  31.         if (\in_array($event->getRequest()->attributes->get('_route'), $softdeletableRoutes)) {
  32.             $controller $event->getController();
  33.             $em $this->em;
  34.             if ($em->getFilters()->isEnabled('softdeleteable')) {
  35.                 $em->getFilters()->disable('softdeleteable');
  36.             }
  37.         }
  38.     }
  39.     /**
  40.      * @return array<string, mixed>
  41.      */
  42.     public static function getSubscribedEvents(): array
  43.     {
  44.         return [\Symfony\Component\HttpKernel\KernelEvents::CONTROLLER => 'onKernelController'];
  45.     }
  46. }