diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 8b2b5c14d2947..710560b76927a 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -480,7 +480,7 @@ Serializer Stopwatch --------- - * Removed support of passing `null` as 1st (`$id`) argument of `Section::get()` method, pass a valid child section identifier instead. + * Removed support for passing `null` as 1st (`$id`) argument of `Section::get()` method, pass a valid child section identifier instead. Translation ----------- diff --git a/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php b/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php index 6c96afdff3908..ce4ddb35d3f75 100644 --- a/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php @@ -41,6 +41,9 @@ protected function beforeDispatch(string $eventName, $event) break; case KernelEvents::TERMINATE: $token = $event->getResponse()->headers->get('X-Debug-Token'); + if (null === $token) { + break; + } // There is a very special case when using built-in AppCache class as kernel wrapper, in the case // of an ESI request leading to a `stale` response [B] inside a `fresh` cached response [A]. // In this case, `$token` contains the [B] debug token, but the open `stopwatch` section ID @@ -65,12 +68,18 @@ protected function afterDispatch(string $eventName, $event) break; case KernelEvents::RESPONSE: $token = $event->getResponse()->headers->get('X-Debug-Token'); + if (null === $token) { + break; + } $this->stopwatch->stopSection($token); break; case KernelEvents::TERMINATE: // In the special case described in the `preDispatch` method above, the `$token` section // does not exist, then closing it throws an exception which must be caught. $token = $event->getResponse()->headers->get('X-Debug-Token'); + if (null === $token) { + break; + } try { $this->stopwatch->stopSection($token); } catch (\LogicException $e) { diff --git a/src/Symfony/Component/HttpKernel/Tests/Debug/TraceableEventDispatcherTest.php b/src/Symfony/Component/HttpKernel/Tests/Debug/TraceableEventDispatcherTest.php index 01cf8e97c72b5..0fa6fcde5114d 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Debug/TraceableEventDispatcherTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Debug/TraceableEventDispatcherTest.php @@ -62,15 +62,13 @@ public function testStopwatchCheckControllerOnRequestEvent() public function testStopwatchStopControllerOnRequestEvent() { $stopwatch = $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch') - ->setMethods(['isStarted', 'stop', 'stopSection']) + ->setMethods(['isStarted', 'stop']) ->getMock(); $stopwatch->expects($this->once()) ->method('isStarted') ->willReturn(true); $stopwatch->expects($this->once()) ->method('stop'); - $stopwatch->expects($this->once()) - ->method('stopSection'); $dispatcher = new TraceableEventDispatcher(new EventDispatcher(), $stopwatch); diff --git a/src/Symfony/Component/Stopwatch/CHANGELOG.md b/src/Symfony/Component/Stopwatch/CHANGELOG.md index 85a62f0181190..14b7dc6dd5ef3 100644 --- a/src/Symfony/Component/Stopwatch/CHANGELOG.md +++ b/src/Symfony/Component/Stopwatch/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +5.0.0 +----- + + * Removed support for passing `null` as 1st (`$id`) argument of `Section::get()` method, pass a valid child section identifier instead. + 4.4.0 ----- diff --git a/src/Symfony/Component/Stopwatch/Stopwatch.php b/src/Symfony/Component/Stopwatch/Stopwatch.php index 19e59bec501f5..9a3fe56d86e78 100644 --- a/src/Symfony/Component/Stopwatch/Stopwatch.php +++ b/src/Symfony/Component/Stopwatch/Stopwatch.php @@ -81,7 +81,7 @@ public function openSection(string $id = null) * * @throws \LogicException When there's no started section to be stopped */ - public function stopSection(?string $id) + public function stopSection(string $id) { $this->stop('__section__');