Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fadeafd

Browse filesBrowse files
committed
[Stopwatch] Add getRootSectionEvents method ROOT constant to Stopwatch
1 parent 5a00a8b commit fadeafd
Copy full SHA for fadeafd

File tree

2 files changed

+19
-2
lines changed
Filter options

2 files changed

+19
-2
lines changed

‎src/Symfony/Component/Stopwatch/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Stopwatch/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Stopwatch/Stopwatch.php
+14-2Lines changed: 14 additions & 2 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.