<?php
namespace App\EventSubscriber\Article;
use App\Event\Article\ArticlePumpUpdateEvent;
use App\Service\Articles\ArticlePumpService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ArticleSubscriber implements EventSubscriberInterface
{
private $em;
private ArticlePumpService $articlePumpService;
public function __construct(EntityManagerInterface $em, ArticlePumpService $articlePumpService)
{
$this->em = $em;
$this->articlePumpService = $articlePumpService;
}
public static function getSubscribedEvents()
{
return [
ArticlePumpUpdateEvent::class => ['onUpdatePumpArticle', 100],
];
}
public function onUpdatePumpArticle(ArticlePumpUpdateEvent $event)
{
$article = $event->getArticle();
$this->em->refresh($article);
$this->articlePumpService->majArticlePump($article, $event->getOutput(), $event->getMouvementStock());
}
}