1441 |
ariadna |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* Slim Framework (https://slimframework.com)
|
|
|
5 |
*
|
|
|
6 |
* @license https://github.com/slimphp/Slim/blob/4.x/LICENSE.md (MIT License)
|
|
|
7 |
*/
|
|
|
8 |
|
|
|
9 |
declare(strict_types=1);
|
|
|
10 |
|
|
|
11 |
namespace Slim\Error\Renderers;
|
|
|
12 |
|
|
|
13 |
use Slim\Error\AbstractErrorRenderer;
|
|
|
14 |
use Throwable;
|
|
|
15 |
|
|
|
16 |
use function get_class;
|
|
|
17 |
use function htmlentities;
|
|
|
18 |
use function sprintf;
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
* Default Slim application Plain Text Error Renderer
|
|
|
22 |
*/
|
|
|
23 |
class PlainTextErrorRenderer extends AbstractErrorRenderer
|
|
|
24 |
{
|
|
|
25 |
public function __invoke(Throwable $exception, bool $displayErrorDetails): string
|
|
|
26 |
{
|
|
|
27 |
$text = "{$this->getErrorTitle($exception)}\n";
|
|
|
28 |
|
|
|
29 |
if ($displayErrorDetails) {
|
|
|
30 |
$text .= $this->formatExceptionFragment($exception);
|
|
|
31 |
|
|
|
32 |
while ($exception = $exception->getPrevious()) {
|
|
|
33 |
$text .= "\nPrevious Error:\n";
|
|
|
34 |
$text .= $this->formatExceptionFragment($exception);
|
|
|
35 |
}
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
return $text;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
private function formatExceptionFragment(Throwable $exception): string
|
|
|
42 |
{
|
|
|
43 |
$text = sprintf("Type: %s\n", get_class($exception));
|
|
|
44 |
|
|
|
45 |
$code = $exception->getCode();
|
|
|
46 |
/** @var int|string $code */
|
|
|
47 |
$text .= sprintf("Code: %s\n", $code);
|
|
|
48 |
|
|
|
49 |
$text .= sprintf("Message: %s\n", htmlentities($exception->getMessage()));
|
|
|
50 |
|
|
|
51 |
$text .= sprintf("File: %s\n", $exception->getFile());
|
|
|
52 |
|
|
|
53 |
$text .= sprintf("Line: %s\n", $exception->getLine());
|
|
|
54 |
|
|
|
55 |
$text .= sprintf('Trace: %s', $exception->getTraceAsString());
|
|
|
56 |
|
|
|
57 |
return $text;
|
|
|
58 |
}
|
|
|
59 |
}
|