<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
class LandingDetectorSubscriber implements EventSubscriberInterface {
public function onKernelRequest(RequestEvent $event) {
$request = $event->getRequest();
$landing = $request->getSession()->get('_landing');
if (empty($landing))
$request->getSession()->set('_landing', $this->getLandingUrl($request));
// NOTE landing could also be stored in cookies so that we keep it across sites. But this would be limited by RGPD consent
}
public function getLandingUrl($request) {
$infos = $request->server->all();
return (isset($infos["HTTPS"]) && $infos["HTTPS"] ? "https" : "http") . "://" . $infos["HTTP_HOST"] . $infos["REQUEST_URI"];
}
public static function getSubscribedEvents() {
return [
'kernel.request' => 'onKernelRequest',
];
}
}