<commit_before><?php
/**
 * This file is part of the PositibeLabs Projects.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Positibe\Bundle\CmfBundle\EventListener;

use Lunetics\LocaleBundle\Event\FilterLocaleSwitchEvent;
use Lunetics\LocaleBundle\EventListener\LocaleListener as LuneticsLocaleListener;
use Lunetics\LocaleBundle\LocaleBundleEvents;
use Lunetics\LocaleBundle\LocaleGuesser\LocaleGuesserManager;
use Lunetics\LocaleBundle\Matcher\BestLocaleMatcher;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;


/**
 * Class LocaleMatcherListener
 * @package Positibe\Bundle\CmfBundle\EventListener
 *
 * @author <NAME> <<EMAIL>>
 */
class LocaleMatcherListener extends LuneticsLocaleListener {
    /**
     * @var string Default framework locale
     */
    private $defaultLocale;

    /**
     * @var LocaleGuesserManager
     */
    private $guesserManager;

    /**
     * @var BestLocaleMatcher
     */
    private $bestLocaleMatcher;

    /**
     * @var EventDispatcher
     */
    private $dispatcher;

    /**
     * @var boolean
     */
    private $disableVaryHeader = false;

    /**
     * @var string
     */
    private $excludedPattern;

    /**
     * Construct the guessermanager
     *
     * @param string $defaultLocale
     * @param LocaleGuesserManager $guesserManager
     * @param BestLocaleMatcher $bestLocaleMatcher
     */
    public function __construct($defaultLocale = 'en', LocaleGuesserManager $guesserManager, BestLocaleMatcher $bestLocaleMatcher = null)
    {
        $this->defaultLocale = $defaultLocale;
        $this->guesserManager = $guesserManager;
        $this->bestLocaleMatcher = $bestLocaleMatcher;
    }

    /**
     * Called at the "kernel.request" event
     *
     * Call the LocaleGuesserManager to guess the locale
     * by the activated guessers
     *
     * Sets the identified locale as default locale to the request
     *
     * @param GetResponseEvent $event
     */
    public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        $request->setDefaultLocale($this->defaultLocale);

        if ($this->excludedPattern && preg_match(sprintf('#%s#', $this->excludedPattern), $request->server->get('PATH_INFO'))) {<commit_msg>only run on Master Request<commit_after><?php
/**
 * This file is part of the PositibeLabs Projects.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Positibe\Bundle\CmfBundle\EventListener;

use Lunetics\LocaleBundle\Event\FilterLocaleSwitchEvent;
use Lunetics\LocaleBundle\EventListener\LocaleListener as LuneticsLocaleListener;
use Lunetics\LocaleBundle\LocaleBundleEvents;
use Lunetics\LocaleBundle\LocaleGuesser\LocaleGuesserManager;
use Lunetics\LocaleBundle\Matcher\BestLocaleMatcher;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;


/**
 * Class LocaleMatcherListener
 * @package Positibe\Bundle\CmfBundle\EventListener
 *
 * @author <NAME> <<EMAIL>>
 */
class LocaleMatcherListener extends LuneticsLocaleListener {
    /**
     * @var string Default framework locale
     */
    private $defaultLocale;

    /**
     * @var LocaleGuesserManager
     */
    private $guesserManager;

    /**
     * @var BestLocaleMatcher
     */
    private $bestLocaleMatcher;

    /**
     * @var EventDispatcher
     */
    private $dispatcher;

    /**
     * @var boolean
     */
    private $disableVaryHeader = false;

    /**
     * @var string
     */
    private $excludedPattern;

    /**
     * Construct the guessermanager
     *
     * @param string $defaultLocale
     * @param LocaleGuesserManager $guesserManager
     * @param BestLocaleMatcher $bestLocaleMatcher
     */
    public function __construct($defaultLocale = 'en', LocaleGuesserManager $guesserManager, BestLocaleMatcher $bestLocaleMatcher = null)
    {
        $this->defaultLocale = $defaultLocale;
        $this->guesserManager = $guesserManager;
        $this->bestLocaleMatcher = $bestLocaleMatcher;
    }

    /**
     * Called at the "kernel.request" event
     *
     * Call the LocaleGuesserManager to guess the locale
     * by the activated guessers
     *
     * Sets the identified locale as default locale to the request
     *
     * @param GetResponseEvent $event
     */
    public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        $request->setDefaultLocale($this->defaultLocale);

        if (!$event->isMasterRequest() || ($this->excludedPattern && preg_match(sprintf('#%s#', $this->excludedPattern), $request->server->get('PATH_INFO')))) {
{'fraction_non_alphanumeric': 0.1023725014010835, 'fraction_numerical': 0.0, 'mean_word_length': 3.5760683760683762, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 36, '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': '4426113', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1469, 'n_words': 333}