|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
declare(strict_types=1); |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Controller; |
|
8
|
|
|
|
|
9
|
|
|
use Symfony\Component\DependencyInjection\Attribute\Autowire; |
|
10
|
|
|
use Symfony\Component\ErrorHandler\ErrorRenderer\ErrorRendererInterface; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
13
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; |
|
14
|
|
|
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; |
|
15
|
|
|
use Twig\Environment; |
|
16
|
|
|
use Twig\Error\LoaderError; |
|
17
|
|
|
use Twig\Error\RuntimeError; |
|
18
|
|
|
use Twig\Error\SyntaxError; |
|
19
|
|
|
|
|
20
|
|
|
class ErrorController |
|
21
|
|
|
{ |
|
22
|
|
|
public function __construct( |
|
23
|
|
|
private readonly Environment $twig, |
|
24
|
|
|
#[Autowire(env: 'APP_ENV')] |
|
25
|
|
|
private readonly string $environment, |
|
26
|
|
|
#[Autowire(service: 'error_renderer')] |
|
27
|
|
|
private readonly ErrorRendererInterface $errorRenderer, |
|
28
|
|
|
) {} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @throws SyntaxError |
|
32
|
|
|
* @throws RuntimeError |
|
33
|
|
|
* @throws LoaderError |
|
34
|
|
|
*/ |
|
35
|
|
|
public function show( |
|
36
|
|
|
Request $request, |
|
37
|
|
|
\Throwable $exception, |
|
38
|
|
|
?DebugLoggerInterface $logger = null, |
|
39
|
|
|
): Response { |
|
40
|
|
|
$statusCode = 500; |
|
41
|
|
|
|
|
42
|
|
|
if ($exception instanceof HttpExceptionInterface) { |
|
43
|
|
|
$statusCode = $exception->getStatusCode(); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if (in_array($this->environment, ['dev', 'test'])) { |
|
47
|
|
|
$exception = $this->errorRenderer->render($exception); |
|
48
|
|
|
|
|
49
|
|
|
$content = $exception->getAsString(); |
|
50
|
|
|
$headers = $exception->getHeaders(); |
|
51
|
|
|
} else { |
|
52
|
|
|
$format = $request->getPreferredFormat(); |
|
53
|
|
|
|
|
54
|
|
|
if ('html' === $format) { |
|
55
|
|
|
$content = $this->twig->render( |
|
56
|
|
|
'@ChamiloCore/Layout/no_layout.html.twig', |
|
57
|
|
|
[ |
|
58
|
|
|
'exception' => $exception, |
|
59
|
|
|
'content' => '', |
|
60
|
|
|
] |
|
61
|
|
|
); |
|
62
|
|
|
} else { |
|
63
|
|
|
$exception = $this->errorRenderer->render($exception); |
|
64
|
|
|
|
|
65
|
|
|
$content = $exception->getAsString(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$headers = []; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return new Response($content, $statusCode, $headers); |
|
72
|
|
|
} |
|
73
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.