src/EventSubscriber/Procedure/ProcedureProcessingSubscriber.php line 52

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of the CosaVostra, TrackPay, Symfony package.
  4.  *
  5.  * (c) Mohamed Radhi GUENNICHI <rg@mate.tn> <+216 50 711 816>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace App\EventSubscriber\Procedure;
  12. use App\Event\ProcedureDispatchEvent;
  13. use App\Events;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class ProcedureProcessingSubscriber implements EventSubscriberInterface
  17. {
  18.     /**
  19.      * @var EntityManagerInterface
  20.      */
  21.     protected $entityManager;
  22.     /**
  23.      * ProcedureProcessingSubscriber constructor.
  24.      *
  25.      * @param EntityManagerInterface $entityManager
  26.      */
  27.     public function __construct(EntityManagerInterface $entityManager)
  28.     {
  29.         $this->entityManager $entityManager;
  30.     }
  31.     /**
  32.      * @param ProcedureDispatchEvent $event
  33.      */
  34.     public function onProcedureBeforeDispatch(ProcedureDispatchEvent $event): void
  35.     {
  36.         $event
  37.             ->getProcedure()
  38.             ->setProcessing(true);
  39.         $this->entityManager->flush();
  40.     }
  41.     /**
  42.      * @param ProcedureDispatchEvent $event
  43.      */
  44.     public function onProcedureAfterDispatch(ProcedureDispatchEvent $event): void
  45.     {
  46.         $event
  47.             ->getProcedure()
  48.             ->setProcessing(false);
  49.         $this->entityManager->flush();
  50.     }
  51.     /**
  52.      * @inheritDoc
  53.      */
  54.     public static function getSubscribedEvents()
  55.     {
  56.         return [
  57.             Events::PROCEDURE_ON_DISPATCH => [
  58.                 ['onProcedureBeforeDispatch'10]
  59.             ],
  60.             Events::PROCEDURE_AFTER_DISPATCH => [
  61.                 ['onProcedureAfterDispatch'10]
  62.             ]
  63.         ];
  64.     }
  65. }