Commit a1f97ea0 authored by Fabien Potencier's avatar Fabien Potencier

merged branch davedevelopment/request-stack (PR #780)

This PR was merged into the master branch.

Discussion
----------

Incorporate new RequestStack

Commits
-------

7fbca3be Switch to single quotes
a2d83aac Use the request stack in the kernel
7f6ca57b Use RequestStack if available
parents 466beac0 7fbca3be
...@@ -23,6 +23,7 @@ use Symfony\Component\HttpKernel\EventListener\RouterListener; ...@@ -23,6 +23,7 @@ use Symfony\Component\HttpKernel\EventListener\RouterListener;
use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpFoundation\StreamedResponse;
...@@ -92,8 +93,8 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte ...@@ -92,8 +93,8 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
$urlMatcher = new LazyUrlMatcher(function () use ($app) { $urlMatcher = new LazyUrlMatcher(function () use ($app) {
return $app['url_matcher']; return $app['url_matcher'];
}); });
$dispatcher->addSubscriber(new RouterListener($urlMatcher, $app['request_context'], $app['logger'])); $dispatcher->addSubscriber(new RouterListener($urlMatcher, $app['request_context'], $app['logger'], $app['request_stack']));
$dispatcher->addSubscriber(new LocaleListener($app, $urlMatcher)); $dispatcher->addSubscriber(new LocaleListener($app, $urlMatcher, $app['request_stack']));
if (isset($app['exception_handler'])) { if (isset($app['exception_handler'])) {
$dispatcher->addSubscriber($app['exception_handler']); $dispatcher->addSubscriber($app['exception_handler']);
} }
...@@ -110,7 +111,15 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte ...@@ -110,7 +111,15 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
}); });
$this['kernel'] = $this->share(function () use ($app) { $this['kernel'] = $this->share(function () use ($app) {
return new HttpKernel($app['dispatcher'], $app['resolver']); return new HttpKernel($app['dispatcher'], $app['resolver'], $app['request_stack']);
});
$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) { $this['request_context'] = $this->share(function () use ($app) {
......
...@@ -13,6 +13,7 @@ namespace Silex\EventListener; ...@@ -13,6 +13,7 @@ namespace Silex\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\EventListener\LocaleListener as BaseLocaleListener; use Symfony\Component\HttpKernel\EventListener\LocaleListener as BaseLocaleListener;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RequestContextAwareInterface; use Symfony\Component\Routing\RequestContextAwareInterface;
use Silex\Application; use Silex\Application;
...@@ -25,9 +26,9 @@ class LocaleListener extends BaseLocaleListener ...@@ -25,9 +26,9 @@ class LocaleListener extends BaseLocaleListener
{ {
protected $app; 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; $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