설명 없음

CliErrorRenderer.php 1.4KB

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