|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Controller; |
|
8
|
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Repository\Node\AccessUrlRepository; |
|
10
|
|
|
use Exception; |
|
11
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
12
|
|
|
use Symfony\Component\ErrorHandler\Exception\FlattenException; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
15
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException; |
|
16
|
|
|
use Symfony\Component\Routing\Attribute\Route; |
|
17
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
|
18
|
|
|
|
|
19
|
|
|
class ExceptionController extends AbstractController |
|
20
|
|
|
{ |
|
21
|
|
|
public function __construct( |
|
22
|
|
|
private UrlGeneratorInterface $urlGenerator, |
|
23
|
|
|
private AccessUrlRepository $accessUrlRepository |
|
24
|
|
|
) {} |
|
25
|
|
|
|
|
26
|
|
|
public function show(Exception $exception): Response |
|
27
|
|
|
{ |
|
28
|
|
|
if ('dev' === (string) $this->getParameter('app_env')) { |
|
29
|
|
|
throw new HttpException($exception->getCode(), $exception->getMessage()); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
$name = 'exception'; |
|
33
|
|
|
$code = $exception->getCode(); |
|
34
|
|
|
$format = 'html'; |
|
35
|
|
|
$loader = $this->container->get('twig')->getLoader(); |
|
36
|
|
|
$templateToLoad = sprintf('@ChamiloCore/Exception/%s.html.twig', 'exception_full'); |
|
37
|
|
|
|
|
38
|
|
|
$candidate = sprintf('@ChamiloCore/Exception/%s%s.%s.twig', $name, $code, $format); |
|
39
|
|
|
if ($loader->exists($candidate)) { |
|
40
|
|
|
$templateToLoad = $candidate; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$candidate = sprintf('@ChamiloCore/Exception/%s.%s.twig', $name, $format); |
|
44
|
|
|
if ($loader->exists($candidate)) { |
|
45
|
|
|
$templateToLoad = $candidate; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return $this->render($templateToLoad, [ |
|
49
|
|
|
'exception' => $exception, |
|
50
|
|
|
]); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
#[Route(path: '/error')] |
|
54
|
|
|
public function error(Request $request): Response |
|
55
|
|
|
{ |
|
56
|
|
|
$message = $request->getSession()->get('error_message', ''); |
|
57
|
|
|
$exception = new FlattenException(); |
|
58
|
|
|
$exception->setCode(500); |
|
59
|
|
|
|
|
60
|
|
|
$exception->setMessage($message); |
|
61
|
|
|
|
|
62
|
|
|
$name = 'exception'; |
|
63
|
|
|
$code = $exception->getCode(); |
|
64
|
|
|
$format = 'html'; |
|
65
|
|
|
$loader = $this->container->get('twig')->getLoader(); |
|
66
|
|
|
$templateToLoad = sprintf('@ChamiloCore/Exception/%s.html.twig', 'exception_full'); |
|
67
|
|
|
|
|
68
|
|
|
$candidate = sprintf('@ChamiloCore/Exception/%s%s.%s.twig', $name, $code, $format); |
|
69
|
|
|
if ($loader->exists($candidate)) { |
|
70
|
|
|
$templateToLoad = $candidate; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$candidate = sprintf('@ChamiloCore/Exception/%s.%s.twig', $name, $format); |
|
74
|
|
|
if ($loader->exists($candidate)) { |
|
75
|
|
|
$templateToLoad = $candidate; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $this->render($templateToLoad, [ |
|
79
|
|
|
'exception' => $exception, |
|
80
|
|
|
]); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
#[Route(path: '/error/undefined-url', name: 'undefined_url_error')] |
|
84
|
|
|
public function undefinedUrlError(Request $request): Response |
|
85
|
|
|
{ |
|
86
|
|
|
$host = $request->getHost(); |
|
87
|
|
|
|
|
88
|
|
|
$accessUrl = $this->accessUrlRepository->find(1); |
|
89
|
|
|
$themeHost = rtrim($accessUrl?->getUrl() ?? '', '/'); |
|
90
|
|
|
$themeName = 'chamilo'; |
|
91
|
|
|
|
|
92
|
|
|
$cssUrl = $themeHost |
|
93
|
|
|
. $this->urlGenerator->generate('theme_asset', [ |
|
94
|
|
|
'name' => $themeName, |
|
95
|
|
|
'path' => 'colors.css', |
|
96
|
|
|
], UrlGeneratorInterface::ABSOLUTE_PATH); |
|
97
|
|
|
|
|
98
|
|
|
$logoUrl = $themeHost |
|
99
|
|
|
. $this->urlGenerator->generate('theme_asset', [ |
|
100
|
|
|
'name' => $themeName, |
|
101
|
|
|
'path' => 'images/header-logo.svg', |
|
102
|
|
|
], UrlGeneratorInterface::ABSOLUTE_PATH); |
|
103
|
|
|
|
|
104
|
|
|
return $this->render('@ChamiloCore/Exception/undefined_url.html.twig', [ |
|
105
|
|
|
'host' => $host, |
|
106
|
|
|
'cssUrl' => $cssUrl, |
|
107
|
|
|
'logoUrl' => $logoUrl, |
|
108
|
|
|
]); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|