Commit 3108bfa1 authored by Fabien Potencier's avatar Fabien Potencier

moved the locale management to its own event listener

That's ensure that the locale is managed in only one place and always at
the right time.
parent ca79d330
......@@ -20,7 +20,6 @@ use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\EventListener\LocaleListener;
use Symfony\Component\HttpKernel\EventListener\ResponseListener;
use Symfony\Component\HttpKernel\EventListener\RouterListener;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
......@@ -37,6 +36,7 @@ use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RequestContext;
use Silex\RedirectableUrlMatcher;
use Silex\ControllerResolver;
use Silex\EventListener\LocaleListener;
/**
* The Silex framework class.
......@@ -96,7 +96,7 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
return $app['url_matcher'];
});
$dispatcher->addSubscriber(new RouterListener($urlMatcher, $app['request_context'], $app['logger']));
$dispatcher->addSubscriber(new LocaleListener($app['locale'], $urlMatcher));
$dispatcher->addSubscriber(new LocaleListener($app, $urlMatcher));
if (isset($app['exception_handler'])) {
$dispatcher->addSubscriber($app['exception_handler']);
}
......@@ -539,8 +539,6 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
*/
public function onKernelRequest(GetResponseEvent $event)
{
$this['locale'] = $event->getRequest()->getLocale();
$this['route_before_middlewares_trigger']($event);
}
......
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\EventListener\LocaleListener as BaseLocaleListener;
use Symfony\Component\Routing\RequestContextAwareInterface;
use Silex\Application;
/**
* Initializes the locale based on the current request.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class LocaleListener extends BaseLocaleListener
{
protected $app;
public function __construct(Application $app, RequestContextAwareInterface $router = null)
{
parent::__construct($app['locale'], $router);
$this->app = $app;
}
public function onKernelRequest(GetResponseEvent $event)
{
parent::onKernelRequest($event);
$this->app['locale'] = $event->getRequest()->getLocale();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment