当前位置: 首页>>代码示例>>PHP>>正文


PHP Exception\FlattenException类代码示例

本文整理汇总了PHP中Symfony\Component\HttpKernel\Exception\FlattenException的典型用法代码示例。如果您正苦于以下问题:PHP FlattenException类的具体用法?PHP FlattenException怎么用?PHP FlattenException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FlattenException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: showAction

    /**
     * Converts an Exception to a Response.
     *
     * @param FlattenException     $exception A FlattenException instance
     * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
     * @param string               $format    The format to use for rendering (html, xml, ...)
     *
     * @throws \InvalidArgumentException When the exception template does not exist
     */
    public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
    {
        $this->container->get('request')->setRequestFormat($format);

        // the count variable avoids an infinite loop on
        // some Windows configurations where ob_get_level()
        // never reaches 0
        $count = 100;
        $currentContent = '';
        while (ob_get_level() && --$count) {
            $currentContent .= ob_get_clean();
        }

        $templating = $this->container->get('templating');
        $code = $exception->getStatusCode();

        $response = $templating->renderResponse(
            $this->findTemplate($templating, $format, $code, $this->container->get('kernel')->isDebug()),
            array(
                'status_code'    => $code,
                'status_text'    => Response::$statusTexts[$code],
                'exception'      => $exception,
                'logger'         => $logger,
                'currentContent' => $currentContent,
            )
        );

        $response->setStatusCode($code);
        $response->headers->replace($exception->getHeaders());

        return $response;
    }
开发者ID:pmjones,项目名称:php-framework-benchmarks,代码行数:41,代码来源:ExceptionController.php

示例2: showAction

 /**
  * Converts an Exception to a Response.
  *
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  * @param string               $format    The format to use for rendering (html, xml, ...)
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  */
 public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
 {
     $this->container->get('request')->setRequestFormat($format);
     // the count variable avoids an infinite loop on
     // some Windows configurations where ob_get_level()
     // never reaches 0
     $count = 100;
     $currentContent = '';
     while (ob_get_level() && --$count) {
         $currentContent .= ob_get_clean();
     }
     $name = $this->container->get('kernel')->isDebug() ? 'exception' : 'error';
     if ($this->container->get('kernel')->isDebug() && 'html' == $format) {
         $name = 'exception_full';
     }
     $template = 'FrameworkBundle:Exception:' . $name . '.' . $format . '.twig';
     $templating = $this->container->get('templating');
     if (!$templating->exists($template)) {
         $this->container->get('request')->setRequestFormat('html');
         $template = 'FrameworkBundle:Exception:' . $name . '.html.twig';
     }
     $code = $exception->getStatusCode();
     $response = $templating->renderResponse($template, array('status_code' => $code, 'status_text' => Response::$statusTexts[$code], 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent));
     $response->setStatusCode($code);
     $response->headers->replace($exception->getHeaders());
     return $response;
 }
开发者ID:nickaggarwal,项目名称:sample-symfony2,代码行数:36,代码来源:ExceptionController.php

示例3: showAction

 /**
  * Converts an Exception to a Response.
  *
  * @param Request              $request   The request
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  * @param string               $format    The format to use for rendering (html, xml, ...)
  *
  * @return Response
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
 {
     $request->setRequestFormat($format);
     $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $code = $exception->getStatusCode();
     return new Response($this->twig->render($this->findTemplate($request, $format, $code, $this->debug), array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent)));
 }
开发者ID:chongsheng,项目名称:book_shop,代码行数:19,代码来源:ExceptionController.php

示例4: showAction

 /**
  * Converts an Exception to a Response.
  *
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  * @param string               $format    The format to use for rendering (html, xml, ...)
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  */
 public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
 {
     $this->container->get('request')->setRequestFormat($format);
     $code = $exception->getStatusCode();
     $params = array('status_code' => $code, 'status_text' => Response::$statusTexts[$code]);
     try {
         $params['auth'] = $this->container->get('security.context')->isGranted('IS_AUTHENTICATED_REMEMBERED');
     } catch (\Exception $e) {
         $params['auth'] = false;
     }
     $templating = $this->container->get('templating');
     if (404 == $code) {
         if ($this->container->get('request')->isXmlHttpRequest()) {
             $response = new Response('You should not do that.');
         } else {
             $response = $templating->renderResponse('LichessBundle:Exception:notFound.html.twig', $params);
         }
     } else {
         if ($this->container->get('request')->isXmlHttpRequest()) {
             $response = new Response('Something went terribly wrong.');
         } else {
             $params['url'] = !empty($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : $_SERVER['REQUEST_URI'];
             $response = $templating->renderResponse('LichessBundle:Exception:error.html.twig', $params);
         }
     }
     $response->setStatusCode($code);
     $response->headers->replace($exception->getHeaders());
     return $response;
 }
开发者ID:hafeez3000,项目名称:lichess,代码行数:38,代码来源:ExceptionController.php

示例5: showAction

 public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
 {
     $isDebug = $this->container->get('kernel')->isDebug();
     $this->request = $this->container->get('request');
     //TODO: there might be a case in the future that we will use other formats, but right now let's make this simple and always use an html template
     $this->request->setRequestFormat('html');
     $currentContent = $this->getAndCleanOutputBuffering();
     $errorMessages = $this->container->getParameter('error_messages');
     $templating = $this->container->get('templating');
     $code = $exception->getStatusCode();
     $factory = $this->container->get('form.factory');
     $form = $factory->create(new ErrorReportFormType());
     if ($this->request->server->has('PATH_INFO')) {
         $pathInfo = $this->request->server->get('PATH_INFO');
     } else {
         $pathInfo = $this->request->server->get('REQUEST_URI');
     }
     if (\preg_match('/admin/i', $pathInfo)) {
         $statusTextDescriptions = $errorMessages['admin'];
     } elseif (\preg_match('/institution/i', $pathInfo)) {
         $statusTextDescriptions = $errorMessages['institution'];
     } else {
         $statusTextDescriptions = $errorMessages['frontend'];
     }
     if ($this->request->server->has('HTTP_REFERER')) {
         if (\preg_match('/healthcareabroad/i', $this->request->server->get('HTTP_REFERER'))) {
             $referer = $this->request->server->get('HTTP_REFERER');
         }
     } else {
         $referer = null;
     }
     return $templating->renderResponse($this->findTemplate($templating, $format, $code, $isDebug, $referer), array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) && Response::$statusTexts[$code] ? Response::$statusTexts[$code] : 'Error', 'status_text_details' => isset($statusTextDescriptions[$code]) ? $statusTextDescriptions[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent, 'form' => $form->createView(), 'referer' => $referer));
 }
开发者ID:TMBaay,项目名称:MEDTrip---Healthcareabroad,代码行数:33,代码来源:CustomExceptionController.php

示例6: getContent

    /**
     * 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;
    }
开发者ID:ronnylt,项目名称:symfony,代码行数:67,代码来源:ExceptionHandler.php

示例7: showAction

 /**
  * 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($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)));
 }
开发者ID:RuntyCybin,项目名称:csymfony,代码行数:23,代码来源:ExceptionController.php

示例8: showAction

 /**
  * Converts an Exception to a Response.
  *
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  * @param string               $format    The format to use for rendering (html, xml, ...)
  *
  * @return Response
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  */
 public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
 {
     $this->container->get('request')->setRequestFormat($format);
     $currentContent = $this->getAndCleanOutputBuffering();
     $templating = $this->container->get('templating');
     $code = $exception->getStatusCode();
     return $templating->renderResponse($this->findTemplate($templating, $format, $code, $this->container->get('kernel')->isDebug()), array('status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent));
 }
开发者ID:joan16v,项目名称:symfony2_test,代码行数:19,代码来源:ExceptionController.php

示例9: exceptionAction

 public function exceptionAction(FlattenException $exception)
 {
     // $msg = 'Something went wrong! ('.$exception->getMessage().')';
     //
     // return new Response($msg, $exception->getStatusCode());
     $msg = 'Something went wrong!';
     return new Response($msg, $exception->getStatusCode());
 }
开发者ID:opensourcerefinery,项目名称:vicus,代码行数:8,代码来源:ErrorController.php

示例10: errorAction

 public function errorAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
 {
     $this->container->get('request')->setRequestFormat($format);
     $response = new Response('Something is wrong');
     $code = $exception->getStatusCode();
     $response->setStatusCode($code);
     $response->headers->replace($exception->getHeaders());
     return $response;
 }
开发者ID:hafeez3000,项目名称:lichess,代码行数:9,代码来源:SyncController.php

示例11: showAction

 public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
 {
     $statusCode = $exception->getStatusCode();
     $statusText = $exception->getMessage();
     $response = $this->render('GitonomyWebsiteBundle:Error:error.html.twig', array('status_code' => $statusCode, 'status_text' => $statusText));
     $response->setStatusCode($statusCode);
     $response->headers->replace($exception->getHeaders());
     return $response;
 }
开发者ID:phecho,项目名称:gitonomy,代码行数:9,代码来源:ErrorController.php

示例12: showAction

 /**
  * Converts an Exception to a Response.
  *
  * @param Request $request The request
  * @param FlattenException $exception A FlattenException instance
  * @param DebugLoggerInterface $logger A DebugLoggerInterface instance
  *
  * @param string $_format
  * @return JsonResponse
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $_format = 'html')
 {
     $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
     $wrapper = new ExceptionWrapper();
     $wrapper->setCode($exception->getCode());
     $wrapper->setMessage($exception->getMessage());
     $wrapper->setStatusCode($exception->getStatusCode());
     $wrapper->setTrace($this->debug ? $exception->getTrace() : array());
     return $wrapper->getResponse();
 }
开发者ID:ismailbaskin,项目名称:EasyRestBundle,代码行数:20,代码来源:ExceptionController.php

示例13: showAction

 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     // IF an API URL, show the result as JSON - otherwise show HTML format
     $format = strncmp($request->getPathInfo(), '/api/', strlen('/api/')) == 0 ? 'json' : 'html';
     $request->setRequestFormat($format);
     $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($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)));
 }
开发者ID:johnprice99,项目名称:predictions,代码行数:11,代码来源:ExceptionController.php

示例14: exceptionAction

 /**
  * Converts an Exception to a Response.
  *
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  * @param string               $format    The format to use for rendering (html, xml, ...)
  * @param Boolean              $embedded  Whether the rendered Response will be embedded or not
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  */
 public function exceptionAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html', $embedded = false)
 {
     $this->container->get('request')->setRequestFormat($format);
     $currentContent = '';
     while (false !== ($content = ob_get_clean())) {
         $currentContent .= $content;
     }
     $response = $this->container->get('templating')->renderResponse('FrameworkBundle:Exception:' . ($this->container->get('kernel')->isDebug() ? 'exception' : 'error'), array('exception' => new SafeDecorator($exception), 'logger' => $logger, 'currentContent' => $currentContent, 'embedded' => $embedded));
     $response->setStatusCode($exception->getStatusCode());
     return $response;
 }
开发者ID:skoop,项目名称:symfony-sandbox,代码行数:21,代码来源:ExceptionController.php

示例15: getStatusCode

 protected function getStatusCode(FlattenException $exception)
 {
     switch ($exception->getClass()) {
         case 'Symfony\\Component\\Security\\Exception\\AccessDeniedException':
             return 403;
         case 'Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException':
             return 404;
         default:
             return 500;
     }
 }
开发者ID:notbrain,项目名称:symfony,代码行数:11,代码来源:ExceptionController.php


注:本文中的Symfony\Component\HttpKernel\Exception\FlattenException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。