Skip to content

Commit

Permalink
[Debug] made the exception handler independant of HttpFoundation
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Apr 7, 2013
1 parent 2b305c2 commit 946bfb2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
37 changes: 35 additions & 2 deletions src/Symfony/Component/Debug/ExceptionHandler.php
Expand Up @@ -57,13 +57,46 @@ public static function register($debug = true)
}

/**
* 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
*
* @see sendPhpResponse
* @see createResponse
*/
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));
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Debug/README.md
Expand Up @@ -27,6 +27,9 @@ You can also use the tools individually:
Not that the `Debug::enable()` call also registers the debug class loader from
the Symfony ClassLoader component when available.

This component can optionally take advantage of the features of the HttpKernel
and HttpFoundation components.

Resources
---------

Expand Down
8 changes: 7 additions & 1 deletion src/Symfony/Component/Debug/composer.json
Expand Up @@ -18,9 +18,15 @@
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"symfony/http-kernel": "2.2.*",
"symfony/http-foundation": "2.2.*"
},
"suggest": {
"symfony/http-foundation": "2.2.*",
"symfony/http-kernel": "2.2.*",
"symfony/class-loader": "2.2.*"
}
},
"autoload": {
"psr-0": { "Symfony\\Component\\Debug\\": "" }
},
Expand Down

0 comments on commit 946bfb2

Please sign in to comment.