[ Index ] |
PHP Cross Reference of phpBB-3.1.12-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\event; 15 16 use Symfony\Component\EventDispatcher\EventSubscriberInterface; 17 use Symfony\Component\HttpFoundation\JsonResponse; 18 use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; 19 use Symfony\Component\HttpKernel\KernelEvents; 20 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; 21 use Symfony\Component\HttpFoundation\Response; 22 23 class kernel_exception_subscriber implements EventSubscriberInterface 24 { 25 /** 26 * Template object 27 * @var \phpbb\template\template 28 */ 29 protected $template; 30 31 /** 32 * User object 33 * @var \phpbb\user 34 */ 35 protected $user; 36 37 /** @var \phpbb\request\type_cast_helper */ 38 protected $type_caster; 39 40 /** 41 * Construct method 42 * 43 * @param \phpbb\template\template $template Template object 44 * @param \phpbb\user $user User object 45 */ 46 public function __construct(\phpbb\template\template $template, \phpbb\user $user) 47 { 48 $this->template = $template; 49 $this->user = $user; 50 $this->type_caster = new \phpbb\request\type_cast_helper(); 51 } 52 53 /** 54 * This listener is run when the KernelEvents::EXCEPTION event is triggered 55 * 56 * @param GetResponseForExceptionEvent $event 57 * @return null 58 */ 59 public function on_kernel_exception(GetResponseForExceptionEvent $event) 60 { 61 $exception = $event->getException(); 62 63 $message = $exception->getMessage(); 64 $this->type_caster->set_var($message, $message, 'string', true, false); 65 66 if ($exception instanceof \phpbb\exception\exception_interface) 67 { 68 $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($message), $exception->get_parameters())); 69 } 70 71 // Show <strong> text in bold 72 $message = preg_replace('#<(/?strong)>#i', '<$1>', $message); 73 74 if (!$event->getRequest()->isXmlHttpRequest()) 75 { 76 page_header($this->user->lang('INFORMATION')); 77 78 $this->template->assign_vars(array( 79 'MESSAGE_TITLE' => $this->user->lang('INFORMATION'), 80 'MESSAGE_TEXT' => $message, 81 )); 82 83 $this->template->set_filenames(array( 84 'body' => 'message_body.html', 85 )); 86 87 page_footer(true, false, false); 88 89 $response = new Response($this->template->assign_display('body'), 500); 90 } 91 else 92 { 93 $data = array(); 94 95 if (!empty($message)) 96 { 97 $data['message'] = $message; 98 } 99 100 if (defined('DEBUG')) 101 { 102 $data['trace'] = $exception->getTrace(); 103 } 104 105 $response = new JsonResponse($data, 500); 106 } 107 108 if ($exception instanceof HttpExceptionInterface) 109 { 110 $response->setStatusCode($exception->getStatusCode()); 111 $response->headers->add($exception->getHeaders()); 112 } 113 114 $event->setResponse($response); 115 } 116 117 public static function getSubscribedEvents() 118 { 119 return array( 120 KernelEvents::EXCEPTION => 'on_kernel_exception', 121 ); 122 } 123 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |