Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fadeafd

Browse files
committed
[Stopwatch] Add getRootSectionEvents method ROOT constant to Stopwatch
1 parent 5a00a8b commit fadeafd

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Symfony/Component/Stopwatch/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.2
5+
---
6+
7+
* Add `getRootSectionEvents()` method and `ROOT` constant to `Stopwatch`
8+
49
5.2
510
---
611

src/Symfony/Component/Stopwatch/Stopwatch.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class_exists(Section::class);
2323
*/
2424
class Stopwatch implements ResetInterface
2525
{
26+
public const ROOT = '__root__';
27+
2628
/**
2729
* @var Section[]
2830
*/
@@ -138,14 +140,24 @@ public function getEvent(string $name): StopwatchEvent
138140
*/
139141
public function getSectionEvents(string $id): array
140142
{
141-
return isset($this->sections[$id]) ? $this->sections[$id]->getEvents() : [];
143+
return $this->sections[$id]->getEvents() ?? [];
144+
}
145+
146+
/**
147+
* Gets all events for the root section.
148+
*
149+
* @return StopwatchEvent[]
150+
*/
151+
public function getRootSectionEvents(): array
152+
{
153+
return $this->sections[self::ROOT]->getEvents() ?? [];
142154
}
143155

144156
/**
145157
* Resets the stopwatch to its original state.
146158
*/
147159
public function reset(): void
148160
{
149-
$this->sections = $this->activeSections = ['__root__' => new Section(null, $this->morePrecision)];
161+
$this->sections = $this->activeSections = [self::ROOT => new Section(null, $this->morePrecision)];
150162
}
151163
}

0 commit comments

Comments
 (0)