/**
  * This listener is run when the KernelEvents::EXCEPTION event is triggered
  *
  * @param GetResponseForExceptionEvent $event
  * @return null
  */
 public function on_kernel_exception(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $message = $exception->getMessage();
     $this->type_caster->set_var($message, $message, 'string', true, false);
     if ($exception instanceof \phpbb\exception\exception_interface) {
         $message = $this->language->lang_array($message, $exception->get_parameters());
     }
     // Show <strong> text in bold
     $message = preg_replace('#&lt;(/?strong)&gt;#i', '<$1>', $message);
     if (!$event->getRequest()->isXmlHttpRequest()) {
         page_header($this->language->lang('INFORMATION'));
         $this->template->assign_vars(array('MESSAGE_TITLE' => $this->language->lang('INFORMATION'), 'MESSAGE_TEXT' => $message));
         $this->template->set_filenames(array('body' => 'message_body.html'));
         page_footer(true, false, false);
         $response = new Response($this->template->assign_display('body'), 500);
     } else {
         $data = array();
         if (!empty($message)) {
             $data['message'] = $message;
         }
         if (defined('DEBUG')) {
             $data['trace'] = $exception->getTrace();
         }
         $response = new JsonResponse($data, 500);
     }
     if ($exception instanceof HttpExceptionInterface) {
         $response->setStatusCode($exception->getStatusCode());
         $response->headers->add($exception->getHeaders());
     }
     $event->setResponse($response);
 }
Esempio n. 2
0
 /**
  * Dependencies should be specified in the service definition and can be
  * then accessed in __construct(). Arguments are sent through the URL path
  * and should match the parameters of the method you are using as your
  * controller.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request Symfony Request object
  * @param mixed $controller A callable (controller class, method)
  * @return array An array of arguments to pass to the controller
  * @throws \phpbb\controller\exception
  */
 public function getArguments(Request $request, $controller)
 {
     // At this point, $controller contains the object and method name
     list($object, $method) = $controller;
     $mirror = new \ReflectionMethod($object, $method);
     $arguments = array();
     $parameters = $mirror->getParameters();
     $attributes = $request->attributes->all();
     foreach ($parameters as $param) {
         if (array_key_exists($param->name, $attributes)) {
             if (is_string($attributes[$param->name])) {
                 $value = $attributes[$param->name];
                 $this->type_cast_helper->set_var($value, $attributes[$param->name], 'string', true, false);
                 $arguments[] = $value;
             } else {
                 $arguments[] = $attributes[$param->name];
             }
         } else {
             if ($param->getClass() && $param->getClass()->isInstance($request)) {
                 $arguments[] = $request;
             } else {
                 if ($param->isDefaultValueAvailable()) {
                     $arguments[] = $param->getDefaultValue();
                 } else {
                     throw new \phpbb\controller\exception('CONTROLLER_ARGUMENT_VALUE_MISSING', array($param->getPosition() + 1, get_class($object) . ':' . $method, $param->name));
                 }
             }
         }
     }
     return $arguments;
 }