當前位置: 首頁>>代碼示例>>PHP>>正文


PHP FlattenException::getStatusCode方法代碼示例

本文整理匯總了PHP中Symfony\Component\Debug\Exception\FlattenException::getStatusCode方法的典型用法代碼示例。如果您正苦於以下問題:PHP FlattenException::getStatusCode方法的具體用法?PHP FlattenException::getStatusCode怎麽用?PHP FlattenException::getStatusCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Debug\Exception\FlattenException的用法示例。


在下文中一共展示了FlattenException::getStatusCode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: showExceptionAction

 /**
  * Сериализует исключение и возвращает исключение.
  * 
  * @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);
 }
開發者ID:zewwwid,項目名稱:task-manager,代碼行數:20,代碼來源:ExceptionController.php

示例2: exceptionAction

 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);
 }
開發者ID:pixocode,項目名稱:noostache,代碼行數:7,代碼來源:PageController.php

示例3: handleException

 /**
  * @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;
 }
開發者ID:spryker,項目名稱:Application,代碼行數:12,代碼來源:SubRequestExceptionHandler.php

示例4: 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((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)));
 }
開發者ID:ninvfeng,項目名稱:symfony,代碼行數:23,代碼來源:ExceptionController.php

示例5: dispatch

 /**
  * @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));
 }
開發者ID:spryker,項目名稱:Application,代碼行數:15,代碼來源:ExceptionHandlerDispatcher.php

示例6: exceptionAction

 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');
 }
開發者ID:hidekscorporation,項目名稱:hideksframework2,代碼行數:9,代碼來源:ErrorController.php

示例7: showAction

 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] : '']);
 }
開發者ID:surfnet,項目名稱:stepup-bundle,代碼行數:10,代碼來源:ExceptionController.php

示例8: 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)
 {
     $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);
 }
開發者ID:e-moe,項目名稱:data-service,代碼行數:26,代碼來源:ExceptionController.php

示例9: showAction

 /**
  * @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]);
     }
 }
開發者ID:8785496,項目名稱:record,代碼行數:18,代碼來源:ExceptionController.php

示例10: showExceptionAction

 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);
 }
開發者ID:vitiko,項目名稱:IphpRedirectNotFoundBundle,代碼行數:11,代碼來源:ExceptionController.php

示例11: exceptionAction

 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;
 }
開發者ID:agitation,項目名稱:page-bundle,代碼行數:15,代碼來源:CatchallController.php

示例12: listAction

 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);
 }
開發者ID:symfony-cmf,項目名稱:seo-bundle,代碼行數:18,代碼來源:SuggestionProviderController.php

示例13: __invoke

 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);
 }
開發者ID:flint,項目名稱:brick,代碼行數:18,代碼來源:ExceptionController.php

示例14: showAction

 /**
  * 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());
 }
開發者ID:amirkheirabadi,項目名稱:pagekit,代碼行數:29,代碼來源:ExceptionController.php

示例15: showAction

 /**
  * {@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'])));
     }
 }
開發者ID:Jandersolutions,項目名稱:mautic,代碼行數:45,代碼來源:ExceptionController.php


注:本文中的Symfony\Component\Debug\Exception\FlattenException::getStatusCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。