Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\HttpKernel\DataCollector; Chris@0: Chris@0: use Symfony\Component\Debug\Exception\FlattenException; Chris@0: use Symfony\Component\HttpFoundation\Request; Chris@0: use Symfony\Component\HttpFoundation\Response; Chris@0: Chris@0: /** Chris@0: * ExceptionDataCollector. Chris@0: * Chris@0: * @author Fabien Potencier Chris@0: */ Chris@0: class ExceptionDataCollector extends DataCollector Chris@0: { Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function collect(Request $request, Response $response, \Exception $exception = null) Chris@0: { Chris@0: if (null !== $exception) { Chris@17: $this->data = [ Chris@0: 'exception' => FlattenException::create($exception), Chris@17: ]; Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public function reset() Chris@14: { Chris@17: $this->data = []; Chris@14: } Chris@14: Chris@14: /** Chris@0: * Checks if the exception is not null. Chris@0: * Chris@0: * @return bool true if the exception is not null, false otherwise Chris@0: */ Chris@0: public function hasException() Chris@0: { Chris@0: return isset($this->data['exception']); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the exception. Chris@0: * Chris@0: * @return \Exception The exception Chris@0: */ Chris@0: public function getException() Chris@0: { Chris@0: return $this->data['exception']; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the exception message. Chris@0: * Chris@0: * @return string The exception message Chris@0: */ Chris@0: public function getMessage() Chris@0: { Chris@0: return $this->data['exception']->getMessage(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the exception code. Chris@0: * Chris@0: * @return int The exception code Chris@0: */ Chris@0: public function getCode() Chris@0: { Chris@0: return $this->data['exception']->getCode(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the status code. Chris@0: * Chris@0: * @return int The status code Chris@0: */ Chris@0: public function getStatusCode() Chris@0: { Chris@0: return $this->data['exception']->getStatusCode(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the exception trace. Chris@0: * Chris@0: * @return array The exception trace Chris@0: */ Chris@0: public function getTrace() Chris@0: { Chris@0: return $this->data['exception']->getTrace(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getName() Chris@0: { Chris@0: return 'exception'; Chris@0: } Chris@0: }