1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Explicit Architecture POC, |
7
|
|
|
* which is created on top of the Symfony Demo application. |
8
|
|
|
* |
9
|
|
|
* (c) Herberto Graça <[email protected]> |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Acme\App\Presentation\Web\Core\Exception; |
16
|
|
|
|
17
|
|
|
use Symfony\Bundle\TwigBundle\Controller\ExceptionController as TwigExceptionController; |
18
|
|
|
use Symfony\Component\Debug\Exception\FlattenException; |
19
|
|
|
use Symfony\Component\HttpFoundation\Request; |
20
|
|
|
use Symfony\Component\HttpFoundation\Response; |
21
|
|
|
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; |
22
|
|
|
|
23
|
|
|
final class ExceptionController extends TwigExceptionController |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
private const TEMPLATE_NAMESPACE_TWIG = 'Twig'; |
26
|
|
|
private const TEMPLATE_NAMESPACE_WEB = 'Web'; |
27
|
|
|
|
28
|
|
|
public function show(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null): Response |
29
|
|
|
{ |
30
|
|
|
return parent::showAction($request, $exception, $logger); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param string $format |
35
|
|
|
* @param int $code An HTTP response status code |
36
|
|
|
* @param bool $showException |
37
|
|
|
*/ |
38
|
|
|
protected function findTemplate(Request $request, $format, $code, $showException): string |
39
|
|
|
{ |
40
|
|
|
$name = $showException ? 'exception' : 'error'; |
41
|
|
|
$namespace = self::TEMPLATE_NAMESPACE_WEB; |
42
|
|
|
if ($showException && $format === 'html') { |
43
|
|
|
$name = 'exception_full'; |
44
|
|
|
$namespace = self::TEMPLATE_NAMESPACE_TWIG; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// For error pages, try to find a template for the specific HTTP status code and format |
48
|
|
|
if (!$showException) { |
49
|
|
|
$template = sprintf('@%s/Exception/%s%s.%s.twig', $namespace, $name, $code, $format); |
50
|
|
|
if ($this->templateExists($template)) { |
51
|
|
|
return $template; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// try to find a template for the given format |
56
|
|
|
$template = sprintf('@%s/Exception/%s.%s.twig', $namespace, $name, $format); |
57
|
|
|
if ($this->templateExists($template)) { |
58
|
|
|
return $template; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// default to a generic HTML exception |
62
|
|
|
$request->setRequestFormat('html'); |
63
|
|
|
|
64
|
|
|
return sprintf( |
65
|
|
|
'@%s/Exception/%s.html.twig', |
66
|
|
|
$showException ? self::TEMPLATE_NAMESPACE_TWIG : self::TEMPLATE_NAMESPACE_WEB, |
67
|
|
|
$showException ? 'exception_full' : $name |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.