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

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.  * ExceptionDataCollector.
  16.  *
  17.  * @author Fabien Potencier <fabien@symfony.com>
  18.  *
  19.  * @final since Symfony 4.4
  20.  */
  21. class ExceptionDataCollector extends DataCollector
  22. {
  23.     /**
  24.      * {@inheritdoc}
  25.      *
  26.      * @param \Throwable|null $exception
  27.      */
  28.     public function collect(Request $requestResponse $response/*, \Throwable $exception = null*/)
  29.     {
  30.         $exception < \func_num_args() ? func_get_arg(2) : null;
  31.         if (null !== $exception) {
  32.             $this->data = [
  33.                 'exception' => FlattenException::createFromThrowable($exception),
  34.             ];
  35.         }
  36.     }
  37.     /**
  38.      * {@inheritdoc}
  39.      */
  40.     public function reset()
  41.     {
  42.         $this->data = [];
  43.     }
  44.     /**
  45.      * Checks if the exception is not null.
  46.      *
  47.      * @return bool true if the exception is not null, false otherwise
  48.      */
  49.     public function hasException()
  50.     {
  51.         return isset($this->data['exception']);
  52.     }
  53.     /**
  54.      * Gets the exception.
  55.      *
  56.      * @return \Exception|FlattenException
  57.      */
  58.     public function getException()
  59.     {
  60.         return $this->data['exception'];
  61.     }
  62.     /**
  63.      * Gets the exception message.
  64.      *
  65.      * @return string The exception message
  66.      */
  67.     public function getMessage()
  68.     {
  69.         return $this->data['exception']->getMessage();
  70.     }
  71.     /**
  72.      * Gets the exception code.
  73.      *
  74.      * @return int The exception code
  75.      */
  76.     public function getCode()
  77.     {
  78.         return $this->data['exception']->getCode();
  79.     }
  80.     /**
  81.      * Gets the status code.
  82.      *
  83.      * @return int The status code
  84.      */
  85.     public function getStatusCode()
  86.     {
  87.         return $this->data['exception']->getStatusCode();
  88.     }
  89.     /**
  90.      * Gets the exception trace.
  91.      *
  92.      * @return array The exception trace
  93.      */
  94.     public function getTrace()
  95.     {
  96.         return $this->data['exception']->getTrace();
  97.     }
  98.     /**
  99.      * {@inheritdoc}
  100.      */
  101.     public function getName()
  102.     {
  103.         return 'exception';
  104.     }
  105. }