Skip to content

Commit

Permalink
[HttpKernel] Fix RequestStack argument position and deprecated behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Sep 10, 2015
1 parent 4b68eb1 commit 51b6d74
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 15 deletions.
Expand Up @@ -26,10 +26,10 @@
<service id="profiler_listener" class="%profiler_listener.class%">
<tag name="kernel.event_subscriber" />
<argument type="service" id="profiler" />
<argument type="service" id="request_stack" />
<argument type="service" id="profiler.request_matcher" on-invalid="null" />
<argument>%profiler_listener.only_exceptions%</argument>
<argument>%profiler_listener.only_master_requests%</argument>
<argument type="service" id="request_stack" />
</service>
</services>
</container>
Expand Up @@ -41,7 +41,7 @@ public function __construct(ContainerInterface $container, $requestStack = null,
if ((null !== $requestStack && !$requestStack instanceof RequestStack) || $debug instanceof RequestStack) {
$tmp = $debug;
$debug = $requestStack;
$requestStack = $tmp;
$requestStack = func_num_args() < 3 ? null : $tmp;

@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);
} elseif (!$requestStack instanceof RequestStack) {
Expand Down
Expand Up @@ -48,11 +48,11 @@ class LocaleListener implements EventSubscriberInterface
*/
public function __construct($requestStack = null, $defaultLocale = 'en', $router = null)
{
if (is_string($requestStack) || $defaultLocale instanceof RequestContextAwareInterface || $router instanceof RequestStack) {
if ((null !== $requestStack && !$requestStack instanceof RequestStack) || $defaultLocale instanceof RequestContextAwareInterface || $router instanceof RequestStack) {
$tmp = $router;
$router = $defaultLocale;
$router = func_num_args() < 2 ? null : $defaultLocale;
$defaultLocale = $requestStack;
$requestStack = $tmp;
$requestStack = func_num_args() < 3 ? null : $tmp;

@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);
} elseif (!$requestStack instanceof RequestStack) {
Expand Down
Expand Up @@ -42,18 +42,30 @@ class ProfilerListener implements EventSubscriberInterface
* Constructor.
*
* @param Profiler $profiler A Profiler instance
* @param RequestStack $requestStack A RequestStack instance
* @param RequestMatcherInterface|null $matcher A RequestMatcher instance
* @param bool $onlyException true if the profiler only collects data when an exception occurs, false otherwise
* @param bool $onlyMasterRequests true if the profiler only collects data when the request is a master request, false otherwise
* @param RequestStack|null $requestStack A RequestStack instance
*/
public function __construct(Profiler $profiler, RequestMatcherInterface $matcher = null, $onlyException = false, $onlyMasterRequests = false, RequestStack $requestStack = null)
public function __construct(Profiler $profiler, $requestStack = null, $matcher = null, $onlyException = false, $onlyMasterRequests = false)
{
if (null === $requestStack) {
// Prevent the deprecation notice to be triggered all the time.
// The onKernelRequest() method fires some logic only when the
// RequestStack instance is not provided as a dependency.
@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);
if ($requestStack instanceof RequestMatcherInterface || $onlyMasterRequests instanceof RequestStack) {
$tmp = $onlyMasterRequests;
$onlyMasterRequests = $onlyException;
$onlyException = $matcher;
$matcher = $requestStack;
$requestStack = func_num_args() < 5 ? null : $tmp;

@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);
} elseif (!$requestStack instanceof RequestStack) {
@trigger_error('The '.__METHOD__.' method now requires a RequestStack instance as '.__CLASS__.'::onKernelRequest method will be removed in 3.0.', E_USER_DEPRECATED);
}

if (null !== $requestStack && !$requestStack instanceof RequestStack) {
throw new \InvalidArgumentException('RequestStack instance expected.');
}
if (null !== $matcher && !$matcher instanceof RequestMatcherInterface) {
throw new \InvalidArgumentException('Matcher must implement RequestMatcherInterface.');
}

$this->profiler = $profiler;
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpKernel/Fragment/FragmentHandler.php
Expand Up @@ -52,9 +52,9 @@ public function __construct($requestStack = null, $renderers = array(), $debug =
{
if (is_array($requestStack)) {
$tmp = $debug;
$debug = $renderers;
$debug = func_num_args() < 2 ? false : $renderers;
$renderers = $requestStack;
$requestStack = $tmp;
$requestStack = func_num_args() < 3 ? null : $tmp;

@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);
} elseif (!$requestStack instanceof RequestStack) {
Expand Down
Expand Up @@ -91,7 +91,7 @@ public function testKernelTerminate()
$requestStack->push($masterRequest);

$onlyException = true;
$listener = new ProfilerListener($profiler, null, $onlyException, false, $requestStack);
$listener = new ProfilerListener($profiler, $requestStack, null, $onlyException);

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

0 comments on commit 51b6d74

Please sign in to comment.