Commit 7f6ca57b authored by Dave Marshall's avatar Dave Marshall

Use RequestStack if available

parent 466beac0
......@@ -23,6 +23,7 @@ use Symfony\Component\HttpKernel\EventListener\RouterListener;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\StreamedResponse;
......@@ -92,8 +93,8 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
$urlMatcher = new LazyUrlMatcher(function () use ($app) {
return $app['url_matcher'];
});
$dispatcher->addSubscriber(new RouterListener($urlMatcher, $app['request_context'], $app['logger']));
$dispatcher->addSubscriber(new LocaleListener($app, $urlMatcher));
$dispatcher->addSubscriber(new RouterListener($urlMatcher, $app['request_context'], $app['logger'], $app['request_stack']));
$dispatcher->addSubscriber(new LocaleListener($app, $urlMatcher, $app['request_stack']));
if (isset($app['exception_handler'])) {
$dispatcher->addSubscriber($app['exception_handler']);
}
......@@ -113,6 +114,14 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
return new HttpKernel($app['dispatcher'], $app['resolver']);
});
$this['request_stack'] = $this->share(function () use ($app) {
if (class_exists("Symfony\Component\HttpFoundation\RequestStack")) {
return new RequestStack();
}
return null;
});
$this['request_context'] = $this->share(function () use ($app) {
$context = new RequestContext();
......
......@@ -13,6 +13,7 @@ namespace Silex\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\EventListener\LocaleListener as BaseLocaleListener;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RequestContextAwareInterface;
use Silex\Application;
......@@ -25,9 +26,9 @@ class LocaleListener extends BaseLocaleListener
{
protected $app;
public function __construct(Application $app, RequestContextAwareInterface $router = null)
public function __construct(Application $app, RequestContextAwareInterface $router = null, RequestStack $requestStack = null)
{
parent::__construct($app['locale'], $router);
parent::__construct($app['locale'], $router, $requestStack);
$this->app = $app;
}
......
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