<commit_before><?php
/**
 *
 * @author Oakensoul (http://www.oakensoul.com/)
 * @link https://github.com/oakensoul/Cornerstone for the canonical source repository
 * @copyright Copyright (c) 2013 <NAME>.
 * @license http://opensource.org/licenses/BSD-2-Clause BSD-2-Clause
 * @package Cornerstone
 */
namespace Cornerstone\Http\Listener;

use Exception;
use Zend\EventManager\EventManagerInterface;
use Zend\Mvc\MvcEvent;
use Zend\EventManager\AbstractListenerAggregate;
use Zend\Mvc\Router\Http\TreeRouteStack;
use Locale;

class Localization extends AbstractListenerAggregate
{

    /**
     * {@inheritDoc}
     */
    public function attach (EventManagerInterface $events)
    {
        /**
         * add onDispatch event to Dispatcher
         */
        $options = array ();
        $options[] = $this;
        $options[] = 'onDispatch';

        $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, $options, 100);
    }

    public function onDispatch (MvcEvent $pEvent)
    {
        /* @var $match RouteMatch */
        $match = $pEvent->getRouteMatch();

        /* locale selected */
        $lang_selected = $match->getParam('lang');

        $default_language = 'en';

        /**
         * This code basically just makes sure that when we dispatch
         * a route the user is forced to use a localized route if the
         * system is configured to enable the feature
         */
        if (is_null($lang_selected) && true === $match->getParam('force_localized_route', false))
        {<commit_msg>Adding console request check into Localization listener<commit_after><?php
/**
 *
 * @author Oakensoul (http://www.oakensoul.com/)
 * @link https://github.com/oakensoul/Cornerstone for the canonical source repository
 * @copyright Copyright (c) 2013 <NAME>.
 * @license http://opensource.org/licenses/BSD-2-Clause BSD-2-Clause
 * @package Cornerstone
 */
namespace Cornerstone\Http\Listener;

use Exception;
use Zend\EventManager\EventManagerInterface;
use Zend\Mvc\MvcEvent;
use Zend\EventManager\AbstractListenerAggregate;
use Zend\Mvc\Router\Http\TreeRouteStack;
use Locale;
use Zend\Console;

class Localization extends AbstractListenerAggregate
{

    /**
     * {@inheritDoc}
     */
    public function attach (EventManagerInterface $events)
    {
        /**
         * add onDispatch event to Dispatcher
         */
        $options = array ();
        $options[] = $this;
        $options[] = 'onDispatch';

        $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, $options, 100);
    }

    public function onDispatch (MvcEvent $pEvent)
    {
        $request = $pEvent->getRequest();

        // Make sure that we are not running in a console
        if ($request instanceof Console\Request)
        {
            return;
        }

        /* @var $match RouteMatch */
        $match = $pEvent->getRouteMatch();

        /* locale selected */
        $lang_selected = $match->getParam('lang');

        $default_language = 'en';

        /**
         * This code basically just makes sure that when we dispatch
         * a route the user is forced to use a localized route if the
         * system is configured to enable the feature
         */
        if (is_null($lang_selected) && true === $match->getParam('force_localized_route', false))
        {
{'fraction_non_alphanumeric': 0.119903352461492, 'fraction_numerical': 0.005436424041075204, 'mean_word_length': 2.6923076923076925, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 16, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '3222234', 'n_tokens_mistral': 955, 'n_tokens_neox': 926, 'n_words': 247}