本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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)));
}
示例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));
}
示例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');
}
示例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] : '']);
}
示例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);
}
示例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]);
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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());
}
示例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'])));
}
}