[HttpKernel] Fix RequestStack argument position and deprecated behavior
This commit is contained in:
parent
4b68eb1f3e
commit
51b6d74557
@ -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>
|
||||
|
@ -41,7 +41,7 @@ class LazyLoadingFragmentHandler extends FragmentHandler
|
||||
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) {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -52,9 +52,9 @@ class FragmentHandler
|
||||
{
|
||||
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) {
|
||||
|
@ -91,7 +91,7 @@ class ProfilerListenerTest extends \PHPUnit_Framework_TestCase
|
||||
$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));
|
||||
|
Reference in New Issue
Block a user