vendor/symfony/http-kernel/DataCollector/ExceptionDataCollector.php line 25

  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\HttpKernel\DataCollector;
  11. use Symfony\Component\ErrorHandler\Exception\FlattenException;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. /**
  15.  * @author Fabien Potencier <fabien@symfony.com>
  16.  *
  17.  * @final
  18.  */
  19. class ExceptionDataCollector extends DataCollector
  20. {
  21.     public function collect(Request $requestResponse $response\Throwable $exception null)
  22.     {
  23.         if (null !== $exception) {
  24.             $this->data = [
  25.                 'exception' => FlattenException::createFromThrowable($exception),
  26.             ];
  27.         }
  28.     }
  29.     public function reset()
  30.     {
  31.         $this->data = [];
  32.     }
  33.     public function hasException(): bool
  34.     {
  35.         return isset($this->data['exception']);
  36.     }
  37.     public function getException(): \Exception|FlattenException
  38.     {
  39.         return $this->data['exception'];
  40.     }
  41.     public function getMessage(): string
  42.     {
  43.         return $this->data['exception']->getMessage();
  44.     }
  45.     public function getCode(): int
  46.     {
  47.         return $this->data['exception']->getCode();
  48.     }
  49.     public function getStatusCode(): int
  50.     {
  51.         return $this->data['exception']->getStatusCode();
  52.     }
  53.     public function getTrace(): array
  54.     {
  55.         return $this->data['exception']->getTrace();
  56.     }
  57.     public function getName(): string
  58.     {
  59.         return 'exception';
  60.     }
  61. }