本文整理汇总了PHP中Symfony\Component\Debug\Exception\FlattenException类的典型用法代码示例。如果您正苦于以下问题:PHP FlattenException类的具体用法?PHP FlattenException怎么用?PHP FlattenException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FlattenException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: showAction
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);
}
示例2: 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;
}
示例3: 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);
}
示例4: __invoke
/**
* Converts a {@see \Symfony\Component\Debug\Exception\FlattenException}
* to a {@see \Dunglas\ApiBundle\JsonLd\Response}.
*
* @param FlattenException $exception
*
* @return Response
*/
public function __invoke(FlattenException $exception)
{
$exceptionClass = $exception->getClass();
if (is_a($exceptionClass, ExceptionInterface::class, true) || is_a($exceptionClass, InvalidArgumentException::class, true)) {
$exception->setStatusCode(Response::HTTP_BAD_REQUEST);
}
return new Response($this->normalizer->normalize($exception, 'hydra-error'), $exception->getStatusCode(), $exception->getHeaders());
}
示例5: 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)));
}
示例6: 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));
}
示例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: 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);
}
示例9: showAction
/**
* Converts an Exception to a Response.
*
* @param Request $request
* @param FlattenException $exception
* @return Response
*/
public function showAction(Request $request, FlattenException $exception)
{
if (is_subclass_of($exception->getClass(), 'Pagekit\\Kernel\\Exception\\HttpException')) {
$title = $exception->getMessage();
} else {
$title = __('Whoops, looks like something went wrong.');
}
$content = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));
$response = App::view('system/error.php', compact('title', 'exception', 'content'));
return App::response($response, $exception->getCode(), $exception->getHeaders());
}
示例10: 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);
}
示例11: 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]);
}
}
示例12: 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);
}
示例13: 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;
}
示例14: handleKernelException
public function handleKernelException(GetResponseForExceptionEvent $event)
{
if ($this->container->get('kernel')->getEnvironment() !== 'dev') {
$exception = FlattenException::create($event->getException());
// First, log the exception to the standard error logs.
$this->container->get('logger')->error(' In File ' . $exception->getFile() . ', on line ' . $exception->getLine() . ': ' . $exception->getMessage());
// Determine what the HTTP status code should be.
if ($event->getException() instanceof \Symfony\Component\HttpKernel\Exception\HttpException) {
$httpStatusCode = $event->getException()->getStatusCode();
} else {
$httpStatusCode = $exception->getCode();
if ($exception->getCode() < 100 || $exception->getCode() >= 600) {
$httpStatusCode = 500;
}
}
$parameters = ['status_code' => $httpStatusCode, 'status_text' => $exception->getMessage(), 'exception' => $exception];
if (in_array('application/json', $event->getRequest()->getAcceptableContentTypes())) {
$errorContent = $this->container->get('templating')->render(':default:exception.json.twig', $parameters);
} else {
$errorContent = $this->container->get('templating')->render(':default:error.html.twig', $parameters);
}
$response = new Response($errorContent, $httpStatusCode);
$response->setProtocolVersion('1.1');
$event->setResponse($response);
}
}
示例15: sendException
public function sendException($exception)
{
if (!$this->isErrorFromBot()) {
$recipients = Config::get("error-emailer::to");
if (isset($recipients['address'])) {
// this is a single recipient
if ($recipients['address']) {
$recipients = array($recipients);
} else {
$recipients = array();
}
}
if (sizeof($recipients) > 0) {
if ($exception instanceof FlattenException) {
$flattened = $exception;
} else {
$flattened = FlattenException::create($exception);
}
$handler = new ExceptionHandler();
$content = $handler->getContent($flattened);
$model = array('trace' => $content, 'exception' => $exception, 'flattened' => $flattened);
Mail::send(Config::get("error-emailer::error_template"), $model, function ($message) use($model, $recipients) {
$subject = View::make(Config::get("error-emailer::subject_template"), $model)->render();
$message->subject($subject);
foreach ($recipients as $to) {
$message->to($to['address'], $to['name']);
}
});
}
}
}