|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Chamilo\CoreBundle\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
8
|
|
|
use Symfony\Component\ErrorHandler\Exception\FlattenException; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException; |
|
11
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
12
|
|
|
|
|
13
|
|
|
class ExceptionController extends AbstractController |
|
14
|
|
|
{ |
|
15
|
|
|
public function showAction(FlattenException $exception) |
|
16
|
|
|
{ |
|
17
|
|
|
if ('dev' === $this->getParameter('app_env')) { |
|
18
|
|
|
throw new HttpException($exception->getCode(), $exception->getMessage()); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
$showException = true; |
|
22
|
|
|
//$name = $showException ? 'exception' : 'error'; |
|
23
|
|
|
$name = 'exception'; |
|
24
|
|
|
$code = $exception->getCode(); |
|
25
|
|
|
$format = 'html'; |
|
26
|
|
|
$loader = $this->container->get('twig')->getLoader(); |
|
27
|
|
|
|
|
28
|
|
|
// when not in debug, try to find a template for the specific HTTP status code and format |
|
29
|
|
|
$template = sprintf('@ChamiloCore/Exception/%s%s.%s.twig', $name, $code, $format); |
|
30
|
|
|
if ($loader->exists($template)) { |
|
31
|
|
|
return $template; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
// try to find a template for the given format |
|
35
|
|
|
$template = sprintf('@ChamiloCore/Exception/%s.%s.twig', $name, $format); |
|
36
|
|
|
if ($loader->exists($template)) { |
|
37
|
|
|
return $template; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
// default to a generic HTML exception |
|
41
|
|
|
//$request->setRequestFormat('html'); |
|
42
|
|
|
//$template = sprintf('@ChamiloCore/Exception/%s.html.twig', $showException ? 'exception_full' : $name); |
|
43
|
|
|
$template = sprintf('@ChamiloCore/Exception/%s.html.twig', 'exception_full'); |
|
44
|
|
|
|
|
45
|
|
|
return $this->render($template, ['exception' => $exception]); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @Route("/error") |
|
50
|
|
|
*/ |
|
51
|
|
|
public function errorAction(Request $request) |
|
52
|
|
|
{ |
|
53
|
|
|
$message = $request->getSession()->get('error_message', ''); |
|
54
|
|
|
$exception = new FlattenException(); |
|
55
|
|
|
$exception->setCode(500); |
|
56
|
|
|
|
|
57
|
|
|
$exception->setMessage($message); |
|
58
|
|
|
|
|
59
|
|
|
$showException = true; |
|
60
|
|
|
//$name = $showException ? 'exception' : 'error'; |
|
61
|
|
|
$name = 'exception'; |
|
62
|
|
|
$code = $exception->getCode(); |
|
63
|
|
|
$format = 'html'; |
|
64
|
|
|
$loader = $this->container->get('twig')->getLoader(); |
|
65
|
|
|
// when not in debug, try to find a template for the specific HTTP status code and format |
|
66
|
|
|
//if (!$showException) { |
|
67
|
|
|
$template = sprintf('@ChamiloCore/Exception/%s%s.%s.twig', $name, $code, $format); |
|
68
|
|
|
if ($loader->exists($template)) { |
|
69
|
|
|
return $template; |
|
70
|
|
|
} |
|
71
|
|
|
//} |
|
72
|
|
|
|
|
73
|
|
|
// try to find a template for the given format |
|
74
|
|
|
$template = sprintf('@ChamiloCore/Exception/%s.%s.twig', $name, $format); |
|
75
|
|
|
if ($loader->exists($template)) { |
|
76
|
|
|
return $template; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
// default to a generic HTML exception |
|
80
|
|
|
//$request->setRequestFormat('html'); |
|
81
|
|
|
$template = sprintf('@ChamiloCore/Exception/%s.html.twig', 'exception_full'); |
|
82
|
|
|
|
|
83
|
|
|
return $this->render($template, ['exception' => $exception]); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|