This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/HttpKernel/DataCollector/ExceptionDataCollector.php
Fabien Potencier 662a4b3740 removed the status message from HttpException, changed the signature so that most useful arguments are first, fixed many small problems introduced with previous HTTP exception refactoring
Quote from HTTP (bis) spec (Part 2 - 5.1.1):

The Reason Phrase exists for the
sole purpose of providing a textual description associated with the
numeric status code, out of deference to earlier Internet application
protocols that were more frequently used with interactive text
clients.  A client SHOULD ignore the content of the Reason Phrase.
2011-03-23 16:11:54 +01:00

111 lines
2.4 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpKernel\DataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\FlattenException;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
/**
* ExceptionDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class ExceptionDataCollector extends DataCollector
{
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
if (null !== $exception) {
$flattenException = FlattenException::create($exception);
if ($exception instanceof HttpExceptionInterface) {
$flattenException->setStatusCode($exception->getStatusCode());
}
$this->data = array(
'exception' => $flattenException,
);
}
}
/**
* Checks if the exception is not null.
*
* @return Boolean true if the exception is not null, false otherwise
*/
public function hasException()
{
return isset($this->data['exception']);
}
/**
* Gets the exception.
*
* @return \Exception The exception
*/
public function getException()
{
return $this->data['exception'];
}
/**
* Gets the exception message.
*
* @return string The exception message
*/
public function getMessage()
{
return $this->data['exception']->getMessage();
}
/**
* Gets the exception code.
*
* @return integer The exception code
*/
public function getCode()
{
return $this->data['exception']->getCode();
}
/**
* Gets the status code.
*
* @return integer The status code
*/
public function getStatusCode()
{
return $this->data['exception']->getStatusCode();
}
/**
* Gets the exception trace.
*
* @return array The exception trace
*/
public function getTrace()
{
return $this->data['exception']->getTrace();
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'exception';
}
}