src/EventSubscriber/ItemUserDeleteEventSubscriber.php line 32
<?phpdeclare(strict_types=1);namespace App\EventSubscriber;use ApiPlatform\Core\EventListener\EventPriorities;use App\Entity\ItemUser;use App\Service\ItemUser\ItemUserService;use Doctrine\DBAL\Exception;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpKernel\Event\ViewEvent;use Symfony\Component\HttpKernel\KernelEvents;final class ItemUserDeleteEventSubscriber implements EventSubscriberInterface{public function __construct(private readonly ItemUserService $itemUserService){}public static function getSubscribedEvents(): array{return [KernelEvents::VIEW => ['removeFromChildren', EventPriorities::PRE_WRITE]];}/*** @throws Exception*/public function removeFromChildren(ViewEvent $event): void{$entity = $event->getControllerResult();if (!$entity instanceof ItemUser||$event->getRequest()->getMethod() !== Request::METHOD_DELETE) {return;}$this->itemUserService->remove($entity);}}