Drupal investigation

ExceptionDataCollector.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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\Debug\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. class ExceptionDataCollector extends DataCollector
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function collect(Request $request, Response $response, \Exception $exception = null)
  25. {
  26. if (null !== $exception) {
  27. $this->data = array(
  28. 'exception' => FlattenException::create($exception),
  29. );
  30. }
  31. }
  32. /**
  33. * Checks if the exception is not null.
  34. *
  35. * @return bool true if the exception is not null, false otherwise
  36. */
  37. public function hasException()
  38. {
  39. return isset($this->data['exception']);
  40. }
  41. /**
  42. * Gets the exception.
  43. *
  44. * @return \Exception The exception
  45. */
  46. public function getException()
  47. {
  48. return $this->data['exception'];
  49. }
  50. /**
  51. * Gets the exception message.
  52. *
  53. * @return string The exception message
  54. */
  55. public function getMessage()
  56. {
  57. return $this->data['exception']->getMessage();
  58. }
  59. /**
  60. * Gets the exception code.
  61. *
  62. * @return int The exception code
  63. */
  64. public function getCode()
  65. {
  66. return $this->data['exception']->getCode();
  67. }
  68. /**
  69. * Gets the status code.
  70. *
  71. * @return int The status code
  72. */
  73. public function getStatusCode()
  74. {
  75. return $this->data['exception']->getStatusCode();
  76. }
  77. /**
  78. * Gets the exception trace.
  79. *
  80. * @return array The exception trace
  81. */
  82. public function getTrace()
  83. {
  84. return $this->data['exception']->getTrace();
  85. }
  86. /**
  87. * {@inheritdoc}
  88. */
  89. public function getName()
  90. {
  91. return 'exception';
  92. }
  93. }