src/EventSubscriber/ItemUserEventSubscriber.php line 28
<?phpdeclare(strict_types=1);namespace App\EventSubscriber;use ApiPlatform\Core\EventListener\EventPriorities;use App\Entity\Item;use App\Service\ItemUser\ItemUserService;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpKernel\Event\ViewEvent;use Symfony\Component\HttpKernel\KernelEvents;final class ItemUserEventSubscriber implements EventSubscriberInterface{public function __construct(private readonly ItemUserService $itemUserService){}public static function getSubscribedEvents(): array{return [KernelEvents::VIEW => ['createItemUser', EventPriorities::POST_WRITE]];}public function createItemUser(ViewEvent $event): void{$entity = $event->getControllerResult();if (!$entity instanceof Item||$event->getRequest()->getMethod() !== Request::METHOD_POST) {return;}if ('api_items_post_collection' !== $event->getRequest()->get('_route')) {return;}$this->itemUserService->create($entity);}}