elements');
$this->assertEquals('foo', (string) $aliases['alias_for_foo'], '->load() parses aliases');
diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php
index e655d3bd8981a..1c700df7b5b9d 100644
--- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php
+++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php
@@ -128,6 +128,9 @@ public function testLoadServices()
$this->assertEquals(array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), $services['method_call2']->getMethodCalls(), '->load() parses the method_call tag');
$this->assertEquals('baz_factory', $services['factory_service']->getFactoryService());
+ $this->assertTrue($services['request']->isSynthetic(), '->load() parses the synthetic flag');
+ $this->assertTrue($services['request']->isSynchronized(), '->load() parses the synchronized flag');
+
$aliases = $container->getAliases();
$this->assertTrue(isset($aliases['alias_for_foo']), '->load() parses aliases');
$this->assertEquals('foo', (string) $aliases['alias_for_foo'], '->load() parses aliases');
diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php b/src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php
index 20b4a5e75e9ad..0aae26b483504 100644
--- a/src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php
+++ b/src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php
@@ -56,11 +56,13 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
try {
$response = parent::handle($request, $type, $catch);
} catch (\Exception $e) {
+ $this->container->set('request', null, 'request');
$this->container->leaveScope('request');
throw $e;
}
+ $this->container->set('request', null, 'request');
$this->container->leaveScope('request');
return $response;
diff --git a/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php b/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php
index f3cb804832660..0b864c02f2bc4 100644
--- a/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php
+++ b/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php
@@ -12,7 +12,6 @@
namespace Symfony\Component\HttpKernel\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
-use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RequestContextAwareInterface;
@@ -27,7 +26,6 @@ class LocaleListener implements EventSubscriberInterface
{
private $router;
private $defaultLocale;
- private $locales = array();
public function __construct($defaultLocale = 'en', RequestContextAwareInterface $router = null)
{
@@ -35,24 +33,27 @@ public function __construct($defaultLocale = 'en', RequestContextAwareInterface
$this->router = $router;
}
- public function onKernelResponse(FilterResponseEvent $event)
+ public function setRequest(Request $request = null)
{
- array_shift($this->locales);
+ if (null === $request) {
+ return;
+ }
- // setting back the locale to the previous value
- $locale = isset($this->locales[0]) ? $this->locales[0] : $this->defaultLocale;
- $request = $event->getRequest();
- $this->setLocale($request, $locale);
+ if ($locale = $request->attributes->get('_locale')) {
+ $request->setLocale($locale);
+ }
+
+ if (null !== $this->router) {
+ $this->router->getContext()->setParameter('_locale', $request->getLocale());
+ }
}
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
-
$request->setDefaultLocale($this->defaultLocale);
- $this->setLocale($request, $request->attributes->get('_locale', $this->defaultLocale));
- array_unshift($this->locales, $request->getLocale());
+ $this->setRequest($request);
}
public static function getSubscribedEvents()
@@ -60,16 +61,6 @@ public static function getSubscribedEvents()
return array(
// must be registered after the Router to have access to the _locale
KernelEvents::REQUEST => array(array('onKernelRequest', 16)),
- KernelEvents::RESPONSE => 'onKernelResponse',
);
}
-
- private function setLocale(Request $request, $locale)
- {
- $request->setLocale($locale);
-
- if (null !== $this->router) {
- $this->router->getContext()->setParameter('_locale', $request->getLocale());
- }
- }
}
diff --git a/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php b/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php
index 606b358e72f04..58ea6f0a5436d 100644
--- a/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php
+++ b/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php
@@ -23,6 +23,7 @@
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RequestContextAwareInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+use Symfony\Component\HttpFoundation\Request;
/**
* Initializes the context from the request and sets request attributes based on a matching route.
@@ -59,12 +60,31 @@ public function __construct($matcher, RequestContext $context = null, LoggerInte
$this->logger = $logger;
}
+ /**
+ * Sets the current Request.
+ *
+ * The application should call this method whenever the Request
+ * object changes (entering a Request scope for instance, but
+ * also when leaving a Request scope -- especially when they are
+ * nested).
+ *
+ * @param Request|null $request A Request instance
+ */
+ public function setRequest(Request $request = null)
+ {
+ if (null !== $request) {
+ $this->context->fromRequest($request);
+ }
+ }
+
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
// initialize the context that is also used by the generator (assuming matcher and generator share the same context instance)
- $this->context->fromRequest($request);
+ // we call setRequest even if most of the time, it has already been done to keep compatibility
+ // with frameworks which do not use the Symfony service container
+ $this->setRequest($request);
if ($request->attributes->has('_controller')) {
// routing is already done
diff --git a/src/Symfony/Component/HttpKernel/Fragment/FragmentHandler.php b/src/Symfony/Component/HttpKernel/Fragment/FragmentHandler.php
index b4f3f9c1eef47..54d0a70b7dbec 100644
--- a/src/Symfony/Component/HttpKernel/Fragment/FragmentHandler.php
+++ b/src/Symfony/Component/HttpKernel/Fragment/FragmentHandler.php
@@ -15,10 +15,6 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
-use Symfony\Component\HttpKernel\KernelEvents;
-use Symfony\Component\HttpKernel\Event\GetResponseEvent;
-use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
-use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Renders a URI that represents a resource fragment.
@@ -30,11 +26,11 @@
*
* @see FragmentRendererInterface
*/
-class FragmentHandler implements EventSubscriberInterface
+class FragmentHandler
{
private $debug;
private $renderers;
- private $requests;
+ private $request;
/**
* Constructor.
@@ -49,7 +45,6 @@ public function __construct(array $renderers = array(), $debug = false)
$this->addRenderer($renderer);
}
$this->debug = $debug;
- $this->requests = array();
}
/**
@@ -63,23 +58,13 @@ public function addRenderer(FragmentRendererInterface $renderer)
}
/**
- * Stores the Request object.
+ * Sets the current Request.
*
- * @param GetResponseEvent $event A GetResponseEvent instance
+ * @param Request $request The current Request
*/
- public function onKernelRequest(GetResponseEvent $event)
+ public function setRequest(Request $request = null)
{
- array_unshift($this->requests, $event->getRequest());
- }
-
- /**
- * Removes the most recent Request object.
- *
- * @param FilterResponseEvent $event A FilterResponseEvent instance
- */
- public function onKernelResponse(FilterResponseEvent $event)
- {
- array_shift($this->requests);
+ $this->request = $request;
}
/**
@@ -108,7 +93,11 @@ public function render($uri, $renderer = 'inline', array $options = array())
throw new \InvalidArgumentException(sprintf('The "%s" renderer does not exist.', $renderer));
}
- return $this->deliver($this->renderers[$renderer]->render($uri, $this->requests[0], $options));
+ if (null === $this->request) {
+ throw new \LogicException('Rendering a fragment can only be done when handling a master Request.');
+ }
+
+ return $this->deliver($this->renderers[$renderer]->render($uri, $this->request, $options));
}
/**
@@ -126,7 +115,7 @@ public function render($uri, $renderer = 'inline', array $options = array())
protected function deliver(Response $response)
{
if (!$response->isSuccessful()) {
- throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $this->requests[0]->getUri(), $response->getStatusCode()));
+ throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $this->request->getUri(), $response->getStatusCode()));
}
if (!$response instanceof StreamedResponse) {
@@ -136,14 +125,6 @@ protected function deliver(Response $response)
$response->sendContent();
}
- public static function getSubscribedEvents()
- {
- return array(
- KernelEvents::REQUEST => 'onKernelRequest',
- KernelEvents::RESPONSE => 'onKernelResponse',
- );
- }
-
// to be removed in 2.3
public function fixOptions(array $options)
{
diff --git a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php
index 80d5ffa61a664..6da06c01d1544 100644
--- a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php
+++ b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\Component\HttpKernel\Tests;
+namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel;
@@ -54,10 +54,15 @@ public function testHandle($type)
->with($this->equalTo('request'))
;
$container
- ->expects($this->once())
+ ->expects($this->at(1))
->method('set')
->with($this->equalTo('request'), $this->equalTo($request), $this->equalTo('request'))
;
+ $container
+ ->expects($this->at(2))
+ ->method('set')
+ ->with($this->equalTo('request'), $this->equalTo(null), $this->equalTo('request'))
+ ;
$dispatcher = new EventDispatcher();
$resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
@@ -101,10 +106,15 @@ public function testHandleRestoresThePreviousRequestOnException($type)
->with($this->equalTo('request'))
;
$container
- ->expects($this->once())
+ ->expects($this->at(1))
->method('set')
->with($this->equalTo('request'), $this->equalTo($request), $this->equalTo('request'))
;
+ $container
+ ->expects($this->at(2))
+ ->method('set')
+ ->with($this->equalTo('request'), $this->equalTo(null), $this->equalTo('request'))
+ ;
$dispatcher = new EventDispatcher();
$resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
diff --git a/src/Symfony/Component/HttpKernel/Tests/Fragment/FragmentHandlerTest.php b/src/Symfony/Component/HttpKernel/Tests/Fragment/FragmentHandlerTest.php
index e0a5b0ad59342..f2a0838a46424 100644
--- a/src/Symfony/Component/HttpKernel/Tests/Fragment/FragmentHandlerTest.php
+++ b/src/Symfony/Component/HttpKernel/Tests/Fragment/FragmentHandlerTest.php
@@ -17,13 +17,6 @@
class FragmentHandlerTest extends \PHPUnit_Framework_TestCase
{
- protected function setUp()
- {
- if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
- $this->markTestSkipped('The "EventDispatcher" component is not available');
- }
- }
-
/**
* @expectedException \InvalidArgumentException
*/
@@ -102,14 +95,7 @@ protected function getHandler($returnValue, $arguments = array())
$handler = new FragmentHandler();
$handler->addRenderer($renderer);
-
- $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock();
- $event
- ->expects($this->once())
- ->method('getRequest')
- ->will($this->returnValue(Request::create('/')))
- ;
- $handler->onKernelRequest($event);
+ $handler->setRequest(Request::create('/'));
return $handler;
}
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy