<?php
namespace Aviatur\GeneralBundle\EventListener;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
class ResponseListener
{
private \Symfony\Component\HttpFoundation\Session\SessionInterface $session;
public function __construct(SessionInterface $session)
{
$this->session = $session;
}
public function onKernelResponse(ResponseEvent $event)
{
$request = $event->getRequest();
$response = $event->getResponse();
if ('viajala.com.co' === $request->getHost() || 'www.viajala.com.co' === $request->getHost()) {
$response->headers->set('x-frame-options', 'ALLOW-FROM https://'.$request->getHost().'/');
} elseif (true !== $this->session->has('whitemark') && true !== $this->session->has('onlySearcherSite')) {
$response->headers->set('x-frame-options', 'deny');
}
if ($this->session->has('typeCoin') && $this->session->has('typeCountry')) {
if (!$request->cookies->has('_world_pay') ||
json_decode(base64_decode($request->cookies->get('_world_pay')), true)['typeCoin'] != $this->session->get('typeCoin')
) {
$response->headers->setCookie(new Cookie('_world_pay', base64_encode(json_encode([
'typeCoin' => $this->session->get('typeCoin'),
'typeCountry' => $this->session->get('typeCountry'),
'CoinValue' => $this->session->get('CoinValue'),
])), (time() + 3600 * 24 * 7), '/'));
}
}
$event->setResponse($response);
}
}