]> Raphaƫl G. Git Repositories - airbundle/blob - Controller/ErrorController.php
Import anonymous token, a token required to validate an user's roles
[airbundle] / Controller / ErrorController.php
1 <?php
2
3 namespace Rapsys\AirBundle\Controller;
4
5 use Symfony\Component\HttpFoundation\Request;
6 use Symfony\Component\HttpFoundation\Response;
7 #use Symfony\Component\Security\Core\Exception\AccessDeniedException;
8 #use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
9 #use Symfony\Component\DependencyInjection\ContainerInterface;
10 #use Symfony\Component\Routing\RouterInterface;
11 #use Symfony\Component\Translation\TranslatorInterface;
12 #use Twig\Environment;
13
14 #use Symfony\Component\Debug\Exception\FlattenException;
15 use Symfony\Component\ErrorHandler\Exception\FlattenException;
16
17 class ErrorController extends DefaultController {
18 /**
19 * {@inheritdoc}
20 */
21 public function show(Request $request, FlattenException $exception) {
22 //Set section
23 $section = $exception->getStatusCode().' '.$this->translator->trans($exception->getStatusText());
24
25 //Set title
26 $title = $this->translator->trans($this->config['site']['title']).' - '.$section;
27
28 //Set the message
29 $message = $exception->getMessage();
30
31 //Init trace
32 $trace = null;
33
34 //Prevent non admin access to trace
35 if ($this->isGranted('ROLE_ADMIN')) {
36 //Set project dir
37 $projectDir = $this->container->getParameter('kernel.project_dir').'/';
38
39 //Set the trace
40 //$trace = $exception->getAsString();
41 $trace = '';
42
43 //Iterate on array
44 foreach($exception->toArray() as $current) {
45 $trace .= $current['class'];
46
47 if (!empty($current['message'])) {
48 $trace .= ': '.$current['message'];
49 }
50
51 if (!empty($current['trace'])) {
52 foreach($current['trace'] as $id => $sub) {
53 $trace .= "\n".'#'.$id.' '.$sub['class'].$sub['type'].$sub['function'];
54 if (!empty($sub['args'])) {
55 $trace .= '('.implode(', ', array_map(function($v){return $v[0].' '.$v[1];}, $sub['args'])).')';
56 }
57 $trace .= ' in '.str_replace($projectDir, '', $sub['file']).':'.$sub['line'];
58 }
59 }
60 }
61 }
62
63 //Render template
64 return $this->render(
65 '@RapsysAir/error.html.twig',
66 ['title' => $title, 'section' => $section, 'message' => $message, 'trace' => $trace]+$this->context
67 );
68 }
69 }