/** * {inheritdoc}. */ public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null) { //always enforce non-debug mode $this->debug = false; $response = parent::showAction($request, $exception, $logger); $response->setStatusCode($exception->getStatusCode()); $response->headers->set(ResponseHeaders::ERROR_HANDLED_HEADER, true); return $response; }
public function testFallbackToHtmlIfNoTemplateForRequestedFormat() { $twig = new \Twig_Environment(new \Twig_Loader_Array(array('TwigBundle:Exception:error.html.twig' => 'html'))); $request = Request::create('whatever'); $request->setRequestFormat('txt'); $controller = new ExceptionController($twig, false); $response = $controller->testErrorPageAction($request, 42); $this->assertEquals('html', $request->getRequestFormat()); }
public function testFallbackToHtmlIfNoTemplateForRequestedFormat() { $twig = new \Twig_Environment(new \Twig_Loader_Array(array('TwigBundle:Exception:error.html.twig' => 'html'))); $request = Request::create('whatever'); $request->headers->set('X-Php-Ob-Level', 1); $request->setRequestFormat('txt'); $exception = FlattenException::create(new \Exception()); $controller = new ExceptionController($twig, false); $response = $controller->showAction($request, $exception); $this->assertEquals('html', $request->getRequestFormat()); }
public function testOnlyClearOwnOutputBuffers() { $flatten = $this->getMock('Symfony\\Component\\HttpKernel\\Exception\\FlattenException'); $flatten->expects($this->once())->method('getStatusCode')->will($this->returnValue(404)); $twig = $this->getMockBuilder('\\Twig_Environment')->disableOriginalConstructor()->getMock(); $twig->expects($this->any())->method('render')->will($this->returnValue($this->getMock('Symfony\\Component\\HttpFoundation\\Response'))); $twig->expects($this->any())->method('getLoader')->will($this->returnValue($this->getMock('\\Twig_LoaderInterface'))); $request = Request::create('/'); $request->headers->set('X-Php-Ob-Level', 1); $controller = new ExceptionController($twig, false); $controller->showAction($request, $flatten); }
/** * @param TemplateReference $template * * @return bool */ protected function templateExists($template) { if ($this->isBackoffice() || $this->inBackofficeRoot()) { $template = '@ClasticBackofficeBundle/Exception/exception_full.html.twig'; } return parent::templateExists($template); }
protected function findTemplate($templating, $format, $code, $debug) { if (!$debug && $this->exceptionClass == 'Yoda\\EventBundle\\Exception\\EventNotFoundHttpException') { return 'EventBundle:Exception:event404.html.twig'; } return parent::findTemplate($templating, $format, $code, $debug); }
/** * @param Request $request * @param string $format * @param int $code * @param bool $debug * * @return TemplateReference */ protected function findTemplate(Request $request, $format, $code, $debug) { if (strpos($request->getPathInfo(), '/admin') !== 0) { return parent::findTemplate($request, $format, $code, $debug); } $name = $debug ? 'exception' : 'error'; if ($debug && 'html' == $format) { $name = 'exception_full'; } // when not in debug, try to find a template for the specific HTTP status code and format if (!$debug) { $template = new TemplateReference('AvanzuAdminThemeBundle', 'Exception', $name . $code, $format, 'twig'); if ($this->templateExists($template)) { return $template; } } // try to find a template for the given format $template = new TemplateReference('AvanzuAdminThemeBundle', 'Exception', $name, $format, 'twig'); if ($this->templateExists($template)) { return $template; } // default to a generic HTML exception $request->setRequestFormat('html'); $template = new TemplateReference('AvanzuAdminThemeBundle', 'Exception', $name, 'html', 'twig'); if ($this->templateExists($template)) { return $template; } return parent::findTemplate($request, $format, $code, $debug); }
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null) { if ($exception->getClass() == MailException::class) { return new Response($this->twig->render('CantigaCoreBundle:Exception:mail-exception.html.twig', array('message' => $exception->getMessage())), 501); } return parent::showAction($request, $exception, $logger); }
/** * @param Request $request * @param string $format * @param int $code An HTTP response status code * @param bool $showException * * @return string */ protected function findTemplate(Request $request, $format, $code, $showException) { if (!$showException) { if ($this->templateExists($this->exceptionTemplate)) { return $this->exceptionTemplate; } } return parent::findTemplate($request, $format, $code, $showException); }
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html') { $code = $exception->getStatusCode(); if (!$this->debug) { $template = new TemplateReference(sprintf('@SymEdit/Exception/%d.html.twig', $code)); if ($this->templateExists($template)) { return new Response($this->twig->render($template, ['status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger])); } } return parent::showAction($request, $exception, $logger, $format); }
/** * {@inheritdoc} */ protected function findTemplate(Request $request, $format, $code, $debug) { if (!$debug && $format === 'html') { $code = in_array($code, array(400, 403, 404, 503)) ? $code : 500; $template = new TemplateReference('ClarolineCoreBundle', 'Exception', 'error' . $code, 'html', 'twig'); if ($this->templateExists($template)) { return $template; } } return parent::findTemplate($request, $format, $code, $debug); }
/** * {@inheritdoc} */ public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null) { $code = $exception->getStatusCode(); $showException = $request->attributes->get('showException', $this->debug); $template = $this->requestAnalyzer->getWebspace()->getTheme()->getErrorTemplate($code); if ($showException || $request->getRequestFormat() !== 'html' || $template === null) { return parent::showAction($request, $exception, $logger); } $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1)); $parameter = ['status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'currentContent' => $currentContent]; $data = $this->parameterResolver->resolve($parameter, $this->requestAnalyzer); return new Response($this->twig->render($template, $data), $code); }
/** * {@inheritDoc} * @see Symfony\Bundle\TwigBundle\Controller\ExceptionController::showAction */ public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null) { if ($exception->getStatusCode() != 404 || $request->getRequestFormat() != 'html') { return parent::showAction($request, $exception, $logger); } // 404 html $randomLine = $this->lineRepo->getRandom(1)[0]; // from parent $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), ['random_line' => $randomLine, 'status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent])); }
/** * @param Request $request * @param FlattenException $exception * @param DebugLoggerInterface $logger * @param string $_format * @return Response */ public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $_format = 'html') { $code = $exception->getStatusCode(); if (404 !== $code) { return parent::showAction($request, $exception, $logger, $_format); } $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($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, 'best_matches' => $groupedSuggestions)), $code); }
protected function findTemplate(Request $request, $format, $code, $showException) { $template = parent::findTemplate($request, $format, $code, $showException); // Only customize error display for PJAX requests. if (!$request->headers->has('X-PJAX')) { return $template; } $customTemplate = clone $template; $customTemplate->set('bundle', 'eZPlatformUIBundle'); if ($this->templateExists($customTemplate)) { return $customTemplate; } return $template; }
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html') { if ('Trez\\LogicielTrezBundle\\Exception\\LockedException' === $exception->getClass()) { $this->session->getFlashBag()->set('error', "Vous ne pouvez pas éditer un exercice/budget verrouillé ou ses fils"); return new RedirectResponse($this->request->getRequestUri(), 302); } if ('Symfony\\Component\\HttpKernel\\Exception\\AccessDeniedHttpException' === $exception->getClass()) { $this->session->getFlashBag()->set('error', "Vous n'avez pas les privilèges nécessaires pour effectuer cette action !"); if ($this->securityContext->isGranted('ROLE_USER') === true) { return new Response($this->twig->render('TrezLogicielTrezBundle:Default:index.html.twig', array())); } else { return new Response("Vous n'avez pas les privilèges nécessaires pour afficher cette page !"); } } // else default behavior return parent::showAction($exception, $logger, $format); }
protected function findTemplate($templating, $format, $code, $debug) { if ($debug) { // debug return parent::findTemplate($templating, $format, $code, $debug); } if ($this->request->server->has('PATH_INFO')) { $pathInfo = $this->request->server->get('PATH_INFO'); } else { $pathInfo = $this->request->server->get('REQUEST_URI'); } // check if this path is /admin/ if (\preg_match('/^\\/admin\\//', $pathInfo)) { $template = new TemplateReference('AdminBundle', 'Exception', 'error', 'html', 'twig'); } elseif (\preg_match('/^\\/institution\\//', $pathInfo)) { $template = new TemplateReference('InstitutionBundle', 'Exception', 'error', 'html', 'twig'); } else { // assume we are in frontend $template = new TemplateReference('FrontendBundle', 'Exception', 'error', 'html', 'twig'); } if ($templating->exists($template)) { return $template; } }
/** * Return the template for rendering a status code * * @param Request $request * @param string $format * @param integer $code Status code to locate a template * @param bool $showException * * @return TemplateReferenceInterface */ protected function findTemplate(Request $request, $format, $code, $showException) { if (!$this->supports($request)) { return parent::findTemplate($request, $format, $code, $showException); } return $this->templateLocator->locate(isset($this->templateByCode[$code]) ? $this->templateByCode[$code] : $this->defaultTemplate); }
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null) { $this->exceptionClass = $exception->getClass(); return parent::showAction($request, $exception, $logger); // TODO: Change the autogenerated stub }
public function __construct(\Twig_Environment $twig, $debug) { parent::__construct($twig, $debug); }
public function __construct(\Twig_Environment $twig, $debug, ParameterResolverInterface $parameterResolver, RequestAnalyzerInterface $requestAnalyzer = null) { parent::__construct($twig, $debug); $this->requestAnalyzer = $requestAnalyzer; $this->parameterResolver = $parameterResolver; }
/** * @param \Twig_Environment $twig * @param bool $debug * @param RequestMatcherInterface $requestMatcher The exclusion matcher to decider whether a route should be handled * by this error handling. It uses the defined exclusion_rules in the * error configuration. * @param array $templates Containing the configured templates to use in custom error cases. */ public function __construct(\Twig_Environment $twig, $debug, RequestMatcherInterface $requestMatcher, $templates) { $this->templates = $templates; $this->exclusionRequestMatcher = $requestMatcher; parent::__construct($twig, $debug); }