src/EventSubscriber/Store/StoreSubscriber.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber\Store;
  3. use App\Event\LoggerServiceEvent;
  4. use App\Event\Store\StoreEvent;
  5. use App\Service\LoggerHelper;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class StoreSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var LoggerHelper
  12.      */
  13.     private $loggerHelper;
  14.     /**
  15.      * @param LoggerHelper $loggerHelper
  16.      */
  17.     public function __construct(LoggerHelper $loggerHelper)
  18.     {
  19.         $this->loggerHelper $loggerHelper;
  20.     }
  21.     public function onStoreEventSave($event)
  22.     {
  23.         $context array_values($event->getLoggerServiceEntity()[0]);
  24.         $this->loggerHelper->saveMessage(
  25.             'Store',
  26.             ucfirst(array_keys($event->getLoggerServiceEntity()[0])[0]),
  27.             $context[0],
  28.             $event->getLoggerServiceEntity()[1]
  29.         );
  30.     }
  31.     public function onStoreEventAuth($event)
  32.     {
  33.         $context array_values($event->getLoggerServiceEntity()[0]);
  34.         $this->loggerHelper->saveMessage(
  35.             'Store',
  36.             ucfirst(array_keys($event->getLoggerServiceEntity()[0])[0]),
  37.             $context[0],
  38.             $event->getLoggerServiceEntity()[1],
  39.             $event->getUrl()
  40.         );
  41.     }
  42.     public static function getSubscribedEvents(): array
  43.     {
  44.         return [
  45.             StoreEvent::STORE_AUTH => 'onStoreEventAuth',
  46.             StoreEvent::STORE_EVENT => 'onStoreEventSave',
  47.         ];
  48.     }
  49. }