<?php
/**
 * LandingInfo KernelEvent Listener
 *
 * Registers LandingPage information
 *
 * @author Elze Kool <info@visualmedia.nl>
 */

namespace VisualM\FormBundle\Event;

use Symfony\Component\HttpKernel\Event\GetResponseEvent;


/**
 * LandingInfo KernelEvent Listener
 *
 * Registers LandingPage information
 *
 * @author Elze Kool <info@visualmedia.nl>
 */
class LandingInfoEventListener
{
    /**
     * {@inheritdoc}
     */
    public function onKernelRequest(GetResponseEvent $event)
    {
        // Only handle master requests
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();
        $session = $request->getSession();

        if (!$session->has('userinfo.landing_page')) {
            $session->set('userinfo.landing_page', $request->getSchemeAndHttpHost() . $request->getRequestUri());
            $session->set('userinfo.landing_time', time());
            $session->set('userinfo.landing_referer', $request->headers->get('referer'));
        }

    }

}