<?php
namespace App\EventSubscriber\Order;
use App\Service\LoggerHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class OrderSubscriber implements EventSubscriberInterface
{
/**
* @var LoggerHelper
*/
private $loggerHelper;
/**
* @param LoggerHelper $loggerHelper
*/
public function __construct(LoggerHelper $loggerHelper)
{
$this->loggerHelper = $loggerHelper;
}
public function onOrderEvent($event)
{
$context = array_values($event->getLoggerServiceEntity()[0]);
$this->loggerHelper->saveMessage(
'Order',
ucfirst(array_keys($event->getLoggerServiceEntity()[0])[0]),
$context[0],
$event->getLoggerServiceEntity()[1],
$event->getUrl()
);
}
public function onOrderResponse($event)
{
$context = array_values($event->getLoggerServiceEntity()[0]);
$this->loggerHelper->saveMessage(
'Order',
ucfirst(array_keys($event->getLoggerServiceEntity()[0])[0]),
$context[0],
$event->getLoggerServiceEntity()[1],
$event->getUrl()
);
}
public static function getSubscribedEvents(): array
{
return [
'order.event' => 'onOrderEvent',
'order.response' => 'onOrderResponse',
];
}
}