|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\TwigBundle\Controller\ExceptionController as BaseController; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
7
|
|
|
use Symfony\Component\HttpKernel\Exception\FlattenException; |
|
8
|
|
|
|
|
9
|
|
|
class ExceptionController extends BaseController |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @Route("/erreur", name="error") |
|
13
|
|
|
*/ |
|
14
|
|
|
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null) |
|
15
|
|
|
{ |
|
16
|
|
|
$currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1)); |
|
17
|
|
|
$showException = $request->attributes->get('showException', $this->debug); // As opposed to an additional parameter, this maintains BC |
|
18
|
|
|
|
|
19
|
|
|
$code = $exception->getStatusCode(); |
|
20
|
|
|
|
|
21
|
|
|
return new Response($this->twig->render( |
|
22
|
|
|
(string) $this->findTemplate($request, $request->getRequestFormat(), $code, $showException), |
|
23
|
|
|
array( |
|
24
|
|
|
'status_code' => $code, |
|
25
|
|
|
'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', |
|
26
|
|
|
'exception' => $exception, |
|
27
|
|
|
'logger' => $logger, |
|
28
|
|
|
'currentContent' => $currentContent, |
|
29
|
|
|
) |
|
30
|
|
|
)); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param Request $request |
|
35
|
|
|
* @param string $format |
|
36
|
|
|
* @param int $code An HTTP response status code |
|
37
|
|
|
* @param bool $showException |
|
38
|
|
|
* |
|
39
|
|
|
* @return string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function findTemplate(Request $request, $format, $code, $showException) |
|
42
|
|
|
{ |
|
43
|
|
|
$name = $showException ? 'exception' : 'error'; |
|
44
|
|
|
if ($showException && 'html' == $format) { |
|
45
|
|
|
$name = 'exception_full'; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
// For error pages, try to find a template for the specific HTTP status code and format |
|
49
|
|
|
if (!$showException) { |
|
50
|
|
|
$template = sprintf('@Twig/Exception/%s%s.%s.twig', $name, $code, $format); |
|
51
|
|
|
if ($this->templateExists($template)) { |
|
52
|
|
|
return $template; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
// try to find a template for the given format |
|
57
|
|
|
$template = sprintf('@Twig/Exception/%s.%s.twig', $name, $format); |
|
58
|
|
|
if ($this->templateExists($template)) { |
|
59
|
|
|
return $template; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
// default to a generic HTML exception |
|
63
|
|
|
$request->setRequestFormat('html'); |
|
64
|
|
|
|
|
65
|
|
|
return sprintf('@Twig/Exception/%s.html.twig', $showException ? 'exception_full' : $name); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|