<?php
namespace RewardPointPlugin\Listener;
use AppBundle\Listener\AbstractSecurityDisabledListener;
use RewardPointPlugin\Component\Decorator\RewardPointResponseDecorator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
class RewardPointNotifyListener extends AbstractSecurityDisabledListener
{
/**
* @var RewardPointResponseDecorator
*/
private $rewardPointResponseDecorator;
public function __construct(RewardPointResponseDecorator $rewardPointResponseDecorator)
{
$this->rewardPointResponseDecorator = $rewardPointResponseDecorator;
}
public function onKernelResponse(ResponseEvent $event)
{
if ($event->getRequestType() != HttpKernelInterface::MAIN_REQUEST) {
return;
}
$request = $event->getRequest();
$saveNotifyToHeader = $request->isXmlHttpRequest() || 0 === strpos($request->getPathInfo(), '/mapi_v2') || 0 === strpos($request->getPathInfo(), '/api_v3');
$this->rewardPointResponseDecorator->decorate($event->getResponse(), $saveNotifyToHeader);
}
}