8000 minor #15754 [HttpKernel] Fix RequestStack argument position and depr… · Seldaek/symfony@8bc6df3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8bc6df3

Browse files
minor symfony#15754 [HttpKernel] Fix RequestStack argument position and deprecated behavior (nicolas-grekas)
This PR was merged into the 2.8 branch. Discussion ---------- [HttpKernel] Fix RequestStack argument position and deprecated behavior | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- 51b6d74 [HttpKernel] Fix RequestStack argument position and deprecated behavior
2 parents 4b68eb1 + 51b6d74 commit 8bc6df3

File tree

6 files changed

+27
-15
lines changed

6 files changed

+27
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
<service id="profiler_listener" class="%profiler_listener.class%">
2727
<tag name="kernel.event_subscriber" />
2828
<argument type="service" id="profiler" />
29+
<argument type="service" id="request_stack" />
2930
<argument type="service" id="profiler.request_matcher" on-invalid="null" />
3031
<argument>%profiler_listener.only_exceptions%</argument>
3132
<argument>%profiler_listener.only_master_requests%</argument>
32-
<argument type="service" id="request_stack" />
3333
</service>
3434
</services>
3535
</container>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(ContainerInterface $container, $requestStack = null,
4141
if ((null !== $requestStack && !$requestStack instanceof RequestStack) || $debug instanceof RequestStack) {
4242
$tmp = $debug;
4343
$debug = $requestStack;
44-
$requestStack = $tmp;
44+
$requestStack = func_num_args() < 3 ? null : $tmp;
4545

4646
@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);
4747
} elseif (!$requestStack instanceof RequestStack) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ class LocaleListener implements EventSubscriberInterface
4848
*/
4949
public function __construct($requestStack = null, $defaultLocale = 'en', $router = null)
5050
{
51-
if (is_string($requestStack) || $defaultLocale instanceof RequestContextAwareInterface || $router instanceof RequestStack) {
51+
if ((null !== $requestStack && !$requestStack instanceof RequestStack) || $defaultLocale instanceof RequestContextAwareInterface || $router instanceof RequestStack) {
5252
$tmp = $router;
53-
$router = $defaultLocale;
53+
$router = func_num_args() < 2 ? null : $defaultLocale;
5454
$defaultLocale = $requestStack;
55-
$requestStack = $tmp;
55+
$requestStack = func_num_args() < 3 ? null : $tmp;
5656

5757
@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);
5858
} elseif (!$requestStack instanceof RequestStack) {

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,30 @@ class ProfilerListener implements EventSubscriberInterface
4242
* Constructor.
4343
*
4444
* @param Profiler $profiler A Profiler instance
45+
* @param RequestStack $requestStack A RequestStack instance
4546
* @param RequestMatcherInterface|null $matcher A RequestMatcher instance
4647
* @param bool $onlyException true if the profiler only collects data when an exception occurs, false otherwise
4748
* @param bool $onlyMasterRequests true if the profiler only collects data when the request is a master request, false otherwise
48-
* @param RequestStack|null $requestStack A RequestStack instance
4949
*/
50-
public function __construct(Profiler $profiler, RequestMatcherInterface $matcher = null, $onlyException = false, $onlyMasterRequests = false, RequestStack $requestStack = null)
50+
public function __construct(Profiler $profiler, $requestStack = null, $matcher = null, $onlyException = false, $onlyMasterRequests = false)
5151
{
52-
if (null === $requestStack) {
53-
// Prevent the deprecation notice to be triggered all the time.
54-
// The onKernelRequest() method fires some logic only when the
55-
// RequestStack instance is not provided as a dependency.
56-
@trigger_error('Since version 2.4, the '.__METHOD__.' method must accept a RequestStack instance to get the request instead of using the '.__CLASS__.'::onKernelRequest method that will be removed in 3.0.', E_USER_DEPRECATED);
52+
if ($requestStack instanceof RequestMatcherInterface || $onlyMasterRequests instanceof RequestStack) {
53+
$tmp = $onlyMasterRequests;
54+
$onlyMasterRequests = $onlyException;
55+
$onlyException = $matcher;
56+
$matcher = $requestStack;
57+
$requestStack = func_num_args() < 5 ? null : $tmp;
58+
59+
@trigger_error('The '.__METHOD__.' method now requires a RequestStack to be given as second argument as '.__CLASS__.'::onKernelRequest method will be removed in 3.0.', E_USER_DEPRECATED);
60+
} elseif (!$requestStack instanceof RequestStack) {
61+
@trigger_error('The '.__METHOD__.' method now requires a RequestStack instance as '.__CLASS__.'::onKernelRequest method will be removed 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 (null !== $matcher && !$matcher insta 6D40 nceof RequestMatcherInterface) {
68+
throw new \InvalidArgumentException('Matcher must implement RequestMatcherInterface.');
5769
}
5870

5971
$this->profiler = $profiler;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public function __construct($requestStack = null, $renderers = array(), $debug =
5252
{
5353
if (is_array($requestStack)) {
5454
$tmp = $debug;
55-
$debug = $renderers;
55+
$debug = func_num_args() < 2 ? false : $renderers;
5656
$renderers = $requestStack;
57-
$requestStack = $tmp;
57+
$requestStack = func_num_args() < 3 ? null : $tmp;
5858

5959
@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);
6060
} elseif (!$requestStack instanceof RequestStack) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function testKernelTerminate()
9191
$requestStack->push($masterRequest);
9292

9393
$onlyException = true;
94-
$listener = new ProfilerListener($profiler, null, $onlyException, false, $requestStack);
94+
$listener = new ProfilerListener($profiler, $requestStack, null, $onlyException);
9595

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

0 commit comments

Comments
 (0)
0