src/EventListener/Workflow/Task/QrCodeUsage/QrCodeUsageUseListener.php line 20

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: takabayashi
  5.  * Date: 2019/09/19
  6.  * Time: 20:48
  7.  */
  8. declare(strict_types=1);
  9. namespace App\EventListener\Workflow\Task\QrCodeUsage;
  10. use App\Entity\QrCodeUsage;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\Workflow\Event\Event;
  13. class QrCodeUsageUseListener implements EventSubscriberInterface
  14. {
  15.     public function onEnteredUsed(Event $event): void
  16.     {
  17.         /** @var QrCodeUsage */
  18.         $qrCodeUsage $event->getSubject();
  19.         if (!$qrCodeUsage instanceof QrCodeUsage) {
  20.             throw new \LogicException('Subject must be '.QrCodeUsage::class);
  21.         }
  22.         $qrCode $qrCodeUsage->getQrCode();
  23.         if (!$qrCode) {
  24.             throw new \LogicException('QrCode must not be null');
  25.         }
  26.         $qrCodeUsage->setUsedAt(new \DateTimeImmutable());
  27.     }
  28.     /**
  29.      * Returns an array of event names this subscriber wants to listen to.
  30.      *
  31.      * The array keys are event names and the value can be:
  32.      *
  33.      *  * The method name to call (priority defaults to 0)
  34.      *  * An array composed of the method name to call and the priority
  35.      *  * An array of arrays composed of the method names to call and respective
  36.      *    priorities, or 0 if unset
  37.      *
  38.      * For instance:
  39.      *
  40.      *  * ['eventName' => 'methodName']
  41.      *  * ['eventName' => ['methodName', $priority]]
  42.      *  * ['eventName' => [['methodName1', $priority], ['methodName2']]]
  43.      *
  44.      * @return array The event names to listen to
  45.      */
  46.     public static function getSubscribedEvents()
  47.     {
  48.         return [
  49.             'workflow.qrcode_usage_states.entered.used' => ['onEnteredUsed'],
  50.         ];
  51.     }
  52. }