Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
kernel_exception_subscriber | |
0.00% |
0 / 31 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
on_kernel_exception | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
42 | |||
getSubscribedEvents | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | namespace phpbb\install\event; |
15 | |
16 | use phpbb\exception\exception_interface; |
17 | use phpbb\install\controller\helper; |
18 | use phpbb\language\language; |
19 | use phpbb\template\template; |
20 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
21 | use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; |
22 | use Symfony\Component\HttpKernel\KernelEvents; |
23 | use Symfony\Component\HttpKernel\Event\ExceptionEvent; |
24 | use Symfony\Component\HttpFoundation\JsonResponse; |
25 | |
26 | /** |
27 | * Exception handler for the installer |
28 | */ |
29 | class kernel_exception_subscriber implements EventSubscriberInterface |
30 | { |
31 | /** |
32 | * @var helper |
33 | */ |
34 | protected $controller_helper; |
35 | |
36 | /** |
37 | * @var language |
38 | */ |
39 | protected $language; |
40 | |
41 | /** |
42 | * @var template |
43 | */ |
44 | protected $template; |
45 | |
46 | /** |
47 | * Constructor |
48 | * |
49 | * @param helper $controller_helper |
50 | * @param language $language |
51 | * @param template $template |
52 | */ |
53 | public function __construct(helper $controller_helper, language $language, template $template) |
54 | { |
55 | $this->controller_helper = $controller_helper; |
56 | $this->language = $language; |
57 | $this->template = $template; |
58 | } |
59 | |
60 | /** |
61 | * This listener is run when the KernelEvents::EXCEPTION event is triggered |
62 | * |
63 | * @param ExceptionEvent $event |
64 | */ |
65 | public function on_kernel_exception(ExceptionEvent $event) |
66 | { |
67 | $exception = $event->getThrowable(); |
68 | $message = $exception->getMessage(); |
69 | |
70 | if ($exception instanceof exception_interface) |
71 | { |
72 | $message = $this->language->lang_array($message, $exception->get_parameters()); |
73 | } |
74 | |
75 | if (!$event->getRequest()->isXmlHttpRequest()) |
76 | { |
77 | $this->template->assign_vars(array( |
78 | 'TITLE' => $this->language->lang('INFORMATION'), |
79 | 'BODY' => $message, |
80 | )); |
81 | |
82 | $response = $this->controller_helper->render( |
83 | 'installer_main.html', |
84 | $this->language->lang('INFORMATION'), |
85 | false, |
86 | 500 |
87 | ); |
88 | } |
89 | else |
90 | { |
91 | $data = array(); |
92 | |
93 | if (!empty($message)) |
94 | { |
95 | $data['message'] = $message; |
96 | } |
97 | |
98 | if (defined('DEBUG')) |
99 | { |
100 | $data['trace'] = $exception->getTrace(); |
101 | } |
102 | |
103 | $response = new JsonResponse($data, 500); |
104 | } |
105 | |
106 | if ($exception instanceof HttpExceptionInterface) |
107 | { |
108 | $response->setStatusCode($exception->getStatusCode()); |
109 | $response->headers->add($exception->getHeaders()); |
110 | } |
111 | |
112 | $event->setResponse($response); |
113 | } |
114 | |
115 | /** |
116 | * {@inheritDoc} |
117 | */ |
118 | public static function getSubscribedEvents() |
119 | { |
120 | return [ |
121 | KernelEvents::EXCEPTION => 'on_kernel_exception', |
122 | ]; |
123 | } |
124 | } |