Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
kernel_exception_subscriber.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 namespace phpbb\event;
015
016 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
017 use Symfony\Component\HttpFoundation\JsonResponse;
018 use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
019 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
020 use Symfony\Component\HttpKernel\KernelEvents;
021 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
022 use Symfony\Component\HttpFoundation\Response;
023
024 class kernel_exception_subscriber implements EventSubscriberInterface
025 {
026 /**
027 * Set to true to show full exception messages
028 *
029 * @var bool
030 */
031 protected $debug;
032
033 /**
034 * Template object
035 *
036 * @var \phpbb\template\template
037 */
038 protected $template;
039
040 /**
041 * Language object
042 *
043 * @var \phpbb\language\language
044 */
045 protected $language;
046
047 /**
048 * User object
049 *
050 * @var \phpbb\user
051 */
052 protected $user;
053
054 /** @var \phpbb\request\type_cast_helper */
055 protected $type_caster;
056
057 /**
058 * Construct method
059 *
060 * @param \phpbb\template\template $template Template object
061 * @param \phpbb\language\language $language Language object
062 * @param \phpbb\user $user User object
063 * @param bool $debug Set to true to show full exception messages
064 */
065 public function __construct(\phpbb\template\template $template, \phpbb\language\language $language, \phpbb\user $user, $debug = false)
066 {
067 $this->debug = $debug || defined('DEBUG');
068 $this->template = $template;
069 $this->language = $language;
070 $this->user = $user;
071 $this->type_caster = new \phpbb\request\type_cast_helper();
072 }
073
074 /**
075 * This listener is run when the KernelEvents::EXCEPTION event is triggered
076 *
077 * @param GetResponseForExceptionEvent $event
078 * @return null
079 */
080 public function on_kernel_exception(GetResponseForExceptionEvent $event)
081 {
082 $exception = $event->getException();
083
084 $message = $exception->getMessage();
085 $this->type_caster->set_var($message, $message, 'string', true, false);
086
087 if ($exception instanceof \phpbb\exception\exception_interface)
088 {
089 $message = $this->language->lang_array($message, $exception->get_parameters());
090 }
091 else if (!$this->debug && $exception instanceof NotFoundHttpException)
092 {
093 $message = $this->language->lang('PAGE_NOT_FOUND');
094 }
095
096 // Do not update user session page if it does not exist
097 if ($exception instanceof NotFoundHttpException)
098 {
099 $this->user->update_session_page = false;
100 }
101
102 // Show <strong> text in bold
103 $message = preg_replace('#<(/?strong)>#i', '<$1>', $message);
104
105 if (!$event->getRequest()->isXmlHttpRequest())
106 {
107 page_header($this->language->lang('INFORMATION'));
108
109 $this->template->assign_vars(array(
110 'MESSAGE_TITLE' => $this->language->lang('INFORMATION'),
111 'MESSAGE_TEXT' => $message,
112 ));
113
114 $this->template->set_filenames(array(
115 'body' => 'message_body.html',
116 ));
117
118 page_footer(true, false, false);
119
120 $response = new Response($this->template->assign_display('body'), 500);
121 }
122 else
123 {
124 $data = array();
125
126 if (!empty($message))
127 {
128 $data['message'] = $message;
129 }
130
131 if ($this->debug)
132 {
133 $data['trace'] = $exception->getTrace();
134 }
135
136 $response = new JsonResponse($data, 500);
137 }
138
139 if ($exception instanceof HttpExceptionInterface)
140 {
141 $response->setStatusCode($exception->getStatusCode());
142 $response->headers->add($exception->getHeaders());
143 }
144
145 $event->setResponse($response);
146 }
147
148 static public function getSubscribedEvents()
149 {
150 return array(
151 KernelEvents::EXCEPTION => 'on_kernel_exception',
152 );
153 }
154 }
155