8000 removed HttpException base class, refactored FlattenException class · symfony/symfony@55bed30 · GitHub
[go: up one dir, main page]

Skip to content

Commit 55bed30

Browse files
committed
removed HttpException base class, refactored FlattenException class
1 parent 23fbd87 commit 55bed30

File tree

14 files changed

+28
-68
lines changed

14 files changed

+28
-68
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/ExceptionController.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Symfony\Component\DependencyInjection\ContainerAware;
66
use Symfony\Component\HttpKernel\Exception\FlattenException;
77
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
8+
use Symfony\Component\HttpFoundation\Response;
89

910
/*
1011
* This file is part of the Symfony framework.
@@ -40,9 +41,7 @@ public function exceptionAction(FlattenException $exception, DebugLoggerInterfac
4041
$currentContent .= ob_get_clean();
4142
}
4243

43-
if ('Symfony\Component\Security\Exception\AccessDeniedException' === $exception->getClass()) {
44-
$exception->setStatusCode($exception->getCode());
45-
}
44+
$code = $this->getStatusCode($exception);
4645

4746
$template = $this->container->get('kernel')->isDebug() ? 'exception' : 'error';
4847
if ($this->container->get('kernel')->isDebug() && 'html' == $format) {
@@ -58,14 +57,28 @@ public function exceptionAction(FlattenException $exception, DebugLoggerInterfac
5857
$response = $templating->renderResponse(
5958
$template,
6059
array(
60+
'status_code' => $code,
61+
'status_text' => Response::$statusTexts[$code],
6162
'exception' => $exception,
6263
'logger' => $logger,
6364
'currentContent' => $currentContent,
6465
)
6566
);
6667

67-
$response->setStatusCode($exception->getStatusCode());
68+
$response->setStatusCode($code);
6869

6970
return $response;
7071
}
72+
73+
protected function getStatusCode(FlattenException $exception)
74+
{
75+
switch ($exception->getClass()) {
76+
case 'Symfony\Component\Security\Exception\AccessDeniedException':
77+
return 403;
78+
case 'Symfony\Component\HttpKernel\Exception\HttpNotFoundException':
79+
return 404;
80+
default:
81+
return 500;
82+
}
83+
}
7184
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/*
2-
{{ exception.statuscode }} {{ exception.statustext }}
2+
{{ status_code }} {{ status_text }}
33

44
*/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/*
2-
{{ exception.statuscode }} {{ exception.statustext }}
2+
{{ status_code }} {{ status_text }}
33

44
*/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{ ['error': ['code': exception.statuscode, 'message': exception.statustext]]|json_encode }}
1+
{{ ['error': ['code': status_code, 'message': status_text]]|json_encode }}

src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</head>
66
<body>
77
<h1>Oops! An Error Occurred</h1>
8-
<h2>The server returned a "{{ exception.statuscode }} {{ exception.statustext }}".</h2>
8+
<h2>The server returned a "{{ status_code }} {{ status_text }}".</h2>
99

1010
<div>
1111
Something is broken. Please e-mail us at [email] and let us know

src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.txt.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Oops! An Error Occurred
22
=======================
33

4-
The server returned a "{{ exception.statuscode }} {{ exception.statustext }}".
4+
The server returned a "{{ status_code }} {{ status_text }}".
55

66
Please e-mail us at [email] and let us know what you were doing when this
77
error occurred. We will fix it as soon as possible. Sorry for any
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?xml version="1.0" encoding="{{ _charset }}" ?>
22

3-
<error code="{{ exception.statuscode }}" message="{{ exception.statustext }}" />
3+
<error code="{{ status_code }}" message="{{ status_text }}" />

src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</div>
66
<div style="float: left; width: 600px">
77
<h1>{{ exception.message|replace(["\n": '<br />'])|format_file_from_text }}</h1>
8-
<h2><strong>{{ exception.statuscode }}</strong> {{ exception.statustext }} - {{ exception.class|abbr_class }}</h2>
8+
<h2><strong>{{ status_code }}</strong> {{ status_text }} - {{ exception.class|abbr_class }}</h2>
99

1010
{% set previous_count = exception.previouses|length %}
1111
{% if previous_count %}

src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.txt.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[exception] {{ exception.statuscode ~ ' | ' ~ exception.statustext ~ ' | ' ~ exception.class }}
1+
[exception] {{ status_code ~ ' | ' ~ status_text ~ ' | ' ~ exception.class }}
22
[message] {{ exception.message }}
33
{% for i, e in exception.toarray %}
44
[{{ i + 1 }}] {{ e.class }}: {{ e.message }}

src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.xml.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="{{ _charset }}" ?>
22

3-
<error code="{{ exception.statuscode }}" message="{{ exception.statustext }}">
3+
<error code="{{ status_code }}" message="{{ status_text }}">
44
{% for e in exception.toarray %}
55
<exception class="{{ e.class }}" message="{{ e.message }}">
66
{% include 'FrameworkBundle:Exception:traces.twig' with ['exception': e] only %}

src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/layout.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset={{ _charset }}"/>
5-
<title>{{ exception.message }} ({{ exception.statuscode }} {{ exception.statustext }})</title>
5+
<title>{{ exception.message }} ({{ status_code }} {{ status_text }})</title>
66
<style type="text/css">
77
html { background: #eee }
88
body { font: 11px Verdana, Arial, sans-serif; color: #333 }

src/Symfony/Component/HttpKernel/Exception/FlattenException.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace Symfony\Component\HttpKernel\Exception;
44

5-
use Symfony\Component\HttpFoundation\Response;
6-
use Symfony\Component\HttpKernel\Exception\HttpException;
7-
85
/*
96
* This file is part of the Symfony framework.
107
*
@@ -28,7 +25,6 @@ class FlattenException
2825
protected $previous;
2926
protected $trace;
3027
protected $class;
31-
protected $status;
3228

3329
static public function create(\Exception $exception)
3430
{
@@ -40,7 +36,6 @@ static public function create(\Exception $exception)
4036
if ($exception->getPrevious()) {
4137
$e->setPrevious(static::create($exception->getPrevious()));
4238
}
43-
$e->setStatusCode($exception instanceof HttpException ? $exception->getCode() : 500);
4439

4540
return $e;
4641
}
@@ -50,7 +45,6 @@ public function toArray()
5045
$exceptions = array();
5146
foreach (array_merge(array($this), $this->getPreviouses()) as $exception) {
5247
$exceptions[] = array(
53-
'code' => $exception->getStatusCode(),
5448
'message' => $exception->getMessage(),
5549
'class' => $exception->getClass(),
5650
'trace' => $exception->getTrace(),
@@ -60,21 +54,6 @@ public function toArray()
6054
return $exceptions;
6155
}
6256

63-
public function getStatusCode()
64-
{
< 93C6 div aria-hidden="true" style="left:-2px" class="position-absolute top-0 d-flex user-select-none DiffLineTableCellParts-module__in-progress-comment-indicator--hx3m3">
65-
return $this->status;
66-
}
67-
68-
public function setStatusCode($status)
69-
{
70-
$this->status = $status;
71-
}
72-
73-
public function getStatusText()
74-
{
75-
return Response::$statusTexts[$this->getStatusCode()];
76-
}
77-
7857
public function getClass()
7958
{
8059
return $this->class;

src/Symfony/Component/HttpKernel/Exception/HttpException.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/Symfony/Component/HttpKernel/Exception/NotFoundHttpException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
1818
*/
19-
class NotFoundHttpException extends HttpException
19+
class NotFoundHttpException extends \RuntimeException
2020
{
2121
public function __construct($message = 'Not Found', \Exception $previous = null)
2222
{

0 commit comments

Comments
 (0)
0