<?php
namespace App\EventSubscriber\Store;
use App\Event\LoggerServiceEvent;
use App\Event\Store\StoreEvent;
use App\Service\LoggerHelper;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class StoreSubscriber implements EventSubscriberInterface
{
/**
* @var LoggerHelper
*/
private $loggerHelper;
/**
* @param LoggerHelper $loggerHelper
*/
public function __construct(LoggerHelper $loggerHelper)
{
$this->loggerHelper = $loggerHelper;
}
public function onStoreEventSave($event)
{
$context = array_values($event->getLoggerServiceEntity()[0]);
$this->loggerHelper->saveMessage(
'Store',
ucfirst(array_keys($event->getLoggerServiceEntity()[0])[0]),
$context[0],
$event->getLoggerServiceEntity()[1]
);
}
public function onStoreEventAuth($event)
{
$context = array_values($event->getLoggerServiceEntity()[0]);
$this->loggerHelper->saveMessage(
'Store',
ucfirst(array_keys($event->getLoggerServiceEntity()[0])[0]),
$context[0],
$event->getLoggerServiceEntity()[1],
$event->getUrl()
);
}
public static function getSubscribedEvents(): array
{
return [
StoreEvent::STORE_AUTH => 'onStoreEventAuth',
StoreEvent::STORE_EVENT => 'onStoreEventSave',
];
}
}