getStatusCode() public method

public getStatusCode ( )
 /**
  * Сериализует исключение и возвращает исключение.
  * 
  * @param Request $request Запрос
  * @param FlattenException $exception Исключение
  * @param DebugLoggerInterface $logger Лог
  * @param string $format Формат сериализации
  * @return Response
  */
 public function showExceptionAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'json')
 {
     /** @var \FOS\RestBundle\View\ViewHandler $viewHandler */
     $viewHandler = $this->get('fos_rest.view_handler');
     // Если формат сериализации не поддерживается, то выбирается json
     if ($viewHandler->isFormatTemplating($format)) {
         $format = 'json';
     }
     $view = View::create()->setStatusCode($exception->getStatusCode())->setData(new ExceptionRepresentation($exception->getStatusCode(), $exception->getMessage(), null))->setFormat($format);
     return $viewHandler->handle($view);
 }
示例#2
0
 public function exceptionAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger)
 {
     $viewData = [];
     $viewData['status'] = $exception->getStatusCode();
     $viewData['message'] = $exception->getMessage();
     return $this->render('AppBundle:Exception:error.html.twig', $viewData);
 }
 /**
  * @param \Symfony\Component\Debug\Exception\FlattenException $exception
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function handleException(FlattenException $exception)
 {
     $errorPageUrl = $this->application->url($this->errorPageNamePrefix . $exception->getStatusCode());
     $request = Request::create($errorPageUrl, 'GET', ['exception' => $exception]);
     $response = $this->application->handle($request, HttpKernelInterface::SUB_REQUEST, false);
     return $response;
 }
示例#4
0
 /**
  * Converts an Exception to a Response.
  *
  * A "showException" request parameter can be used to force display of an error page (when set to false) or
  * the exception page (when true). If it is not present, the "debug" value passed into the constructor will
  * be used.
  *
  * @param Request              $request   The request
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  *
  * @return Response
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $showException = $request->attributes->get('showException', $this->debug);
     // As opposed to an additional parameter, this maintains BC
     $code = $exception->getStatusCode();
     return new Response($this->twig->render((string) $this->findTemplate($request, $request->getRequestFormat(), $code, $showException), array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent)));
 }
 /**
  * @param \Symfony\Component\Debug\Exception\FlattenException $exception
  *
  * @throws \Spryker\Yves\Application\Plugin\Exception\UndefinedExceptionHandlerException
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function dispatch(FlattenException $exception)
 {
     $statusCode = $exception->getStatusCode();
     if (isset($this->exceptionHandlers[$statusCode])) {
         return $this->exceptionHandlers[$statusCode]->handleException($exception);
     }
     throw new UndefinedExceptionHandlerException(sprintf('Undefined exception handler for status code "%d".', $statusCode));
 }
 public function exceptionAction(FlattenException $exception)
 {
     $this->view->status_code = $exception->getStatusCode();
     $this->view->message = $exception->getMessage();
     $this->view->file = $this->getShortFileName($exception->getFile());
     $this->view->line = $exception->getLine();
     $this->view->trace = $this->parseTrace($exception->getTrace());
     return $this->renderTo('@HideksFramework/templates/exception.html');
 }
 public function showAction(FlattenException $exception)
 {
     $statusCode = $exception->getStatusCode();
     if ($statusCode == 404) {
         $template = 'SurfnetStepupBundle:Exception:error404.html.twig';
     } else {
         $template = 'SurfnetStepupBundle:Exception:error.html.twig';
     }
     return $this->render($template, ['exception' => $exception, 'art' => Art::forFlattenException($exception), 'statusCode' => $statusCode, 'statusText' => isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : '']);
 }
 /**
  * Converts an Exception to a Response.
  *
  * A "showException" request parameter can be used to force display of an error page (when set to false) or
  * the exception page (when true). If it is not present, the "debug" value passed into the constructor will
  * be used.
  *
  * @param Request              $request   The request
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  *
  * @return Response
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     $showException = $request->attributes->get('showException', $this->debug);
     // As opposed to an additional parameter, this maintains BC
     $code = $exception->getStatusCode();
     $response = ['error' => $code, 'message' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : ''];
     if ($showException) {
         $response['exception'] = $exception->toArray();
     }
     return new JsonResponse($response, $code);
 }
示例#9
0
 /**
  * @param Request              $request   The request
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  *
  * @return Response
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     $status = $exception->getStatusCode();
     $message = $exception->getMessage();
     $previousUrl = $request->headers->get('referer');
     if ($request->getFormat($request->getAcceptableContentTypes()[0]) == 'json') {
         return new JsonResponse(['status' => $status, 'message' => $message]);
     } else {
         return $this->render('exception/404.html.twig', ['status' => $status, 'message' => $message, 'previousUrl' => $previousUrl]);
     }
 }
 public function showExceptionAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     if ($exception->getStatusCode() == 404) {
         $uri = str_replace('/app_dev.php', '', $request->getRequestUri());
         $redirectUri = $this->get('iphp.redirectnotfound.observer_pool')->findRedirect($uri);
         if (!is_null($redirectUri)) {
             return new RedirectResponse($redirectUri, 301);
         }
     }
     return $this->get('twig.controller.exception')->showAction($request, $exception, $logger);
 }
 public function exceptionAction(Request $request, FlattenException $exception)
 {
     $status = $exception->getStatusCode();
     $message = $status && $status < 500 ? $exception->getMessage() : Translate::t("Sorry, there has been an internal error. The administrators have been notified and will fix this as soon as possible.");
     try {
         $reqDetails = $this->load($request);
         $pageDetails = $this->get("agit.page")->getPage("_exception");
         $response = $this->createResponse($pageDetails, $reqDetails, ["message" => $message]);
     } catch (Exception $e) {
         $response = $this->render("AgitPageBundle:Special:exception.html.twig", ["locale" => "en_GB", "message" => $message]);
     }
     $response->setStatusCode($status);
     $response->headers->set("X-Frame-Options", "SAMEORIGIN");
     return $response;
 }
 public function listAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     $code = $exception->getStatusCode();
     if (404 !== $code || $this->exclusionRequestMatcher->matches($request)) {
         return $this->showAction($request, $exception, $logger, $request->getRequestFormat());
     }
     $templateForSuggestion = $this->getTemplateForSuggestions($request->getRequestFormat());
     if (null === $templateForSuggestion) {
         return $this->showAction($request, $exception, $logger, $request->getRequestFormat());
     }
     $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $groupedSuggestions = array();
     foreach ($this->suggestionProviders as $item) {
         $suggestions = $item['provider']->create($request);
         $groupedSuggestions[$item['group']] = isset($groupedSuggestions[$item['group']]) ? array_merge($groupedSuggestions[$item['group']], $suggestions) : $suggestions;
     }
     return new Response($this->twig->render($templateForSuggestion, array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'message' => $exception->getMessage(), 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent, 'best_matches' => $groupedSuggestions)), $code);
 }
示例#13
0
 public function __invoke(Request $request, FlattenException $exception, $format)
 {
     $statusCode = $exception->getStatusCode();
     try {
         $template = $this->twig->resolveTemplate(['Exception/error' . $statusCode . '.' . $format . '.twig', 'Exception/error.' . $format . '.twig', 'Exception/error.html.twig']);
     } catch (\Twig_Error_Loader $e) {
         $request->setRequestFormat('html');
         $content = (new ExceptionHandler(false))->getHtml($exception);
         return new Response($content, $exception->getStatusCode(), $exception->getHeaders());
     }
     // We cannot find a template that matches the precise format so we will default
     // to html as previously in the ExceptionHandler
     if (substr($template->getTemplateName(), -9) == 'html.twig') {
         $request->setRequestFormat('html');
     }
     $variables = ['exception' => $exception, 'status_code' => $statusCode, 'status_text' => isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : ''];
     return new Response($template->render($variables), $statusCode);
 }
 /**
  * Converts an Exception to a Response.
  *
  * @param  Request              $request
  * @param  FlattenException     $exception
  * @param  DebugLoggerInterface $logger
  * @param  string               $_format
  * @throws \InvalidArgumentException
  * @return Response
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $_format = 'html')
 {
     $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     switch ($exception->getClass()) {
         case 'Pagekit\\Component\\Session\\Csrf\\Exception\\BadTokenException':
             $title = __('Invalid CSRF token.');
             break;
         case 'Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException':
             $title = __('Sorry, the page you are looking for could not be found.');
             break;
         case 'Symfony\\Component\\HttpKernel\\Exception\\AccessDeniedHttpException':
             $title = $exception->getMessage();
             break;
         default:
             $title = __('Whoops, looks like something went wrong.');
     }
     $response = $this['view']->render('extension://system/theme/templates/error.razr', compact('title', 'exception', 'currentContent'));
     return $this['response']->create($response, $exception->getStatusCode(), $exception->getHeaders());
 }
 /**
  * {@inheritdoc}
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     $class = $exception->getClass();
     //ignore authentication exceptions
     if (strpos($class, 'Authentication') === false) {
         $env = $this->factory->getEnvironment();
         $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
         $layout = $env == 'prod' ? 'Error' : 'Exception';
         $code = $exception->getStatusCode();
         if ($code === 0) {
             //thrown exception that didn't set a code
             $code = 500;
         }
         // Special handling for oauth and api urls
         if (strpos($request->getUri(), '/oauth') !== false && strpos($request->getUri(), 'authorize') === false || strpos($request->getUri(), '/api') !== false) {
             $dataArray = array('error' => array('message' => $exception->getMessage(), 'code' => $code));
             if ($env == 'dev') {
                 $dataArray['trace'] = $exception->getTrace();
             }
             return new JsonResponse($dataArray, 200);
         }
         if ($request->get('prod')) {
             $layout = 'Error';
         }
         $anonymous = $this->factory->getSecurity()->isAnonymous();
         $baseTemplate = 'MauticCoreBundle:Default:slim.html.php';
         if ($anonymous) {
             if ($templatePage = $this->factory->getTheme()->getErrorPageTemplate($code)) {
                 $baseTemplate = $templatePage;
             }
         }
         $template = "MauticCoreBundle:{$layout}:{$code}.html.php";
         $templating = $this->factory->getTemplating();
         if (!$templating->exists($template)) {
             $template = "MauticCoreBundle:{$layout}:base.html.php";
         }
         $statusText = isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '';
         $url = $request->getRequestUri();
         $urlParts = parse_url($url);
         return $this->delegateView(array('viewParameters' => array('baseTemplate' => $baseTemplate, 'status_code' => $code, 'status_text' => $statusText, 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent, 'isPublicPage' => $anonymous), 'contentTemplate' => $template, 'passthroughVars' => array('error' => array('code' => $code, 'text' => $statusText, 'exception' => $env == 'dev' ? $exception->getMessage() : '', 'trace' => $env == 'dev' ? $exception->getTrace() : ''), 'route' => $urlParts['path'])));
     }
 }
    /**
     * Gets the HTML content associated with the given exception.
     *
     * @param FlattenException $exception A FlattenException instance
     *
     * @return string The content as a string
     */
    public function getContent(FlattenException $exception)
    {
        switch ($exception->getStatusCode()) {
            case 404:
                $title = 'Sorry, the page you are looking for could not be found.';
                break;
            default:
                $title = 'Whoops, looks like something went wrong.';
        }
        $content = '';
        if ($this->debug) {
            try {
                $count = count($exception->getAllPrevious());
                $total = $count + 1;
                foreach ($exception->toArray() as $position => $e) {
                    $ind = $count - $position + 1;
                    $class = $this->formatClass($e['class']);
                    $message = nl2br($this->escapeHtml($e['message']));
                    $content .= sprintf(<<<EOF
                        <h2 class="block_exception clear_fix">
                            <span class="exception_counter">%d/%d</span>
                            <span class="exception_title">%s%s:</span>
                            <span class="exception_message">%s</span>
                        </h2>
                        <div class="block">
                            <ol class="traces list_exception">

EOF
, $ind, $total, $class, $this->formatPath($e['trace'][0]['file'], $e['trace'][0]['line']), $message);
                    foreach ($e['trace'] as $trace) {
                        $content .= '       <li>';
                        if ($trace['function']) {
                            $content .= sprintf('at %s%s%s(%s)', $this->formatClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args']));
                        }
                        if (isset($trace['file']) && isset($trace['line'])) {
                            $content .= $this->formatPath($trace['file'], $trace['line']);
                        }
                        $content .= "</li>\n";
                    }
                    $content .= "    </ol>\n</div>\n";
                }
            } catch (\Exception $e) {
                // something nasty happened and we cannot throw an exception anymore
                if ($this->debug) {
                    $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $this->escapeHtml($e->getMessage()));
                } else {
                    $title = 'Whoops, looks like something went wrong.';
                }
            }
        }
        return <<<EOF
            <div id="sf-resetcontent" class="sf-reset">
                <h1>{$title}</h1>
                {$content}
            </div>
EOF;
    }
 public function exceptionAction(FlattenException $exception)
 {
     $msg = 'Something went wrong! (' . $exception->getMessage() . ')';
     return new Response($msg, $exception->getStatusCode());
 }
示例#18
0
    /**
     * Gets the HTML content associated with the given exception.
     *
     * @param FlattenException $exception A FlattenException instance
     *
     * @return string The content as a string
     */
    public function getContent(FlattenException $exception)
    {
        switch ($exception->getStatusCode()) {
            case 404:
                $title = 'Sorry, the page you are looking for could not be found.';
                break;
            default:
                $title = 'Whoops, looks like something went wrong.';
        }
        $content = '';
        if ($this->debug) {
            try {
                $count = count($exception->getAllPrevious());
                $total = $count + 1;
                foreach ($exception->toArray() as $position => $e) {
                    $ind = $count - $position + 1;
                    $class = $this->abbrClass($e['class']);
                    $message = nl2br($e['message']);
                    $content .= sprintf(<<<EOF
                        <div class="block_exception clear_fix">
                            <h2><span>%d/%d</span> %s: %s</h2>
                        </div>
                        <div class="block">
                            <ol class="traces list_exception">

EOF
, $ind, $total, $class, $message);
                    foreach ($e['trace'] as $trace) {
                        $content .= '       <li>';
                        if ($trace['function']) {
                            $content .= sprintf('at %s%s%s(%s)', $this->abbrClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args']));
                        }
                        if (isset($trace['file']) && isset($trace['line'])) {
                            if ($linkFormat = ini_get('xdebug.file_link_format')) {
                                $link = str_replace(array('%f', '%l'), array($trace['file'], $trace['line']), $linkFormat);
                                $content .= sprintf(' in <a href="%s" title="Go to source">%s line %s</a>', $link, $trace['file'], $trace['line']);
                            } else {
                                $content .= sprintf(' in %s line %s', $trace['file'], $trace['line']);
                            }
                        }
                        $content .= "</li>\n";
                    }
                    $content .= "    </ol>\n</div>\n";
                }
            } catch (\Exception $e) {
                // something nasty happened and we cannot throw an exception anymore
                if ($this->debug) {
                    $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($exception), $exception->getMessage());
                } else {
                    $title = 'Whoops, looks like something went wrong.';
                }
            }
        }
        return <<<EOF
            <div id="sf-resetcontent" class="sf-reset">
                <h1>{$title}</h1>
                {$content}
            </div>
EOF;
    }
 /**
  * Handles an exception on a request.
  *
  * @param \Symfony\Component\Debug\Exception\FlattenException $exception
  *   The flattened exception.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request that generated the exception.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  *   A response object.
  */
 public function execute(FlattenException $exception, Request $request)
 {
     $method = 'on' . $exception->getStatusCode() . $this->negotiation->getContentType($request);
     if (method_exists($this, $method)) {
         return $this->{$method}($exception, $request);
     }
     return new Response('A fatal error occurred: ' . $exception->getMessage(), $exception->getStatusCode(), $exception->getHeaders());
 }
    public function getStylesheet(FlattenException $exception)
    {
        $exception->getStatusCode();
        switch ($exception->getStatusCode()) {
            case 403:
                $errorImg = '/assets/common/images/error-pages/403.png';
                break;
            case 404:
                $errorImg = '/assets/common/images/error-pages/404.png';
                break;
            case 500:
                $errorImg = '/assets/common/images/error-pages/500.png';
                break;
            case 503:
                $errorImg = '/assets/common/images/error-pages/503.png';
                break;
            default:
                $errorImg = '/assets/common/images/error-pages/error.png';
                break;
        }
        return <<<EOF
            html {
                background-image:url("/assets/common/images/error-pages/background.png");
                background-repeat:repeat;
                padding-top:0px;
            }
            body {
                background-image:url("{$errorImg}");
                background-repeat:no-repeat;
                background-position:top center;
            }
            .sf-reset { font: 11px Arial, Verdana, sans-serif; color: #333 }
            .sf-reset .clear { clear:both; height:0; font-size:0; line-height:0; }
            .sf-reset .clear_fix:after { display:block; height:0; clear:both; visibility:hidden; }
            .sf-reset .clear_fix { display:inline-block; }
            .sf-reset * html .clear_fix { height:1%; }
            .sf-reset .clear_fix { display:block; }
            .sf-reset, .sf-reset .block { margin: auto }
            .sf-reset abbr { border-bottom: 1px dotted #000; cursor: help; }
            .sf-reset p { font-size:14px; line-height:20px; color:#868686; padding-bottom:20px }
            .sf-reset strong { font-weight:bold; }
            .sf-reset a { color:#6c6159; }
            .sf-reset a img { border:none; }
            .sf-reset a:hover { text-decoration:underline; }
            .sf-reset em { font-style:italic; }
            .sf-reset h2 { font: 20px Arial, Verdana, sans-serif; color: #3C3C3B; }
            .sf-reset h2 span {
                background-color: #fff;
                color: #333;
                padding: 6px;
                float: left;
                margin-right: 10px;
                color: #ED7060;
                border-radius: 5px;
                -webkit-border-radius: 5px;
                -moz-border-radius: 5px;
            }
            .sf-reset .traces li { font-size:15px; padding: 2px 4px; list-style-type:decimal; margin-left:20px; margin-top:15px; }
            .sf-reset .block { background-color:#FFFFFF; padding:10px 28px; margin-bottom:20px;
                border-bottom:1px solid #ccc;
                border-right:1px solid #ccc;
                border-left:1px solid #ccc;
            }
            .sf-reset .block_exception {
                background-color:#ddd;
                color: #333;
                padding:20px;
                -webkit-border-top-left-radius: 16px;
                -webkit-border-top-right-radius: 16px;
                -moz-border-radius-topleft: 16px;
                -moz-border-radius-topright: 16px;
                border-top-left-radius: 16px;
                border-top-right-radius: 16px;
                border-top:1px solid #ccc;
                border-right:1px solid #ccc;
                border-left:1px solid #ccc;
                overflow: hidden;
                word-wrap: break-word;
                background-color: #719AAF;
            }
            .sf-reset li a { background:none; color:#868686; text-decoration:none; }
            .sf-reset li a:hover { background:none; color:#313131; text-decoration:underline; }
            .sf-reset ol { padding: 10px 0; }
            .sf-reset h1 {
                height:510px;
            }
            .sf-reset h1 span { color:#646363; display:inline-block; margin-top:430px; margin-left:190px; font-size:28px; }
EOF;
    }
示例#21
0
    public function getContent(FlattenException $exception)
    {
        switch ($exception->getStatusCode()) {
            case 404:
                $title = 'Sorry, the page you are looking for could not be found.';
                break;
            default:
                $title = 'Whoops, looks like something went wrong.';
        }
        $content = '';
        if ($this->debug) {
            try {
                $count = count($exception->getAllPrevious());
                $total = $count + 1;
                $truncated = 0;
                foreach ($exception->toArray() as $position => $e) {
                    if (mb_strlen($content, '8bit') > 12 * 1024 * 1024) {
                        $truncated++;
                        continue;
                    }
                    $ind = $count - $position + 1;
                    $class = $this->formatClass($e['class']);
                    $message = nl2br($this->escapeHtml($e['message']));
                    $contentTemplate = <<<EOF
                        <h2 class="block_exception clear_fix">
                            <span class="exception_counter">%d/%d</span>
                            <span class="exception_title">%s (%d)%s:</span>
                            <span class="exception_message">%s</span>
                        </h2>
                        <div class="block">
EOF;
                    $content .= sprintf($contentTemplate, $ind, $total, $class, empty($e['code']) ? 0 : $e['code'], $this->formatPath($e['trace'][0]['file'], $e['trace'][0]['line']), $message);
                    if (!empty($e['data'])) {
                        $content .= '<h2>Data</h2>';
                        $content .= '<pre>' . json_encode($e['data'], JSON_PRETTY_PRINT) . '</pre>';
                    }
                    $content .= '<h2 style="margin-top:10px">Trace</h2>';
                    $content .= '<ol class="traces list_exception">';
                    foreach ($e['trace'] as $trace) {
                        $content .= '       <li>';
                        if ($trace['function']) {
                            $content .= sprintf('at %s%s%s(%s)', $this->formatClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args']));
                        }
                        if (isset($trace['file']) && isset($trace['line'])) {
                            $content .= $this->formatPath($trace['file'], $trace['line']);
                        }
                        $content .= "</li>\n";
                    }
                    $content .= "    </ol>\n</div>\n";
                }
                $content .= sprintf('<div class="block">%s exceptions truncated</div>', $truncated);
            } catch (\Exception $e) {
                // something nasty happened and we cannot throw an exception anymore
                if ($this->debug) {
                    $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage());
                } else {
                    $title = 'Whoops, looks like something went wrong.';
                }
            }
        }
        return <<<EOF
            <div id="sf-resetcontent" class="sf-reset">
                <h1>{$title}</h1>
                {$content}
            </div>
EOF;
    }
 /**
  * Converts an Exception to a SoapFault Response.
  *
  * @param Request              $request   The request
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  *
  * @return Response
  *
  * @throws \LogicException When the request query parameter "_besimple_soap_webservice" does not exist
  */
 public function exceptionAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     if (!($webservice = $request->query->get('_besimple_soap_webservice'))) {
         throw new \LogicException(sprintf('The parameter "%s" is required in Request::$query parameter bag to generate the SoapFault.', '_besimple_soap_webservice'), null, $e);
     }
     $view = 'TwigBundle:Exception:' . ($this->container->get('kernel')->isDebug() ? 'exception' : 'error') . '.txt.twig';
     $code = $exception->getStatusCode();
     $details = $this->container->get('templating')->render($view, array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger));
     $handler = new ExceptionHandler($exception, $details);
     if ($soapFault = $request->query->get('_besimple_soap_fault')) {
         $handler->setSoapFault($soapFault);
         // Remove parameter from query because cannot be Serialized in Logger
         $request->query->remove('_besimple_soap_fault');
     }
     $server = SoapServerBuilder::createWithDefaults()->withWsdl(__DIR__ . '/../Handler/wsdl/exception.wsdl')->withWsdlCacheNone()->withHandler($handler)->build();
     ob_start();
     $server->handle('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://besim.pl/soap/exception/1.0/">' . '<soapenv:Header/>' . '<soapenv:Body>' . '<ns:exception />' . '</soapenv:Body>' . '</soapenv:Envelope>');
     return new Response(ob_get_clean());
 }
示例#23
0
 public function error(FlattenException $exception)
 {
     $data = ['styles' => ['/files/lib/bootstrap/3.2.0/css/bootstrap.css']];
     return $this->render($exception->getStatusCode(), $data, Template::FILTER_ESCAPE, [], null, dirname(__DIR__) . '/Core/templates/');
 }
示例#24
0
    /**
     * Gets the HTML content associated with the given exception.
     *
     * @param FlattenException $exception A FlattenException instance
     * @param bool             $showAll   Show all exceptions or just the last one
     *
     * @return string The content as a string
     */
    public function getContent(FlattenException $exception, $showAll = true)
    {
        switch ($exception->getStatusCode()) {
            case 404:
                $title = "The page you are looking for could not be found";
                break;
            default:
                $title = "Oh noes, something's broken";
        }
        $content = '';
        if ($this->debug) {
            try {
                $exceptions = $exception->toArray();
                if (false === $showAll) {
                    $exceptions = array_slice($exceptions, -1, 1);
                    $count = 1;
                    $total = 1;
                } else {
                    $count = count($exception->getAllPrevious());
                    $total = $count + 1;
                }
                foreach ($exceptions as $position => $e) {
                    $i = 0;
                    $class = $this->abbrClass($e['class']);
                    $message = nl2br($e['message']);
                    if (false === $showAll) {
                        $content .= sprintf(<<<EOT
                        <div>
                            <h3 class="alert alert-error">%s: %s</h3>
                        </div>
EOT
, $class, $message);
                    } else {
                        $ind = $count - $position + 1;
                        $content .= sprintf(<<<EOT
                        <div>
                            <h3 class="alert alert-error">%d/%d %s: %s</h3>
                        </div>
EOT
, $ind, $total, $class, $message);
                    }
                    $content .= <<<EOT
                        <div>
                            <table class="table table-bordered table-striped"><tbody>
EOT;
                    foreach ($e['trace'] as $trace) {
                        $i++;
                        $content .= '       <tr><td>' . $i . '</td><td>';
                        if ($trace['function']) {
                            $content .= sprintf('at %s%s%s(%s)', $this->abbrClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args']));
                        }
                        if (isset($trace['file']) && isset($trace['line'])) {
                            if ($linkFormat = ini_get('xdebug.file_link_format')) {
                                $link = str_replace(array('%f', '%l'), array($trace['file'], $trace['line']), $linkFormat);
                                $content .= sprintf(' in <a href="%s" title="Go to source">%s line %s</a>', $link, $trace['file'], $trace['line']);
                            } else {
                                $content .= sprintf(' in %s line %s', $trace['file'], $trace['line']);
                            }
                        }
                        $content .= "</td</tr>\n";
                    }
                    $content .= "    </tbody></table>\n</div>\n";
                }
            } catch (\Exception $e) {
                // something nasty happened and we cannot throw an exception anymore
                if ($this->debug) {
                    $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($exception), $exception->getMessage());
                } else {
                    $title = "Uh oh something's broken";
                }
            }
        }
        list($quote, $author) = $this->getQuote();
        $statusCode = $exception->getStatusCode();
        $ppiLogo = $this->getPpiLogo();
        return <<<EOF
            <div class="page-header well">
                <h1 title="An exception has occurred - Code {$statusCode}"><img src="{$ppiLogo}" height="56" width="89">&nbsp;{$title}.</h1>
                <p class="muted quote"><i>"{$quote}"</i> &mdash; {$author}</p>
            </div>
            <div class="ppi-container well">
                {$content}
            </div>
EOF;
    }
 /**
  * Process and render 
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @param \Symfony\Component\HttpKernel\Exception\FlattenException $exception
  * @param String $template
  * @return Response
  */
 public function showAction(Request $request, FlattenException $exception, $template)
 {
     $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $code = $exception->getStatusCode();
     return $this->templating->renderResponse($template, array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $this->logger, 'currentContent' => $currentContent));
 }