|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Alpixel\Bundle\CMSBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\TwigBundle\Controller\ExceptionController as BaseController; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
7
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
8
|
|
|
use Symfony\Component\HttpKernel\Exception\FlattenException; |
|
9
|
|
|
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; |
|
10
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
11
|
|
|
|
|
12
|
|
|
class ExceptionController extends BaseController |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @Route("/erreur", name="error") |
|
16
|
|
|
*/ |
|
17
|
|
|
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null) |
|
18
|
|
|
{ |
|
19
|
|
|
$currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1)); |
|
|
|
|
|
|
20
|
|
|
$showException = $request->attributes->get('showException', $this->debug); // As opposed to an additional parameter, this maintains BC |
|
21
|
|
|
|
|
22
|
|
|
$code = $exception->getStatusCode(); |
|
23
|
|
|
|
|
24
|
|
|
if($showException) { |
|
25
|
|
|
$statusCode = Response::HTTP_ACCEPTED; |
|
26
|
|
|
} else { |
|
27
|
|
|
$statusCode = $code; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
return new Response($this->twig->render( |
|
31
|
|
|
(string) $this->findTemplate($request, $request->getRequestFormat(), $code, $showException), |
|
32
|
|
|
[ |
|
33
|
|
|
'status_code' => $code, |
|
34
|
|
|
'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', |
|
35
|
|
|
'exception' => $exception, |
|
36
|
|
|
'logger' => $logger, |
|
37
|
|
|
'currentContent' => $currentContent, |
|
38
|
|
|
] |
|
39
|
|
|
), $statusCode); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param Request $request |
|
44
|
|
|
* @param string $format |
|
45
|
|
|
* @param int $code An HTTP response status code |
|
46
|
|
|
* @param bool $showException |
|
47
|
|
|
* |
|
48
|
|
|
* @return string |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function findTemplate(Request $request, $format, $code, $showException) |
|
51
|
|
|
{ |
|
52
|
|
|
if(!$showException) { |
|
53
|
|
|
// try to find a template for the given format |
|
54
|
|
|
$template = sprintf('page/errors.html.twig'); |
|
55
|
|
|
if ($this->templateExists($template)) { |
|
56
|
|
|
return $template; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return parent::findTemplate($request, $format, $code, $showException); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: