[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
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\GetResponseForExceptionEvent; 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 GetResponseForExceptionEvent $event 64 */ 65 public function on_kernel_exception(GetResponseForExceptionEvent $event) 66 { 67 $exception = $event->getException(); 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 * Returns an array of events the object is subscribed to 117 * 118 * @return array Array of events the object is subscribed to 119 */ 120 static public function getSubscribedEvents() 121 { 122 return array( 123 KernelEvents::EXCEPTION => 'on_kernel_exception', 124 ); 125 } 126 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |