Skip to content

Commit 519b9e4

Browse files
committed
Enabler: Add override for change state during request
1 parent 3aa59a3 commit 519b9e4

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/DebugModeDetector.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ public function getEnabler(): DebugModeEnabler
2727

2828
public function isDebugMode(): bool
2929
{
30-
return $this->isDebugModeByEnabler() ?? $this->isDebugModeByEnv() ?? $this->isDebugModeByIp() ?? false;
30+
return $this->isDebugModeByEnabler()
31+
?? $this->isDebugModeByEnv()
32+
?? $this->isDebugModeByIp()
33+
?? false;
3134
}
3235

3336
/**

src/DebugModeEnabler.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class DebugModeEnabler
2727
/** @var string */
2828
private $tempDir;
2929

30+
/** @var bool|null */
31+
private $override;
32+
3033
public function __construct(string $tempDir)
3134
{
3235
$this->tempDir = $tempDir;
@@ -51,6 +54,8 @@ public function activate(bool $isDebug): void
5154
'samesite' => 'Strict',
5255
]
5356
);
57+
58+
$this->override = $isDebug;
5459
}
5560

5661

@@ -72,9 +77,27 @@ public function deactivate(): void
7277
'samesite' => 'Strict',
7378
]
7479
);
80+
81+
$this->override = null;
82+
}
83+
84+
public function override(bool $isDebug): void
85+
{
86+
$this->override = $isDebug;
7587
}
7688

7789
public function isDebug(): ?bool
90+
{
91+
return $this->isDebugByOverride()
92+
?? $this->isDebugByToken();
93+
}
94+
95+
private function isDebugByOverride(): ?bool
96+
{
97+
return $this->override;
98+
}
99+
100+
private function isDebugByToken(): ?bool
78101
{
79102
$tokenName = $this->getTokenName();
80103

0 commit comments

Comments
 (0)