Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[Debug] made the exception handler independant of HttpFoundation

  • Loading branch information...
commit 946bfb218023c999c3f9239d3dae6d30765e08a1 1 parent 2b305c2
@fabpot authored
View
37 src/Symfony/Component/Debug/ExceptionHandler.php
@@ -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));
}
/**
View
3  src/Symfony/Component/Debug/README.md
@@ -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
---------
View
8 src/Symfony/Component/Debug/composer.json
@@ -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\\": "" }
},
Please sign in to comment.
Something went wrong with that request. Please try again.