From fadeafde9a46f68ee07633403bc3af32c69a8f2b Mon Sep 17 00:00:00 2001 From: Philipp Wahala Date: Mon, 13 May 2024 10:19:23 +0200 Subject: [PATCH] [Stopwatch] Add `getRootSectionEvents` method `ROOT` constant to `Stopwatch` --- src/Symfony/Component/Stopwatch/CHANGELOG.md | 5 +++++ src/Symfony/Component/Stopwatch/Stopwatch.php | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Stopwatch/CHANGELOG.md b/src/Symfony/Component/Stopwatch/CHANGELOG.md index f2fd7d0f03de1..816eb796d1d9a 100644 --- a/src/Symfony/Component/Stopwatch/CHANGELOG.md +++ b/src/Symfony/Component/Stopwatch/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.2 +--- + + * Add `getRootSectionEvents()` method and `ROOT` constant to `Stopwatch` + 5.2 --- diff --git a/src/Symfony/Component/Stopwatch/Stopwatch.php b/src/Symfony/Component/Stopwatch/Stopwatch.php index 53ef69f769987..335fd9325f32b 100644 --- a/src/Symfony/Component/Stopwatch/Stopwatch.php +++ b/src/Symfony/Component/Stopwatch/Stopwatch.php @@ -23,6 +23,8 @@ class_exists(Section::class); */ class Stopwatch implements ResetInterface { + public const ROOT = '__root__'; + /** * @var Section[] */ @@ -138,7 +140,17 @@ public function getEvent(string $name): StopwatchEvent */ public function getSectionEvents(string $id): array { - return isset($this->sections[$id]) ? $this->sections[$id]->getEvents() : []; + return $this->sections[$id]->getEvents() ?? []; + } + + /** + * Gets all events for the root section. + * + * @return StopwatchEvent[] + */ + public function getRootSectionEvents(): array + { + return $this->sections[self::ROOT]->getEvents() ?? []; } /** @@ -146,6 +158,6 @@ public function getSectionEvents(string $id): array */ public function reset(): void { - $this->sections = $this->activeSections = ['__root__' => new Section(null, $this->morePrecision)]; + $this->sections = $this->activeSections = [self::ROOT => new Section(null, $this->morePrecision)]; } }