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);

0 commit comments

Comments
 (0)
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