src/EventSubscriber/InventorySubscriber.php line 43
<?phpnamespace App\EventSubscriber;use App\Entity\Inventory;use App\EventSubscriber\Traits\InventorySubscriberHandlerTrait;use App\Repository\InventoryRepository;use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeCrudActionEvent;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpFoundation\RequestStack;class InventorySubscriber implements EventSubscriberInterface{use InventorySubscriberHandlerTrait;/*** @param InventoryRepository $inventoryRepository* @param RequestStack $requestStack*/public function __construct(protected readonly InventoryRepository $inventoryRepository,protected readonly RequestStack $requestStack){}/*** @return array*/public static function getSubscribedEvents(): array{return [BeforeCrudActionEvent::class => ['beforeCrudAction'],AfterEntityUpdatedEvent::class => ['afterEntityUpdatedEvent'],];}/*** @param BeforeCrudActionEvent $event* @return void*/public function beforeCrudAction(BeforeCrudActionEvent $event): void{if (!$event->getAdminContext()->getRequest()->isMethod('POST')) {return;}$entity = $event->getAdminContext()->getEntity()->getInstance();if ($entity instanceof Inventory) {$this->processQtyBeforeUpdate($event, $entity);}}/*** @param AfterEntityUpdatedEvent $event* @return void*/public function afterEntityUpdatedEvent(AfterEntityUpdatedEvent $event): void{$entity = $event->getEntityInstance();if ($entity instanceof Inventory) {$this->processQtyAfterUpdate($entity);}}}