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

Open in your IDE?
  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.     /**
  22.      * {@inheritdoc}
  23.      */
  24.     public function collect(Request $requestResponse $response\Throwable $exception null)
  25.     {
  26.         if (null !== $exception) {
  27.             $this->data = [
  28.                 'exception' => FlattenException::createFromThrowable($exception),
  29.             ];
  30.         }
  31.     }
  32.     /**
  33.      * {@inheritdoc}
  34.      */
  35.     public function reset()
  36.     {
  37.         $this->data = [];
  38.     }
  39.     public function hasException(): bool
  40.     {
  41.         return isset($this->data['exception']);
  42.     }
  43.     /**
  44.      * @return \Exception|FlattenException
  45.      */
  46.     public function getException()
  47.     {
  48.         return $this->data['exception'];
  49.     }
  50.     public function getMessage(): string
  51.     {
  52.         return $this->data['exception']->getMessage();
  53.     }
  54.     public function getCode(): int
  55.     {
  56.         return $this->data['exception']->getCode();
  57.     }
  58.     public function getStatusCode(): int
  59.     {
  60.         return $this->data['exception']->getStatusCode();
  61.     }
  62.     public function getTrace(): array
  63.     {
  64.         return $this->data['exception']->getTrace();
  65.     }
  66.     /**
  67.      * {@inheritdoc}
  68.      */
  69.     public function getName(): string
  70.     {
  71.         return 'exception';
  72.     }
  73. }