8000 feature #15724 [HttpKernel] Move required RequestStack args as first … · symfony/symfony@d1c51a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit d1c51a3

Browse files
committed
feature #15724 [HttpKernel] Move required RequestStack args as first arguments (nicolas-grekas)
This PR was merged into the 2.8 branch. Discussion ---------- [HttpKernel] Move required RequestStack args as first arguments | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Since we planned to make RequestStack required, we have to move it as first arguments. Commits ------- 84ba05b [HttpKernel] Move required RequestStack args as first arguments
2 parents f1c01ed + 84ba05b commit d1c51a3

File tree

14 files changed

+111
-31
lines changed

14 files changed

+111
-31
lines changed

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

Lines 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), false);
6666

6767
return $renderer;
6868
}

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"symfony/asset": "~2.7|~3.0.0",
2525
"symfony/finder": "~2.3|~3.0.0",
2626
"symfony/form": "~2.8",
27-
"symfony/http-kernel": "~2.3|~3.0.0",
27+
"symfony/http-kernel": "~2.8|~3.0.0",
2828
"symfony/intl": "~2.3|~3.0.0",
2929
"symfony/routing": "~2.2|~3.0.0",
3030
"symfony/templating": "~2.1|~3.0.0",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<services>
1717
<service id="fragment.handler" class="%fragment.handler.class%">
1818
<argument type="service" id="service_container" />
19-
<argument>%kernel.debug%</argument>
2019
<argument type="service" id="request_stack" />
20+
<argument>%kernel.debug%</argument>
2121
</service>
2222

2323
<service id="fragment.renderer.inline" class="%fragment.renderer.inline.class%">

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@
9797
<tag name="kernel.event_subscriber" />
9898
<tag name="monolog.logger" channel="request" />
9999
<argument type="service" id="router" />
100+
<argument type="service" id="request_stack" />
100101
<argument type="service" id="router.request_context" on-invalid="ignore" />
101102
<argument type="service" id="logger" on-invalid="ignore" />
102-
<argument type="service" id="request_stack" />
103103
</service>
104104
</services>
105105
</container>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636

3737
<service id="locale_listener" class="%locale_listener.class%">
3838
<tag name="kernel.event_subscriber" />
39+
<argument type="service" id="request_stack" />
3940
<argument>%kernel.default_locale%</argument>
4041
<argument type="service" id="router" on-invalid="ignore" />
41-
<argument type="service" id="request_stack" />
4242
</service>
4343

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

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"symfony/config": "~2.4",
2323
"symfony/event-dispatcher": "~2.8|~3.0.0",
2424
"symfony/http-foundation": "~2.4.9|~2.5,>=2.5.4|~3.0.0",
25-
"symfony/http-kernel": "~2.7",
25+
"symfony/http-kernel": "~2.8",
2626
"symfony/filesystem": "~2.3|~3.0.0",
2727
"symfony/routing": "~2.8|~3.0.0",
2828
"symfony/security-core": "~2.6|~3.0.0",

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,30 @@ class LazyLoadingFragmentHandler extends FragmentHandler
2525
private $container;
2626
private $rendererIds = array();
2727

28-
public function __construct(ContainerInterface $container, $debug = false, RequestStack $requestStack = null)
28+
/**
29+
* Constructor.
30+
*
31+
* RequestStack will become required in 3.0.
32+
*
33+
* @param ContainerInterface $container A container
34+
* @param RequestStack $requestStack The Request stack that controls the lifecycle of requests
35+
* @param bool $debug Whether the debug mode is enabled or not
36+
*/
37+
public function __construct(ContainerInterface $container, $requestStack = null, $debug = false)
2938
{
3039
$this->container = $container;
3140

32-
parent::__construct(array(), $debug, $requestStack);
41+
if ((null !== $requestStack && !$requestStack instanceof RequestStack) || $debug instanceof RequestStack) {
42+
$tmp = $debug;
43+
$debug = $requestStack;
44+
$requestStack = $tmp;
45+
46+
@trigger_error('The '.__METHOD__.' method now requires a RequestStack to be given as second argument as '.__CLASS__.'::setRequest method will not be supported anymore in 3.0.', E_USER_DEPRECATED);
47+
} elseif (!$requestStack instanceof RequestStack) {
48+
@trigger_error('The '.__METHOD__.' method now requires a RequestStack instance as '.__CLASS__.'::setRequest method will not be supported anymore in 3.0.', E_USER_DEPRECATED);
49+
}
50+
51+
parent::__construct($requestStack, array(), $debug);
3352
}
3453

3554
/**

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,36 @@ class LocaleListener implements EventSubscriberInterface
3636
private $requestStack;
3737

3838
/**
39+
* Constructor.
40+
*
3941
* RequestStack will become required in 3.0.
42+
*
43+
* @param RequestStack $requestStack A RequestStack instance
44+
* @param string $defaultLocale The default locale
45+
* @param RequestContextAwareInterface|null $router The router
46+
*
47+
* @throws \InvalidArgumentException
4048
*/
41-
public function __construct($defaultLocale = 'en', RequestContextAwareInterface $router = null, RequestStack $requestStack = null)
49+
public function __construct($requestStack = null, $defaultLocale = 'en', $router = null)
4250
{
51+
if (is_string($requestStack) || $defaultLocale instanceof RequestContextAwareInterface || $router instanceof RequestStack) {
52+
$tmp = $router;
53+
$router = $defaultLocale;
54+
$defaultLocale = $requestStack;
55+
$requestStack = $tmp;
56+
57+
@trigger_error('The '.__METHOD__.' method now requires a RequestStack to be given as first argument as '.__CLASS__.'::setRequest method will not be supported anymore in 3.0.', E_USER_DEPRECATED);
58+
} elseif (!$requestStack instanceof RequestStack) {
59+
@trigger_error('The '.__METHOD__.' method now requires a RequestStack instance as '.__CLASS__.'::setRequest method will not be supported anymore in 3.0.', E_USER_DEPRECATED);
60+
}
61+
62+
if (null !== $requestStack && !$requestStack instanceof RequestStack) {
63+
throw new \InvalidArgumentException('RequestStack instance expected.');
64+
}
65+
if (null !== $router && !$router instanceof RequestContextAwareInterface) {
66+
throw new \InvalidArgumentException('Router must implement RequestContextAwareInterface.');
67+
}
68+
4369
$this->defaultLocale = $defaultLocale;
4470
$this->requestStack = $requestStack;
4571
$this->router = $router;

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,35 @@ class RouterListener implements EventSubscriberInterface
5151
* RequestStack will become required in 3.0.
5252
*
5353
* @param UrlMatcherInterface|RequestMatcherInterface $matcher The Url or Request matcher
54+
* @param RequestStack $requestStack A RequestStack instance
5455
* @param RequestContext|null $context The RequestContext (can be null when $matcher implements RequestContextAwareInterface)
5556
* @param LoggerInterface|null $logger The logger
56-
* @param RequestStack|null $requestStack A RequestStack instance
5757
*
5858
* @throws \InvalidArgumentException
5959
*/
60-
public function __construct($matcher, RequestContext $context = null, LoggerInterface $logger = null, RequestStack $requestStack = null)
60+
public function __construct($matcher, $requestStack = null, $context = null, $logger = null)
6161
{
62+
if ($requestStack instanceof RequestContext || $context instanceof LoggerInterface || $logger instanceof RequestStack) {
63+
$tmp = $requestStack;
64+
$requestStack = $logger;
65+
$logger = $context;
66+
$context = $tmp;
67+
68+
@trigger_error('The '.__METHOD__.' method now requires a RequestStack to be given as second argument as '.__CLASS__.'::setRequest method will not be supported anymore in 3.0.', E_USER_DEPRECATED);
69+
} elseif (!$requestStack instanceof RequestStack) {
70+
@trigger_error('The '.__METHOD__.' method now requires a RequestStack instance as '.__CLASS__.'::setRequest method will not be supported anymore in 3.0.', E_USER_DEPRECATED);
71+
}
72+
73+
if (null !== $requestStack && !$requestStack instanceof RequestStack) {
74+
throw new \InvalidArgumentException('RequestStack instance expected.');
75+
}
76+
if (null !== $context && !$context instanceof RequestContext) {
77+
throw new \InvalidArgumentException('RequestContext instance expected.');
78+
}
79+
if (null !== $logger && !$logger instanceof LoggerInterface) {
80+
throw new \InvalidArgumentException('Logger must implement LoggerInterface.');
81+
}
82+
6283
if (!$matcher instanceof UrlMatcherInterface && !$matcher instanceof RequestMatcherInterface) {
6384
throw new \InvalidArgumentException('Matcher must either implement UrlMatcherInterface or RequestMatcherInterface.');
6485
}
@@ -67,10 +88,6 @@ public function __construct($matcher, RequestContext $context = null, LoggerInte
6788
throw new \InvalidArgumentException('You must either pass a RequestContext or the matcher must implement RequestContextAwareInterface.');
6889
}
6990

70-
if (!$requestStack instanceof RequestStack) {
71-
@trigger_error('The '.__METHOD__.' method now requires a RequestStack instance as '.__CLASS__.'::setRequest method will not be supported anymore in 3.0.', E_USER_DEPRECATED);
72-
}
73-
7491
$this->matcher = $matcher;
7592
$this->context = $context ?: $matcher->getContext();
7693
$this->requestStack = $requestStack;

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,30 @@ class FragmentHandler
4444
*
4545
* RequestStack will become required in 3.0.
4646
*
47+
* @param RequestStack $requestStack The Request stack that controls the lifecycle of requests
4748
* @param FragmentRendererInterface[] $renderers An array of FragmentRendererInterface instances
4849
* @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
5050
*/
51-
public function __construct(array $renderers = array(), $debug = false, RequestStack $requestStack = null)
51+
public function __construct($requestStack = null, $renderers = array(), $debug = false)
5252
{
53+
if (is_array($requestStack)) {
54+
$tmp = $debug;
55+
$debug = $renderers;
56+
$renderers = $requestStack;
57+
$requestStack = $tmp;
58+
59+
@trigger_error('The '.__METHOD__.' method now requires a RequestStack to be given as first argument as '.__CLASS__.'::setRequest method will not be supported anymore in 3.0.', E_USER_DEPRECATED);
60+
} elseif (!$requestStack instanceof RequestStack) {
61+
@trigger_error('The '.__METHOD__.' method now requires a RequestStack instance as '.__CLASS__.'::setRequest method will not be supported anymore in 3.0.', E_USER_DEPRECATED);
62+
}
63+
64+
if (null !== $requestStack && !$requestStack instanceof RequestStack) {
65+
throw new \InvalidArgumentException('RequestStack instance expected.');
66+
}
67+
if (!is_array($renderers)) {
68+
throw new \InvalidArgumentException('Renderers must be an array.');
69+
}
70+
5371
$this->requestStack = $requestStack;
5472
foreach ($renderers as $renderer) {
5573
$this->addRenderer($renderer);

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

Lines 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, false);
3333
$handler->addRendererService('foo', 'foo');
3434

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

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

Lines 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/RouterListenerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function testPort($defaultHttpPort, $defaultHttpsPort, $uri, $expectedHtt
4242
->method('getContext')
4343
->will($this->returnValue($context));
4444

45-
$listener = new RouterListener($urlMatcher, null, null, $this->requestStack);
45+
$listener = new RouterListener($urlMatcher, $this->requestStack);
4646
$event = $this->createGetResponseEventForUri($uri);
4747
$listener->onKernelRequest($event);
4848

@@ -80,7 +80,7 @@ private function createGetResponseEventForUri($uri)
8080
*/
8181
public function testInvalidMatcher()
8282
{
83-
new RouterListener(new \stdClass(), null, null, $this->requestStack);
83+
new RouterListener(new \stdClass(), $this->requestStack);
8484
}
8585

8686
public function testRequestMatcher()
@@ -95,7 +95,7 @@ public function testRequestMatcher()
9595
->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
9696
->will($this->returnValue(array()));
9797

98-
$listener = new RouterListener($requestMatcher, new RequestContext(), null, $this->requestStack);
98+
$listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext());
9999
$listener->onKernelRequest($event);
100100
}
101101

@@ -116,7 +116,7 @@ public function testSubRequestWithDifferentMethod()
116116
->method('getContext')
117117
->will($this->returnValue($context));
118118

119-
$listener = new RouterListener($requestMatcher, new RequestContext(), null, $this->requestStack);
119+
$listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext());
120120
$listener->onKernelRequest($event);
121121

122122
// sub-request with another HTTP method
@@ -147,7 +147,7 @@ public function testLoggingParameter($parameter, $log)
147147
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
148148
$request = Request::create('http://localhost/');
149149

150-
$listener = new RouterListener($requestMatcher, new RequestContext(), $logger, $this->requestStack);
150+
$listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext(), $logger);
151151
$listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
152152 C381
}
153153

src/Symfony/Component/HttpKernel/Tests/Fragment/FragmentHandlerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function setUp()
3737
*/
3838
public function testRenderWhenRendererDoesNotExist()
3939
{
40-
$handler = new FragmentHandler(array(), null, $this->requestStack);
40+
$handler = new FragmentHandler($this->requestStack);
4141
$handler->render('/', 'foo');
4242
}
4343

@@ -87,7 +87,7 @@ protected function getHandler($returnValue, $arguments = array())
8787
call_user_func_array(array($e, 'with'), $arguments);
8888
}
8989

90-
$handler = new FragmentHandler(array(), null, $this->requestStack);
90+
$handler = new FragmentHandler($this->requestStack);
9191
$handler->addRenderer($renderer);
9292

9393
return $handler;

0 commit comments

Comments
 (0)
0