src/EventSubscriber/LandingDetectorSubscriber.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\RequestEvent;
  5. class LandingDetectorSubscriber implements EventSubscriberInterface {
  6. public function onKernelRequest(RequestEvent $event) {
  7. $request = $event->getRequest();
  8. $landing = $request->getSession()->get('_landing');
  9. if (empty($landing))
  10. $request->getSession()->set('_landing', $this->getLandingUrl($request));
  11. // NOTE landing could also be stored in cookies so that we keep it across sites. But this would be limited by RGPD consent
  12. }
  13. public function getLandingUrl($request) {
  14. $infos = $request->server->all();
  15. return (isset($infos["HTTPS"]) && $infos["HTTPS"] ? "https" : "http") . "://" . $infos["HTTP_HOST"] . $infos["REQUEST_URI"];
  16. }
  17. public static function getSubscribedEvents() {
  18. return [
  19. 'kernel.request' => 'onKernelRequest',
  20. ];
  21. }
  22. }