From 55bed307f1e67eda91c50819a00ec3ee42b83db5 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 10 Dec 2010 09:16:42 +0100 Subject: [PATCH] removed HttpException base class, refactored FlattenException class --- .../Controller/ExceptionController.php | 21 +++++++++--- .../Resources/views/Exception/error.css.twig | 2 +- .../Resources/views/Exception/error.js.twig | 2 +- .../Resources/views/Exception/error.json.twig | 2 +- .../Resources/views/Exception/error.twig | 2 +- .../Resources/views/Exception/error.txt.twig | 2 +- .../Resources/views/Exception/error.xml.twig | 2 +- .../Resources/views/Exception/exception.twig | 2 +- .../views/Exception/exception.txt.twig | 2 +- .../views/Exception/exception.xml.twig | 2 +- .../Resources/views/Exception/layout.twig | 2 +- .../HttpKernel/Exception/FlattenException.php | 21 ------------ .../HttpKernel/Exception/HttpException.php | 32 ------------------- .../Exception/NotFoundHttpException.php | 2 +- 14 files changed, 28 insertions(+), 68 deletions(-) delete mode 100644 src/Symfony/Component/HttpKernel/Exception/HttpException.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/ExceptionController.php index 94ed41f18e..2d5bea26b6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/ExceptionController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/ExceptionController.php @@ -5,6 +5,7 @@ namespace Symfony\Bundle\FrameworkBundle\Controller; use Symfony\Component\DependencyInjection\ContainerAware; use Symfony\Component\HttpKernel\Exception\FlattenException; use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; +use Symfony\Component\HttpFoundation\Response; /* * This file is part of the Symfony framework. @@ -40,9 +41,7 @@ class ExceptionController extends ContainerAware $currentContent .= ob_get_clean(); } - if ('Symfony\Component\Security\Exception\AccessDeniedException' === $exception->getClass()) { - $exception->setStatusCode($exception->getCode()); - } + $code = $this->getStatusCode($exception); $template = $this->container->get('kernel')->isDebug() ? 'exception' : 'error'; if ($this->container->get('kernel')->isDebug() && 'html' == $format) { @@ -58,14 +57,28 @@ class ExceptionController extends ContainerAware $response = $templating->renderResponse( $template, array( + 'status_code' => $code, + 'status_text' => Response::$statusTexts[$code], 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent, ) ); - $response->setStatusCode($exception->getStatusCode()); + $response->setStatusCode($code); return $response; } + + protected function getStatusCode(FlattenException $exception) + { + switch ($exception->getClass()) { + case 'Symfony\Component\Security\Exception\AccessDeniedException': + return 403; + case 'Symfony\Component\HttpKernel\Exception\HttpNotFoundException': + return 404; + default: + return 500; + } + } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.css.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.css.twig index 8dceb6d31d..d8a9369487 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.css.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.css.twig @@ -1,4 +1,4 @@ /* -{{ exception.statuscode }} {{ exception.statustext }} +{{ status_code }} {{ status_text }} */ diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.js.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.js.twig index 8dceb6d31d..d8a9369487 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.js.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.js.twig @@ -1,4 +1,4 @@ /* -{{ exception.statuscode }} {{ exception.statustext }} +{{ status_code }} {{ status_text }} */ diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.json.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.json.twig index 5067d96406..4ec46641b3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.json.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.json.twig @@ -1 +1 @@ -{{ ['error': ['code': exception.statuscode, 'message': exception.statustext]]|json_encode }} +{{ ['error': ['code': status_code, 'message': status_text]]|json_encode }} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.twig index 55fac38bf4..6cd36bb11a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.twig @@ -5,7 +5,7 @@

Oops! An Error Occurred

-

The server returned a "{{ exception.statuscode }} {{ exception.statustext }}".

+

The server returned a "{{ status_code }} {{ status_text }}".

Something is broken. Please e-mail us at [email] and let us know diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.txt.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.txt.twig index 944cdc9eb9..b621b089c8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.txt.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.txt.twig @@ -1,7 +1,7 @@ Oops! An Error Occurred ======================= -The server returned a "{{ exception.statuscode }} {{ exception.statustext }}". +The server returned a "{{ status_code }} {{ status_text }}". Please e-mail us at [email] and let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.xml.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.xml.twig index 505dc1e8b1..5ea8f565ab 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.xml.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.xml.twig @@ -1,3 +1,3 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.twig index 1456f247ec..a4a82a6a46 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.twig @@ -5,7 +5,7 @@

{{ exception.message|replace(["\n": '
'])|format_file_from_text }}

-

{{ exception.statuscode }} {{ exception.statustext }} - {{ exception.class|abbr_class }}

+

{{ status_code }} {{ status_text }} - {{ exception.class|abbr_class }}

{% set previous_count = exception.previouses|length %} {% if previous_count %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.txt.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.txt.twig index 7f7ffd8c5a..cb64c24c07 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.txt.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.txt.twig @@ -1,4 +1,4 @@ -[exception] {{ exception.statuscode ~ ' | ' ~ exception.statustext ~ ' | ' ~ exception.class }} +[exception] {{ status_code ~ ' | ' ~ status_text ~ ' | ' ~ exception.class }} [message] {{ exception.message }} {% for i, e in exception.toarray %} [{{ i + 1 }}] {{ e.class }}: {{ e.message }} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.xml.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.xml.twig index e2cb5ebeb3..ca104e7006 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.xml.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.xml.twig @@ -1,6 +1,6 @@ - + {% for e in exception.toarray %} {% include 'FrameworkBundle:Exception:traces.twig' with ['exception': e] only %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/layout.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/layout.twig index b8eeb9c332..00d2026b11 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/layout.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/layout.twig @@ -2,7 +2,7 @@ - {{ exception.message }} ({{ exception.statuscode }} {{ exception.statustext }}) + {{ exception.message }} ({{ status_code }} {{ status_text }})