Skip to content

Commit 47900b8

Browse files
committed
[HttpKernel] fixed regression caused by the previous commit
1 parent fbf19f0 commit 47900b8

File tree

2 files changed

+43
-44
lines changed

2 files changed

+43
-44
lines changed

src/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ public function createResponse($exception)
8989
*/
9090
public function getContent(FlattenException $exception)
9191
{
92-
if (!$this->debug) {
93-
return '';
94-
}
95-
9692
$title = '';
9793
switch ($exception->getStatusCode()) {
9894
case 404:
@@ -102,49 +98,52 @@ public function getContent(FlattenException $exception)
10298
$title = 'Whoops, looks like something went wrong.';
10399
}
104100

105-
try {
106-
$message = nl2br($exception->getMessage());
107-
$class = $this->abbrClass($exception->getClass());
108-
$count = count($exception->getAllPrevious());
109-
$content = '';
110-
foreach ($exception->toArray() as $position => $e) {
111-
$ind = $count - $position + 1;
112-
$total = $count + 1;
113-
$class = $this->abbrClass($e['class']);
114-
$message = nl2br($e['message']);
115-
$content .= sprintf(<<<EOF
116-
<div class="block_exception clear_fix">
117-
<h2><span>%d/%d</span> %s: %s</h2>
118-
</div>
119-
<div class="block">
120-
<ol class="traces list_exception">
101+
$content = '';
102+
if ($this->debug) {
103+
try {
104+
$message = nl2br($exception->getMessage());
105+
$class = $this->abbrClass($exception->getClass());
106+
$count = count($exception->getAllPrevious());
107+
$content = '';
108+
foreach ($exception->toArray() as $position => $e) {
109+
$ind = $count - $position + 1;
110+
$total = $count + 1;
111+
$class = $this->abbrClass($e['class']);
112+
$message = nl2br($e['message']);
113+
$content .= sprintf(<<<EOF
114+
<div class="block_exception clear_fix">
115+
<h2><span>%d/%d</span> %s: %s</h2>
116+
</div>
117+
<div class="block">
118+
<ol class="traces list_exception">
121119
122120
EOF
123-
, $ind, $total, $class, $message);
124-
foreach ($e['trace'] as $i => $trace) {
125-
$content .= ' <li>';
126-
if ($trace['function']) {
127-
$content .= sprintf('at %s%s%s(%s)', $this->abbrClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args']));
128-
}
129-
if (isset($trace['file']) && isset($trace['line'])) {
130-
if ($linkFormat = ini_get('xdebug.file_link_format')) {
131-
$link = str_replace(array('%f', '%l'), array($trace['file'], $trace['line']), $linkFormat);
132-
$content .= sprintf(' in <a href="%s" title="Go to source">%s line %s</a>', $link, $trace['file'], $trace['line']);
133-
} else {
134-
$content .= sprintf(' in %s line %s', $trace['file'], $trace['line']);
121+
, $ind, $total, $class, $message);
122+
foreach ($e['trace'] as $i => $trace) {
123+
$content .= ' <li>';
124+
if ($trace['function']) {
125+
$content .= sprintf('at %s%s%s(%s)', $this->abbrClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args']));
135126
}
127+
if (isset($trace['file']) && isset($trace['line'])) {
128+
if ($linkFormat = ini_get('xdebug.file_link_format')) {
129+
$link = str_replace(array('%f', '%l'), array($trace['file'], $trace['line']), $linkFormat);
130+
$content .= sprintf(' in <a href="%s" title="Go to source">%s line %s</a>', $link, $trace['file'], $trace['line']);
131+
} else {
132+
$content .= sprintf(' in %s line %s', $trace['file'], $trace['line']);
133+
}
134+
}
135+
$content .= "</li>\n";
136136
}
137-
$content .= "</li>\n";
138-
}
139137

140-
$content .= " </ol>\n</div>\n";
141-
}
142-
} catch (\Exception $e) {
143-
// something nasty happened and we cannot throw an exception anymore
144-
if ($this->debug) {
145-
$title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($exception), $exception->getMessage());
146-
} else {
147-
$title = 'Whoops, looks like something went wrong.';
138+
$content .= " </ol>\n</div>\n";
139+
}
140+
} catch (\Exception $e) {
141+
// something nasty happened and we cannot throw an exception anymore
142+
if ($this->debug) {
143+
$title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($exception), $exception->getMessage());
144+
} else {
145+
$title = 'Whoops, looks like something went wrong.';
146+
}
148147
}
149148
}
150149

src/Symfony/Component/HttpKernel/Tests/Debug/ExceptionHandlerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ public function testStatusCode()
4545

4646
$response = $handler->createResponse(new \RuntimeException('Foo'));
4747
$this->assertEquals('500', $response->getStatusCode());
48-
$this->assertContains('<title>Whoops, looks like something went wrong.</title>', $response->getContent());
48+
$this->assertContains('Whoops, looks like something went wrong.', $response->getContent());
4949

5050
$response = $handler->createResponse(new NotFoundHttpException('Foo'));
5151
$this->assertEquals('404', $response->getStatusCode());
52-
$this->assertContains('<title>Sorry, the page you are looking for could not be found.</title>', $response->getContent());
52+
$this->assertContains('Sorry, the page you are looking for could not be found.', $response->getContent());
5353
}
5454

5555
public function testHeaders()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy