|
21 | 21 | * ExceptionController.
|
22 | 22 | *
|
23 | 23 | * @author Fabien Potencier <fabien@symfony.com>
|
| 24 | + * @author Matthias Pigulla <mp@webfactory.de> |
24 | 25 | */
|
25 | 26 | class ExceptionController
|
26 | 27 | {
|
@@ -48,18 +49,24 @@ public function showAction(Request $request, FlattenException $exception, DebugL
|
48 | 49 | {
|
49 | 50 | $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
|
50 | 51 |
|
51 |
| - $code = $exception->getStatusCode(); |
| 52 | + return $this->createResponse($request, $exception, $this->debug, $logger, $currentContent); |
| 53 | + } |
52 | 54 |
|
53 |
| - return new Response($this->twig->render( |
54 |
| - $this->findTemplate($request, $request->getRequestFormat(), $code, $this->debug), |
55 |
| - array( |
56 |
| - 'status_code' => $code, |
57 |
| - 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', |
58 |
| - 'exception' => $exception, |
59 |
| - 'logger' => $logger, |
60 |
| - 'currentContent' => $currentContent, |
61 |
| - ) |
62 |
| - )); |
| 55 | + /** |
| 56 | + * Displays the error page for arbitrary status codes and formats. |
| 57 | + * |
| 58 | + * @param Request $request The request |
| 59 | + * @param int $code The HTTP status code to show the error page for. |
| 60 | + * |
| 61 | + * @return Response |
| 62 | + * |
| 63 | + * @throws \InvalidArgumentException When the error template does not exist |
| 64 | + */ |
| 65 | + public function testErrorPageAction(Request $request, $code) |
| 66 | + { |
| 67 | + $exception = FlattenException::create(new \Exception("Something has intentionally gone wrong."), $code); |
| 68 | + |
| 69 | + return $this->createResponse($request, $exception, false); |
63 | 70 | }
|
64 | 71 |
|
65 | 72 | /**
|
@@ -130,4 +137,29 @@ protected function templateExists($template)
|
130 | 137 |
|
131 | 138 | return false;
|
132 | 139 | }
|
| 140 | + |
| 141 | + /** |
| 142 | + * @param Request $request |
| 143 | + * @param FlattenException $exception |
| 144 | + * @param bool $debug |
| 145 | + * @param DebugLoggerInterface $logger |
| 146 | + * @param string $currentContent |
| 147 | + * |
| 148 | + * @return Response |
| 149 | + */ |
| 150 | + protected function createResponse(Request $request, FlattenException $exception, $debug, DebugLoggerInterface $logger = null, $currentContent = '') |
| 151 | + { |
| 152 | + $code = $exception->getStatusCode(); |
| 153 | + |
| 154 | + return new Response($this->twig->render( |
| 155 | + $this->findTemplate($request, $request->getRequestFormat(), $code, $debug), |
| 156 | + array( |
| 157 | + 'status_code' => $code, |
| 158 | + 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', |
| 159 | + 'exception' => $exception, |
| 160 | + 'logger' => $logger, |
| 161 | + 'currentContent' => $currentContent, |
| 162 | + ) |
| 163 | + )); |
| 164 | + } |
133 | 165 | }
|
0 commit comments