Example #1
0
 /**
  * Shows caught exception in a nice view.
  * @param \App\Exception\HttpException|\Exception $exception
  * @return null
  */
 public function handle_error_request(\Exception $exception)
 {
     if (!function_exists('apache_request_headers')) {
         function apache_request_headers()
         {
             $arh = array();
             $rx_http = '/\\AHTTP_/';
             foreach ($_SERVER as $key => $val) {
                 if (preg_match($rx_http, $key)) {
                     $arh_key = preg_replace($rx_http, '', $key);
                     $rx_matches = array();
                     // do some nasty string manipulations to restore the original letter case
                     // this should work in most cases
                     $rx_matches = explode('_', $arh_key);
                     if (count($rx_matches) > 0 and strlen($arh_key) > 2) {
                         foreach ($rx_matches as $ak_key => $ak_val) {
                             $rx_matches[$ak_key] = ucfirst($ak_val);
                         }
                         $arh_key = implode('-', $rx_matches);
                     }
                     $arh[$arh_key] = $val;
                 }
             }
             return $arh;
         }
     }
     try {
         $response = null;
         $request = null;
         if ($exception instanceof HttpException) {
             $request = $exception->getParameter('request');
         }
         $event = new GetResponseEvent($request, $request ? $request->cookie() : []);
         $event->setException($exception);
         $this->dispatcher->dispatch(Events::KERNEL_PRE_HANDLE_EXCEPTION, $event);
         if ($event->getResponse()) {
             $response = $event->getResponse();
         }
         if (!$response) {
             $isAdmin = $exception instanceof HttpException && $exception->getParameter('request') && $exception->getParameter('request')->isAdminPath() && $this->auth->has_role('admin');
             if ($isAdmin) {
                 $route_data = $this->router->match('/admin/error/' . $exception->getCode());
             } else {
                 $route_data = $this->router->match('/error/' . $exception->getCode());
             }
             $route_data['params'] = array_merge($route_data['params'], ['exception' => $exception]);
             $request = $this->request($route_data['route'], $_SERVER['REQUEST_METHOD'], $_POST, $_GET, $route_data['params'], $_SERVER, $_COOKIE, apache_request_headers());
             $response = $request->execute();
         }
         $response->send_headers()->send_body();
     } catch (\Exception $e) {
         $this->handle_exception($e);
     }
 }
Example #2
0
 /**
  * Shows caught exception in a nice view.
  * @param \App\Exception\HttpException|\Exception $exception
  * @return null
  */
 public function handle_error_request(\Exception $exception)
 {
     try {
         $response = null;
         $request = null;
         if ($exception instanceof HttpException) {
             $request = $exception->getParameter('request');
         }
         $event = new GetResponseEvent($request, $request ? $request->getCookie() : []);
         $event->setException($exception);
         $this->dispatcher->dispatch(Events::KERNEL_PRE_HANDLE_EXCEPTION, $event);
         if ($event->getResponse()) {
             $response = $event->getResponse();
         }
         if (!$response) {
             $isAdmin = $exception instanceof HttpException && $exception->getParameter('request') && $exception->getParameter('request')->isAdminPath() && $this->auth->has_role('admin');
             if ($isAdmin) {
                 $route_data = $this->router->match('/admin/error/' . $exception->getCode());
             } else {
                 $route_data = $this->router->match('/error/' . $exception->getCode());
             }
             $route_data['params'] = array_merge($route_data['params'], ['exception' => $exception]);
             $request = $this->request($route_data['route'], $_SERVER['REQUEST_METHOD'], $_POST, $_GET, $route_data['params'], $_SERVER, $_COOKIE);
             $response = $request->execute();
         }
         $response->send_headers()->send_body();
     } catch (\Exception $e) {
         $this->handle_exception($e);
     }
 }