<?php
/**
* This file is part of the CosaVostra, TrackPay, Symfony package.
*
* (c) Mohamed Radhi GUENNICHI <rg@mate.tn> <+216 50 711 816>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace App\EventSubscriber\Procedure;
use App\Event\ProcedureDispatchEvent;
use App\Events;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ProcedureProcessingSubscriber implements EventSubscriberInterface
{
/**
* @var EntityManagerInterface
*/
protected $entityManager;
/**
* ProcedureProcessingSubscriber constructor.
*
* @param EntityManagerInterface $entityManager
*/
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
/**
* @param ProcedureDispatchEvent $event
*/
public function onProcedureBeforeDispatch(ProcedureDispatchEvent $event): void
{
$event
->getProcedure()
->setProcessing(true);
$this->entityManager->flush();
}
/**
* @param ProcedureDispatchEvent $event
*/
public function onProcedureAfterDispatch(ProcedureDispatchEvent $event): void
{
$event
->getProcedure()
->setProcessing(false);
$this->entityManager->flush();
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents()
{
return [
Events::PROCEDURE_ON_DISPATCH => [
['onProcedureBeforeDispatch', 10]
],
Events::PROCEDURE_AFTER_DISPATCH => [
['onProcedureAfterDispatch', 10]
]
];
}
}