8000 Added Profiler::isEnabled method. · symfony/symfony@c3b08e8 · GitHub
[go: up one dir, main page]

Skip to content

Commit c3b08e8

Browse files
committed
Added Profiler::isEnabled method.
1 parent 43e3e71 commit c3b08e8

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add `BackedEnumValueResolver` to resolve backed enum cases from request attributes in controller arguments
8+
* Add `Profiler::isEnabled()` so collaborating collector services may elect to omit themselves.
89

910
6.0
1011
---

src/Symfony/Component/HttpKernel/Profiler/Profiler.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class Profiler implements ResetInterface
3434
private array $collectors = [];
3535

3636
private ?LoggerInterface $logger;
37-
private bool $initiallyEnabled = true;
38-
private bool $enabled = true;
37+
private bool $initiallyEnabled;
38+
private bool $enabled;
3939

4040
public function __construct(ProfilerStorageInterface $storage, LoggerInterface $logger = null, bool $enable = true)
4141
{
@@ -60,6 +60,16 @@ public function enable()
6060
$this->enabled = true;
6161
}
6262

63+
/**
64+
* Gets a value indicating whether the profiler is enabled.
65+
*
66+
* @return bool True if the profiler is enabled, otherwise false
67+
*/
68+
public function isEnabled(): bool
69+
{
70+
return $this->enabled;
71+
}
72+
6373
/**
6474
* Loads the Profile for the given Response.
6575
*/

src/Symfony/Component/HttpKernel/Tests/Profiler/ProfilerTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,28 @@ public function testFindWorksWithStatusCode()
8383
$this->assertCount(0, $profiler->find(null, null, null, null, null, null, '204'));
8484
}
8585

86+
public function testIsInitiallyEnabled()
87+
{
88+
self::assertTrue((new Profiler($this->storage))->isEnabled());
89+
}
90+
91+
public function testDisable()
92+
{
93+
$profiler = new Profiler($this->storage);
94+
$profiler->disable();
95+
96+
self::assertFalse($profiler->isEnabled());
97+
}
98+
99+
public function testEnable()
100+
{
101+
$profiler = new Profiler($this->storage);
102+
$profiler->disable();
103+
$profiler->enable();
104+
105+
self::assertTrue($profiler->isEnabled());
106+
}
107+
86108
protected function setUp(): void
87109
{
88110
$this->tmp = tempnam(sys_get_temp_dir(), 'sf_profiler');

0 commit comments

Comments
 (0)
0