<commit_before><?php

namespace BaseBundle\EventListener;

use BaseBundle\Services\RoutingHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;

class LastRouteListener implements EventSubscriberInterface
{
    protected $routingHelper;

    public function __construct(RoutingHelper $routingHelper)
    {
        $this->routingHelper = $routingHelper;
    }

    public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        if (!$request->hasPreviousSession()) {
            return;
        }

        try {
            $currentRoute = $this->routingHelper->getCurrentRoute($request);
        } catch (ResourceNotFoundException $ex) {
            return;
        }
        if (is_null($currentRoute)) {
            return;
        }

        $session = $request->getSession();
        $previousRoute = $session->get('current_route', array());
        if ($currentRoute == $previousRoute) {
            return;
        }

        $session->set('previous_route', $previousRoute);
        $session->set('current_route', $currentRoute);
    }

    public static function getSubscribedEvents()
    {
        return array(<commit_msg>keep query string when storing the last route<commit_after><?php

namespace BaseBundle\EventListener;

use BaseBundle\Services\RoutingHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;

class LastRouteListener implements EventSubscriberInterface
{
    protected $routingHelper;

    public function __construct(RoutingHelper $routingHelper)
    {
        $this->routingHelper = $routingHelper;
    }

    public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        if (!$request->hasPreviousSession()) {
            return;
        }

        try {
            $currentRoute = $this->routingHelper->getCurrentRoute($request);
        } catch (ResourceNotFoundException $ex) {
            return;
        }
        if (is_null($currentRoute)) {
            return;
        }

        // Keep query string
        $currentRoute['params'] = array_merge($request->query->all(), $currentRoute['params']);

        $session = $request->getSession();
        $previousRoute = $session->get('current_route', array());
        if ($currentRoute == $previousRoute) {
            return;
        }

        $session->set('previous_route', $previousRoute);
        $session->set('current_route', $currentRoute);
    }

    public static function getSubscribedEvents()
    {
        return array(
{'fraction_non_alphanumeric': 0.10980662983425414, 'fraction_numerical': 0.0, 'mean_word_length': 3.0069156293222683, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4734104', 'n_tokens_mistral': 737, 'n_tokens_neox': 741, 'n_words': 138}