| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the Symfony package.
|
|
|
5 |
*
|
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
7 |
*
|
|
|
8 |
* For the full copyright and license information, please view the LICENSE
|
|
|
9 |
* file that was distributed with this source code.
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\ErrorHandler\ErrorRenderer;
|
|
|
13 |
|
|
|
14 |
use Symfony\Component\ErrorHandler\Exception\FlattenException;
|
|
|
15 |
use Symfony\Component\VarDumper\Cloner\VarCloner;
|
|
|
16 |
use Symfony\Component\VarDumper\Dumper\CliDumper;
|
|
|
17 |
|
|
|
18 |
// Help opcache.preload discover always-needed symbols
|
|
|
19 |
class_exists(CliDumper::class);
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* @author Nicolas Grekas <p@tchwork.com>
|
|
|
23 |
*/
|
|
|
24 |
class CliErrorRenderer implements ErrorRendererInterface
|
|
|
25 |
{
|
|
|
26 |
public function render(\Throwable $exception): FlattenException
|
|
|
27 |
{
|
|
|
28 |
$cloner = new VarCloner();
|
|
|
29 |
$dumper = new class() extends CliDumper {
|
|
|
30 |
protected function supportsColors(): bool
|
|
|
31 |
{
|
|
|
32 |
$outputStream = $this->outputStream;
|
|
|
33 |
$this->outputStream = fopen('php://stdout', 'w');
|
|
|
34 |
|
|
|
35 |
try {
|
|
|
36 |
return parent::supportsColors();
|
|
|
37 |
} finally {
|
|
|
38 |
$this->outputStream = $outputStream;
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
};
|
|
|
42 |
|
|
|
43 |
return FlattenException::createFromThrowable($exception)
|
|
|
44 |
->setAsString($dumper->dump($cloner->cloneVar($exception), true));
|
|
|
45 |
}
|
|
|
46 |
}
|