/
FallbackHtmlDisplayer.php
61 lines (49 loc) · 1.65 KB
/
FallbackHtmlDisplayer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types=1);
namespace Snicco\Component\Psr7ErrorHandler\Displayer;
use RuntimeException;
use Snicco\Component\Psr7ErrorHandler\Information\ExceptionInformation;
use function dirname;
use function htmlentities;
use function str_replace;
use const ENT_QUOTES;
final class FallbackHtmlDisplayer implements ExceptionDisplayer
{
public function display(ExceptionInformation $exception_information): string
{
$content = @file_get_contents($file = dirname(__DIR__, 2) . '/resources/error.fallback.html');
if (false === $content) {
// @codeCoverageIgnoreStart
throw new RuntimeException(sprintf('Cant read fallback error template at location [%s].', $file));
// @codeCoverageIgnoreEnd
}
$content = str_replace('{{title}}', htmlentities($exception_information->safeTitle(), ENT_QUOTES), $content);
$content = str_replace(
'{{details}}',
htmlentities($exception_information->safeDetails(), ENT_QUOTES),
$content
);
$content = str_replace(
'{{identifier}}',
htmlentities($exception_information->identifier(), ENT_QUOTES),
$content
);
return str_replace(
'{{status}}',
htmlentities((string) $exception_information->statusCode(), ENT_QUOTES),
$content
);
}
public function supportedContentType(): string
{
return 'text/html';
}
public function isVerbose(): bool
{
return false;
}
public function canDisplay(ExceptionInformation $exception_information): bool
{
return true;
}
}