Skip to content

Commit 16c7140

Browse files
committed
Allows not to show the log id in the production view
1 parent 57e4940 commit 16c7140

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/ExceptionHandler.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ExceptionHandler
4040
protected Language $language;
4141
protected bool $testing = false;
4242
protected SearchEngines $searchEngines;
43+
protected bool $showLogId = true;
4344

4445
/**
4546
* ExceptionHandler constructor.
@@ -107,6 +108,29 @@ public function getLanguage() : Language
107108
return $this->language;
108109
}
109110

111+
/**
112+
* Sets whether the log id will be shown in the production view.
113+
*
114+
* @param bool $showLogId True to show. False to not show.
115+
*
116+
* @return static
117+
*/
118+
public function setShowLogId(bool $showLogId = true) : static
119+
{
120+
$this->showLogId = $showLogId;
121+
return $this;
122+
}
123+
124+
/**
125+
* Tells if the log id is being shown.
126+
*
127+
* @return bool
128+
*/
129+
public function isShowingLogId() : bool
130+
{
131+
return $this->showLogId;
132+
}
133+
110134
protected function validateView(string $file) : string
111135
{
112136
$realpath = \realpath($file);

src/Views/exceptions/production.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
<h1><?= $handler->getLanguage()->render('debug', 'exceptionTitle') ?></h1>
3131
<p><?= $handler->getLanguage()->render('debug', 'exceptionDescription') ?></p>
3232
<?php
33-
$log = $handler->getLogger()?->getLastLog();
34-
if ($log) {
35-
echo '<p>Log Id: ' . htmlentities($log->id) . '</p>';
33+
if ($handler->isShowingLogId()) {
34+
$log = $handler->getLogger()?->getLastLog();
35+
if ($log) {
36+
echo '<p>Log Id: ' . htmlentities($log->id) . '</p>';
37+
}
3638
}
3739
?>
3840
</body>

tests/ExceptionHandlerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ public function testErrorHandler(int $error, string $type) : void
218218
\trigger_error('Error message', $error);
219219
}
220220

221+
public function testShowLogId() : void
222+
{
223+
$exceptions = new ExceptionHandler();
224+
self::assertTrue($exceptions->isShowingLogId());
225+
$exceptions->setShowLogId(false);
226+
self::assertFalse($exceptions->isShowingLogId());
227+
}
228+
221229
/**
222230
* @return array<array<string>>
223231
*/

0 commit comments

Comments
 (0)