Skip to content

Commit 89169c8

Browse files
author
Hugo Hamon
committed
Fixes more deprecation notices.
1 parent c2c1cb7 commit 89169c8

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

EventListener/ProfilerListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(Profiler $profiler, RequestMatcherInterface $matcher
5353
// Prevent the deprecation notice to be triggered all the time.
5454
// The onKernelRequest() method fires some logic only when the
5555
// RequestStack instance is not provided as a dependency.
56-
trigger_error('The '.__CLASS__.'::onKernelRequest method is deprecated since version 2.4 and will be removed in 3.0.', E_USER_DEPRECATED);
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);
5757
}
5858

5959
$this->profiler = $profiler;

EventListener/RouterListener.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public function __construct($matcher, RequestContext $context = null, LoggerInte
6767
throw new \InvalidArgumentException('You must either pass a RequestContext or the matcher must implement RequestContextAwareInterface.');
6868
}
6969

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.');
72+
}
73+
7074
$this->matcher = $matcher;
7175
$this->context = $context ?: $matcher->getContext();
7276
$this->requestStack = $requestStack;
@@ -88,9 +92,15 @@ public function setRequest(Request $request = null)
8892
{
8993
trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be made private in 3.0.', E_USER_DEPRECATED);
9094

95+
$this->setCurrentRequest($request);
96+
}
97+
98+
private function setCurrentRequest(Request $request = null)
99+
{
91100
if (null !== $request && $this->request !== $request) {
92101
$this->context->fromRequest($request);
93102
}
103+
94104
$this->request = $request;
95105
}
96106

@@ -100,19 +110,19 @@ public function onKernelFinishRequest(FinishRequestEvent $event)
100110
return; // removed when requestStack is required
101111
}
102112

103-
$this->setRequest($this->requestStack->getParentRequest());
113+
$this->setCurrentRequest($this->requestStack->getParentRequest());
104114
}
105115

106116
public function onKernelRequest(GetResponseEvent $event)
107117
{
108118
$request = $event->getRequest();
109119

110120
// initialize the context that is also used by the generator (assuming matcher and generator share the same context instance)
111-
// we call setRequest even if most of the time, it has already been done to keep compatibility
121+
// we call setCurrentRequest even if most of the time, it has already been done to keep compatibility
112122
// with frameworks which do not use the Symfony service container
113123
// when we have a RequestStack, no need to do it
114124
if (null !== $this->requestStack) {
115-
$this->setRequest($request);
125+
$this->setCurrentRequest($request);
116126
}
117127

118128
if ($request->attributes->has('_controller')) {

0 commit comments

Comments
 (0)