[Debug] made the exception handler independant of HttpFoundation
This commit is contained in:
parent
2b305c21d8
commit
946bfb2180
@ -57,13 +57,46 @@ class ExceptionHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a Response for the given Exception.
|
* Sends a response for the given Exception.
|
||||||
|
*
|
||||||
|
* If you have the Symfony HttpFoundation component installed,
|
||||||
|
* this method will use it to create and send the response. If not,
|
||||||
|
* it will fallback to plain PHP functions.
|
||||||
*
|
*
|
||||||
* @param \Exception $exception An \Exception instance
|
* @param \Exception $exception An \Exception instance
|
||||||
|
*
|
||||||
|
* @see sendPhpResponse
|
||||||
|
* @see createResponse
|
||||||
*/
|
*/
|
||||||
public function handle(\Exception $exception)
|
public function handle(\Exception $exception)
|
||||||
{
|
{
|
||||||
$this->createResponse($exception)->send();
|
if (class_exists('Symfony\Component\HttpFoundation\Response')) {
|
||||||
|
$this->createResponse($exception)->send();
|
||||||
|
} else {
|
||||||
|
$this->sendPhpResponse($exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends the error associated with the given Exception as a plain PHP response.
|
||||||
|
*
|
||||||
|
* This method uses plain PHP functions like header() and echo to output
|
||||||
|
* the response.
|
||||||
|
*
|
||||||
|
* @param \Exception|FlattenException $exception An \Exception instance
|
||||||
|
*/
|
||||||
|
public function sendPhpResponse($exception)
|
||||||
|
{
|
||||||
|
if (!$exception instanceof FlattenException) {
|
||||||
|
$exception = FlattenException::create($exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
header(sprintf('HTTP/1.0 %s', $exception->getStatusCode()));
|
||||||
|
foreach ($exception->getHeaders() as $name => $value) {
|
||||||
|
header($name.': '.$value, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $this->decorate($this->getContent($exception), $this->getStylesheet($exception));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +27,9 @@ You can also use the tools individually:
|
|||||||
Not that the `Debug::enable()` call also registers the debug class loader from
|
Not that the `Debug::enable()` call also registers the debug class loader from
|
||||||
the Symfony ClassLoader component when available.
|
the Symfony ClassLoader component when available.
|
||||||
|
|
||||||
|
This component can optionally take advantage of the features of the HttpKernel
|
||||||
|
and HttpFoundation components.
|
||||||
|
|
||||||
Resources
|
Resources
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
@ -18,9 +18,15 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.3"
|
"php": ">=5.3.3"
|
||||||
},
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"symfony/http-kernel": "2.2.*",
|
||||||
|
"symfony/http-foundation": "2.2.*"
|
||||||
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
|
"symfony/http-foundation": "2.2.*",
|
||||||
|
"symfony/http-kernel": "2.2.*",
|
||||||
"symfony/class-loader": "2.2.*"
|
"symfony/class-loader": "2.2.*"
|
||||||
}
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": { "Symfony\\Component\\Debug\\": "" }
|
"psr-0": { "Symfony\\Component\\Debug\\": "" }
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user