Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7ed4189

Browse filesBrowse files
committed
[HttpKernel] make RequestStack parameter required for classes that need it
1 parent 8279d11 commit 7ed4189
Copy full SHA for 7ed4189

File tree

Expand file treeCollapse file tree

16 files changed

+46
-88
lines changed
Filter options
Expand file treeCollapse file tree

16 files changed

+46
-88
lines changed

‎src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Tests/Extension/HttpKernelExtensionTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testUnknownFragmentRenderer()
4343
->disableOriginalConstructor()
4444
->getMock()
4545
;
46-
$renderer = new FragmentHandler(array(), false, $context);
46+
$renderer = new FragmentHandler($context);
4747

4848
$this->setExpectedException('InvalidArgumentException', 'The "inline" renderer does not exist.');
4949
$renderer->render('/foo');
@@ -62,7 +62,7 @@ protected function getFragmentHandler($return)
6262

6363
$context->expects($this->any())->method('getCurrentRequest')->will($this->returnValue(Request::create('/')));
6464

65-
$renderer = new FragmentHandler(array($strategy), false, $context);
65+
$renderer = new FragmentHandler($context, array($strategy));
6666

6767
return $renderer;
6868
}

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/fragment_renderer.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/fragment_renderer.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<services>
1313
<service id="fragment.handler" class="Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler">
1414
<argument type="service" id="service_container" />
15-
<argument>%kernel.debug%</argument>
1615
<argument type="service" id="request_stack" />
16+
<argument>%kernel.debug%</argument>
1717
</service>
1818

1919
<service id="fragment.renderer.inline" class="Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer">

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
<service id="profiler_listener" class="Symfony\Component\HttpKernel\EventListener\ProfilerListener">
2222
<tag name="kernel.event_subscriber" />
2323
<argument type="service" id="profiler" />
24+
<argument type="service" id="request_stack" />
2425
<argument type="service" id="profiler.request_matcher" on-invalid="null" />
2526
<argument>%profiler_listener.only_exceptions%</argument>
2627
<argument>%profiler_listener.only_master_requests%</argument>
27-
<argument type="service" id="request_stack" />
2828
</service>
2929
</services>
3030
</container>

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@
8383
<tag name="kernel.event_subscriber" />
8484
<tag name="monolog.logger" channel="request" />
8585
<argument type="service" id="router" />
86+
<argument type="service" id="request_stack" />
8687
<argument type="service" id="router.request_context" on-invalid="ignore" />
8788
<argument type="service" id="logger" on-invalid="ignore" />
88-
<argument type="service" id="request_stack" />
8989
</service>
9090
</services>
9191
</container>

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828

2929
<service id="locale_listener" class="Symfony\Component\HttpKernel\EventListener\LocaleListener">
3030
<tag name="kernel.event_subscriber" />
31+
<argument type="service" id="request_stack" />
3132
<argument>%kernel.default_locale%</argument>
3233
<argument type="service" id="router" on-invalid="ignore" />
33-
<argument type="service" id="request_stack" />
3434
</service>
3535

3636
<service id="translator_listener" class="Symfony\Component\HttpKernel\EventListener\TranslatorListener">

‎src/Symfony/Component/HttpKernel/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/CHANGELOG.md
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ CHANGELOG
2424
* removed `Symfony\Component\HttpKernel\HttpCache\EsiResponseCacheStrategyInterface`
2525
* removed `Symfony\Component\HttpKernel\Log\LoggerInterface`
2626
* removed `Symfony\Component\HttpKernel\Log\NullLogger`
27+
* made the `RequestStack` parameter required in the constructor of the following classes, which also changed the parameter order:
28+
* `Symfony\Component\HttpKernel\EventListener\LocaleListener`
29+
* `Symfony\Component\HttpKernel\EventListener\ProfilerListener`
30+
* `Symfony\Component\HttpKernel\EventListener\RouterListener`
31+
* `Symfony\Component\HttpKernel\Fragment\FragmentHandler`
32+
* `Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler`
2733

2834
2.7.0
2935
-----

‎src/Symfony/Component/HttpKernel/DependencyInjection/LazyLoadingFragmentHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/DependencyInjection/LazyLoadingFragmentHandler.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class LazyLoadingFragmentHandler extends FragmentHandler
2525
private $container;
2626
private $rendererIds = array();
2727

28-
public function __construct(ContainerInterface $container, $debug = false, RequestStack $requestStack = null)
28+
public function __construct(ContainerInterface $container, RequestStack $requestStack, $debug = false)
2929
{
3030
$this->container = $container;
3131

32-
parent::__construct(array(), $debug, $requestStack);
32+
parent::__construct($requestStack, array(), $debug);
3333
}
3434

3535
/**

‎src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php
+1-13Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222
/**
2323
* Initializes the locale based on the current request.
2424
*
25-
* This listener works in 2 modes:
26-
*
27-
* * 2.3 compatibility mode where you must call setRequest whenever the Request changes.
28-
* * 2.4+ mode where you must pass a RequestStack instance in the constructor.
29-
*
3025
* @author Fabien Potencier <fabien@symfony.com>
3126
*/
3227
class LocaleListener implements EventSubscriberInterface
@@ -35,10 +30,7 @@ class LocaleListener implements EventSubscriberInterface
3530
private $defaultLocale;
3631
private $requestStack;
3732

38-
/**
39-
* RequestStack will become required in 3.0.
40-
*/
41-
public function __construct($defaultLocale = 'en', RequestContextAwareInterface $router = null, RequestStack $requestStack = null)
33+
public function __construct(RequestStack $requestStack, $defaultLocale = 'en', RequestContextAwareInterface $router = null)
4234
{
4335
$this->defaultLocale = $defaultLocale;
4436
$this->requestStack = $requestStack;
@@ -56,10 +48,6 @@ public function onKernelRequest(GetResponseEvent $event)
5648

5749
public function onKernelFinishRequest(FinishRequestEvent $event)
5850
{
59-
if (null === $this->requestStack) {
60-
return; // removed when requestStack is required
61-
}
62-
6351
if (null !== $parentRequest = $this->requestStack->getParentRequest()) {
6452
$this->setRouterContext($parentRequest);
6553
}

‎src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php
+3-12Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class ProfilerListener implements EventSubscriberInterface
3232
protected $onlyException;
3333
protected $onlyMasterRequests;
3434
protected $exception;
35-
protected $requests = array();
3635
protected $profiles;
3736
protected $requestStack;
3837
protected $parents;
@@ -41,12 +40,12 @@ class ProfilerListener implements EventSubscriberInterface
4140
* Constructor.
4241
*
4342
* @param Profiler $profiler A Profiler instance
43+
* @param RequestStack $requestStack A RequestStack instance
4444
* @param RequestMatcherInterface|null $matcher A RequestMatcher instance
4545
* @param bool $onlyException true if the profiler only collects data when an exception occurs, false otherwise
4646
* @param bool $onlyMasterRequests true if the profiler only collects data when the request is a master request, false otherwise
47-
* @param RequestStack|null $requestStack A RequestStack instance
4847
*/
49-
public function __construct(Profiler $profiler, RequestMatcherInterface $matcher = null, $onlyException = false, $onlyMasterRequests = false, RequestStack $requestStack = null)
48+
public function __construct(Profiler $profiler, RequestStack $requestStack, RequestMatcherInterface $matcher = null, $onlyException = false, $onlyMasterRequests = false)
5049
{
5150
$this->profiler = $profiler;
5251
$this->matcher = $matcher;
@@ -101,14 +100,7 @@ public function onKernelResponse(FilterResponseEvent $event)
101100

102101
$this->profiles[$request] = $profile;
103102

104-
if (null !== $this->requestStack) {
105-
$this->parents[$request] = $this->requestStack->getParentRequest();
106-
} elseif (!$master) {
107-
// to be removed when requestStack is required
108-
array_pop($this->requests);
109-
110-
$this->parents[$request] = end($this->requests);
111-
}
103+
$this->parents[$request] = $this->requestStack->getParentRequest();
112104
}
113105

114106
public function onKernelTerminate(PostResponseEvent $event)
@@ -130,7 +122,6 @@ public function onKernelTerminate(PostResponseEvent $event)
130122

131123
$this->profiles = new \SplObjectStorage();
132124
$this->parents = new \SplObjectStorage();
133-
$this->requests = array();
134125
}
135126

136127
public static function getSubscribedEvents()

‎src/Symfony/Component/HttpKernel/EventListener/RouterListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/EventListener/RouterListener.php
+10-24Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,26 @@
3030
/**
3131
* Initializes the context from the request and sets request attributes based on a matching route.
3232
*
33-
* This listener works in 2 modes:
34-
*
35-
* * 2.3 compatibility mode where you must call setRequest whenever the Request changes.
36-
* * 2.4+ mode where you must pass a RequestStack instance in the constructor.
37-
*
3833
* @author Fabien Potencier <fabien@symfony.com>
3934
*/
4035
class RouterListener implements EventSubscriberInterface
4136
{
4237
private $matcher;
4338
private $context;
4439
private $logger;
45-
private $request;
4640
private $requestStack;
4741

4842
/**
4943
* Constructor.
5044
*
51-
* RequestStack will become required in 3.0.
52-
*
5345
* @param UrlMatcherInterface|RequestMatcherInterface $matcher The Url or Request matcher
46+
* @param RequestStack $requestStack A RequestStack instance
5447
* @param RequestContext|null $context The RequestContext (can be null when $matcher implements RequestContextAwareInterface)
5548
* @param LoggerInterface|null $logger The logger
56-
* @param RequestStack|null $requestStack A RequestStack instance
5749
*
5850
* @throws \InvalidArgumentException
5951
*/
60-
public function __construct($matcher, RequestContext $context = null, LoggerInterface $logger = null, RequestStack $requestStack = null)
52+
public function __construct($matcher, RequestStack $requestStack, RequestContext $context = null, LoggerInterface $logger = null)
6153
{
6254
if (!$matcher instanceof UrlMatcherInterface && !$matcher instanceof RequestMatcherInterface) {
6355
throw new \InvalidArgumentException('Matcher must either implement UrlMatcherInterface or RequestMatcherInterface.');
@@ -75,33 +67,27 @@ public function __construct($matcher, RequestContext $context = null, LoggerInte
7567

7668
private function setCurrentRequest(Request $request = null)
7769
{
78-
if (null !== $request && $this->request !== $request) {
70+
if (null !== $request) {
7971
$this->context->fromRequest($request);
8072
}
81-
82-
$this->request = $request;
8373
}
8474

75+
/**
76+
* After a sub-request is done, we need to reset the routing context to the parent request so that the URL generator
77+
* operates on the correct context again.
78+
*
79+
* @param FinishRequestEvent $event
80+
*/
8581
public function onKernelFinishRequest(FinishRequestEvent $event)
8682
{
87-
if (null === $this->requestStack) {
88-
return; // removed when requestStack is required
89-
}
90-
9183
$this->setCurrentRequest($this->requestStack->getParentRequest());
9284
}
9385

9486
public function onKernelRequest(GetResponseEvent $event)
9587
{
9688
$request = $event->getRequest();
9789

98-
// initialize the context that is also used by the generator (assuming matcher and generator share the same context instance)
99-
// we call setCurrentRequest even if most of the time, it has already been done to keep compatibility
100-
// with frameworks which do not use the Symfony service container
101-
// when we have a RequestStack, no need to do it
102-
if (null !== $this->requestStack) {
103-
$this->setCurrentRequest($request);
104-
}
90+
$this->setCurrentRequest($request);
10591

10692
if ($request->attributes->has('_controller')) {
10793
// routing is already done

‎src/Symfony/Component/HttpKernel/Fragment/FragmentHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Fragment/FragmentHandler.php
+4-17Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@
2323
* This class handles the rendering of resource fragments that are included into
2424
* a main resource. The handling of the rendering is managed by specialized renderers.
2525
*
26-
* This listener works in 2 modes:
27-
*
28-
* * 2.3 compatibility mode where you must call setRequest whenever the Request changes.
29-
* * 2.4+ mode where you must pass a RequestStack instance in the constructor.
30-
*
3126
* @author Fabien Potencier <fabien@symfony.com>
3227
*
3328
* @see FragmentRendererInterface
@@ -36,19 +31,16 @@ class FragmentHandler
3631
{
3732
private $debug;
3833
private $renderers = array();
39-
private $request;
4034
private $requestStack;
4135

4236
/**
4337
* Constructor.
4438
*
45-
* RequestStack will become required in 3.0.
46-
*
39+
* @param RequestStack $requestStack The Request stack that controls the lifecycle of requests
4740
* @param FragmentRendererInterface[] $renderers An array of FragmentRendererInterface instances
4841
* @param bool $debug Whether the debug mode is enabled or not
49-
* @param RequestStack|null $requestStack The Request stack that controls the lifecycle of requests
5042
*/
51-
public function __construct(array $renderers = array(), $debug = false, RequestStack $requestStack = null)
43+
public function __construct(RequestStack $requestStack, array $renderers = array(), $debug = false)
5244
{
5345
$this->requestStack = $requestStack;
5446
foreach ($renderers as $renderer) {
@@ -93,7 +85,7 @@ public function render($uri, $renderer = 'inline', array $options = array())
9385
throw new \InvalidArgumentException(sprintf('The "%s" renderer does not exist.', $renderer));
9486
}
9587

96-
if (!$request = $this->getRequest()) {
88+
if (!$request = $this->requestStack->getCurrentRequest()) {
9789
throw new \LogicException('Rendering a fragment can only be done when handling a Request.');
9890
}
9991

@@ -115,7 +107,7 @@ public function render($uri, $renderer = 'inline', array $options = array())
115107
protected function deliver(Response $response)
116108
{
117109
if (!$response->isSuccessful()) {
118-
throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $this->getRequest()->getUri(), $response->getStatusCode()));
110+
throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $this->requestStack->getCurrentRequest()->getUri(), $response->getStatusCode()));
119111
}
120112

121113
if (!$response instanceof StreamedResponse) {
@@ -124,9 +116,4 @@ protected function deliver(Response $response)
124116

125117
$response->sendContent();
126118
}
127-
128-
private function getRequest()
129-
{
130-
return $this->requestStack ? $this->requestStack->getCurrentRequest() : $this->request;
131-
}
132119
}

‎src/Symfony/Component/HttpKernel/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function test()
2929
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
3030
$container->expects($this->once())->method('get')->will($this->returnValue($renderer));
3131

32-
$handler = new LazyLoadingFragmentHandler($container, false, $requestStack);
32+
$handler = new LazyLoadingFragmentHandler($container, $requestStack);
3333
$handler->addRendererService('foo', 'foo');
3434

3535
$handler->render('/foo', 'foo');

‎src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/EventListener/LocaleListenerTest.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function setUp()
2828

2929
public function testDefaultLocaleWithoutSession()
3030
{
31-
$listener = new LocaleListener('fr', null, $this->requestStack);
31+
$listener = new LocaleListener($this->requestStack, 'fr');
3232
$event = $this->getEvent($request = Request::create('/'));
3333

3434
$listener->onKernelRequest($event);
@@ -42,7 +42,7 @@ public function testLocaleFromRequestAttribute()
4242
$request->cookies->set('foo', 'value');
4343

4444
$request->attributes->set('_locale', 'es');
45-
$listener = new LocaleListener('fr', null, $this->requestStack);
45+
$listener = new LocaleListener($this->requestStack, 'fr');
4646
$event = $this->getEvent($request);
4747

4848
$listener->onKernelRequest($event);
@@ -61,7 +61,7 @@ public function testLocaleSetForRoutingContext()
6161
$request = Request::create('/');
6262

6363
$request->attributes->set('_locale', 'es');
64-
$listener = new LocaleListener('fr', $router, $this->requestStack);
64+
$listener = new LocaleListener($this->requestStack, 'fr', $router);
6565
$listener->onKernelRequest($this->getEvent($request));
6666
}
6767

@@ -81,15 +81,15 @@ public function testRouterResetWithParentRequestOnKernelFinishRequest()
8181

8282
$event = $this->getMock('Symfony\Component\HttpKernel\Event\FinishRequestEvent', array(), array(), '', false);
8383

84-
$listener = new LocaleListener('fr', $router, $this->requestStack);
84+
$listener = new LocaleListener($this->requestStack, 'fr', $router);
8585
$listener->onKernelFinishRequest($event);
8686
}
8787

8888
public function testRequestLocaleIsNotOverridden()
8989
{
9090
$request = Request::create('/');
9191
$request->setLocale('de');
92-
$listener = new LocaleListener('fr', null, $this->requestStack);
92+
$listener = new LocaleListener($this->requestStack, 'fr');
9393
$event = $this->getEvent($request);
9494

9595
$listener->onKernelRequest($event);

‎src/Symfony/Component/HttpKernel/Tests/EventListener/ProfilerListenerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/EventListener/ProfilerListenerTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testKernelTerminate()
4444
->disableOriginalConstructor()
4545
->getMock();
4646

47-
$subRequest = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
47+
$subRequest = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
4848
->disableOriginalConstructor()
4949
->getMock();
5050

@@ -56,7 +56,7 @@ public function testKernelTerminate()
5656
$requestStack->push($masterRequest);
5757

5858
$onlyException = true;
59-
$listener = new ProfilerListener($profiler, null, $onlyException, false, $requestStack);
59+
$listener = new ProfilerListener($profiler, $requestStack, null, $onlyException);
6060

6161
// master request
6262
$listener->onKernelResponse(new FilterResponseEvent($kernel, $masterRequest, Kernel::MASTER_REQUEST, $response));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.