vendor/symfony/workflow/EventListener/AuditTrailListener.php line 43

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <[email protected]>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Workflow\EventListener;
  11. use Psr\Log\LoggerInterface;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\Workflow\Event\Event;
  14. /**
  15.  * @author GrĂ©goire Pineau <[email protected]>
  16.  */
  17. class AuditTrailListener implements EventSubscriberInterface
  18. {
  19.     private LoggerInterface $logger;
  20.     public function __construct(LoggerInterface $logger)
  21.     {
  22.         $this->logger $logger;
  23.     }
  24.     /**
  25.      * @return void
  26.      */
  27.     public function onLeave(Event $event)
  28.     {
  29.         foreach ($event->getTransition()->getFroms() as $place) {
  30.             $this->logger->info(sprintf('Leaving "%s" for subject of class "%s" in workflow "%s".'$place$event->getSubject()::class, $event->getWorkflowName()));
  31.         }
  32.     }
  33.     /**
  34.      * @return void
  35.      */
  36.     public function onTransition(Event $event)
  37.     {
  38.         $this->logger->info(sprintf('Transition "%s" for subject of class "%s" in workflow "%s".'$event->getTransition()->getName(), $event->getSubject()::class, $event->getWorkflowName()));
  39.     }
  40.     /**
  41.      * @return void
  42.      */
  43.     public function onEnter(Event $event)
  44.     {
  45.         foreach ($event->getTransition()->getTos() as $place) {
  46.             $this->logger->info(sprintf('Entering "%s" for subject of class "%s" in workflow "%s".'$place$event->getSubject()::class, $event->getWorkflowName()));
  47.         }
  48.     }
  49.     public static function getSubscribedEvents(): array
  50.     {
  51.         return [
  52.             'workflow.leave' => ['onLeave'],
  53.             'workflow.transition' => ['onTransition'],
  54.             'workflow.enter' => ['onEnter'],
  55.         ];
  56.     }
  57. }