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


PHP GetResponseForExceptionEvent::setException方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent::setException方法的典型用法代码示例。如果您正苦于以下问题:PHP GetResponseForExceptionEvent::setException方法的具体用法?PHP GetResponseForExceptionEvent::setException怎么用?PHP GetResponseForExceptionEvent::setException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent的用法示例。


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

示例1: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if ($this->env != "prod") {
         $event->setException($exception);
         return;
     }
     try {
         $code = 404;
         if ($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) {
             $code = 404;
         } else {
             if ($exception instanceof \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException) {
                 $code = 403;
             }
         }
         $file = $code;
         if ($this->env != "prod") {
             //$file = $file . '.' . $this->env;
         }
         $file = $file . '.html.twig';
         $template = $this->siteManager->getTemplate("portal");
         $template = "SymbbTemplateDefaultBundle:Exception:" . $file;
         $response = new Response($this->templating->render($template, array('status_code' => $code, 'status_text' => $exception->getMessage(), 'exception' => $exception)));
         // setup the Response object based on the caught exception
         $event->setResponse($response);
     } catch (\Exception $exc) {
         $event->setException($exception);
     }
     // you can alternatively set a new Exception
     // $exception = new \Exception('Some special exception');
     // $event->setException($exception);
 }
开发者ID:symbb,项目名称:symbb,代码行数:33,代码来源:ExceptionListener.php

示例2: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if ($exception instanceof NotFoundException) {
         $event->setException(new NotFoundHttpException($this->getTranslatedMessage($exception), $exception));
     } elseif ($exception instanceof UnauthorizedException) {
         $event->setException(new AccessDeniedException($this->getTranslatedMessage($exception), $exception));
     } elseif ($exception instanceof BadStateException || $exception instanceof InvalidArgumentException) {
         $event->setException(new BadRequestHttpException($this->getTranslatedMessage($exception), $exception));
     } elseif ($exception instanceof Translatable) {
         $event->setException(new HttpException(Response::HTTP_INTERNAL_SERVER_ERROR, get_class($exception) . ': ' . $this->getTranslatedMessage($exception), $exception));
     }
 }
开发者ID:Pixy,项目名称:ezpublish-kernel,代码行数:13,代码来源:ExceptionListener.php

示例3: onKernelException

 /**
  * @param GetResponseForExceptionEvent $event
  * @return bool|void
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     static $handling;
     if (true === $handling) {
         return false;
     }
     $handling = true;
     $exception = $event->getException();
     if ($exception instanceof AccessDeniedHttpException) {
         if (StringUtils::startsWith($exception->getMessage(), 'Expression "has_role(\'ROLE_')) {
             $message = 'Bu alana erişebilmek için kullanıcı girişi yapılmalıdır';
             $statusCode = 401;
         } else {
             $message = $exception->getMessage();
             $statusCode = $exception->getStatusCode();
         }
         $exception = new HttpException($statusCode, $message, $exception);
         $event->setException($exception);
         parent::onKernelException($event);
     } elseif ($exception instanceof InsufficientAuthenticationException) {
         $exception = new AccessDeniedHttpException('Bu alana erişebilmek için geçerli bir kullanıcı kimliği belirtilmelidir', $exception);
         $event->setException($exception);
         parent::onKernelException($event);
     }
     $handling = false;
     return false;
 }
开发者ID:Resmin,项目名称:Resmin-Api,代码行数:31,代码来源:AccessDeniedListener.php

示例4: exceptionHandler

 public function exceptionHandler(GetResponseForExceptionEvent $event)
 {
     if ($event->getException() instanceof PluginException) {
         return;
     }
     $event->setException(new PluginException(sprintf('The plugin `%s` from bundle `%s` [%s] errored.', $this->plugin['plugin'], $this->bundleName, $this->pluginDef->getController()), null, $event->getException()));
 }
开发者ID:jarves,项目名称:jarves,代码行数:7,代码来源:TypePlugin.php

示例5: onJsonRpcException

 public function onJsonRpcException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if ($exception instanceof InvalidRequestException) {
         $event->setException(new BadRequestHttpException($exception->getMessage(), $exception));
     }
 }
开发者ID:bankiru,项目名称:jsonrpc-server-bundle,代码行数:7,代码来源:HttpExceptionListener.php

示例6: onException

 /**
  * Catches failed parameter conversions and throw a 404 instead.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
  */
 public function onException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if ($exception instanceof ParamNotConvertedException) {
         $event->setException(new NotFoundHttpException($exception->getMessage(), $exception));
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:12,代码来源:ParamConversionEnhancer.php

示例7: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if (!$exception instanceof BlockadeException) {
         return;
     }
     //try to get a response from one of the resolvers. It
     //could be a redirect, an access denied page, or anything
     //really
     try {
         foreach ($this->resolvers as $resolver) {
             $driver = $exception->getDriver();
             if (!$driver || !$resolver->supportsDriver($driver)) {
                 continue;
             }
             if (!$resolver->supportsException($exception)) {
                 continue;
             }
             $request = $event->getRequest();
             $response = $resolver->onException($exception, $request);
             if ($response instanceof Response) {
                 $event->setResponse($response);
                 return;
             }
         }
         //no response has been created by now, so let other
         //exception listeners handle it
         return;
     } catch (\Exception $e) {
         //if anything at all goes wrong in calling the
         //resolvers, pass the exception on
         $event->setException($e);
     }
 }
开发者ID:glynnforrest,项目名称:blockade,代码行数:34,代码来源:BlockadeExceptionListener.php

示例8: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     static $handling;
     if (true === $handling) {
         return false;
     }
     $request = $event->getRequest();
     if (empty($this->formats[$request->getRequestFormat()]) && empty($this->formats[$request->getContentType()])) {
         return false;
     }
     $handling = true;
     $exception = $event->getException();
     if ($exception instanceof AccessDeniedException) {
         $exception = new AccessDeniedHttpException('You do not have the necessary permissions', $exception);
         $event->setException($exception);
         parent::onKernelException($event);
     } elseif ($exception instanceof AuthenticationException) {
         if ($this->challenge) {
             $exception = new UnauthorizedHttpException($this->challenge, 'You are not authenticated', $exception);
         } else {
             $exception = new HttpException(401, 'You are not authenticated', $exception);
         }
         $event->setException($exception);
         parent::onKernelException($event);
     }
     $handling = false;
 }
开发者ID:mgldev,项目名称:coffeetrack,代码行数:27,代码来源:AccessDeniedListener.php

示例9: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if (!$exception instanceof ParamValidationFailedException) {
         return;
     }
     $event->setException($this->convertException($exception));
 }
开发者ID:alekitto,项目名称:param-fetcher-bundle,代码行数:8,代码来源:ValidationFailedExceptionListener.php

示例10: onCoreException

 /**
  * Handles security related exceptions.
  *
  * @param GetResponseForExceptionEvent $event An GetResponseForExceptionEvent instance
  */
 public function onCoreException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $request = $event->getRequest();
     if ($exception instanceof AuthenticationException) {
         if (null !== $this->logger) {
             $this->logger->info(sprintf('Authentication exception occurred; redirecting to authentication entry point (%s)', $exception->getMessage()));
         }
         try {
             $response = $this->startAuthentication($request, $exception);
         } catch (\Exception $e) {
             $event->setException($e);
             return;
         }
     } elseif ($exception instanceof AccessDeniedException) {
         $token = $this->context->getToken();
         if (!$this->authenticationTrustResolver->isFullFledged($token)) {
             if (null !== $this->logger) {
                 $this->logger->info('Access denied (user is not fully authenticated); redirecting to authentication entry point');
             }
             try {
                 $response = $this->startAuthentication($request, new InsufficientAuthenticationException('Full authentication is required to access this resource.', $token, 0, $exception));
             } catch (\Exception $e) {
                 $event->setException($e);
                 return;
             }
         } else {
             if (null !== $this->logger) {
                 $this->logger->info('Access is denied (and user is neither anonymous, nor remember-me)');
             }
             try {
                 if (null !== $this->accessDeniedHandler) {
                     $response = $this->accessDeniedHandler->handle($request, $exception);
                     if (!$response instanceof Response) {
                         return;
                     }
                 } else {
                     if (null === $this->errorPage) {
                         return;
                     }
                     $subRequest = Request::create($this->errorPage, 'get', array(), $request->cookies->all(), array(), $request->server->all());
                     $subRequest->attributes->set(SecurityContextInterface::ACCESS_DENIED_ERROR, $exception);
                     $response = $event->getKernel()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);
                     $response->setStatusCode(403);
                 }
             } catch (\Exception $e) {
                 if (null !== $this->logger) {
                     $this->logger->err(sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()));
                 }
                 $event->setException(new \RuntimeException('Exception thrown when handling an exception.', 0, $e));
                 return;
             }
         }
     } else {
         return;
     }
     $event->setResponse($response);
 }
开发者ID:renegare,项目名称:symfony,代码行数:63,代码来源:ExceptionListener.php

示例11: onKernelException

 /**
  * Maps known exceptions to HTTP exceptions.
  *
  * @param GetResponseForExceptionEvent $event The event object
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $class = $this->getTargetClass($exception);
     if (null === $class) {
         return;
     }
     if (null !== ($httpException = $this->convertToHttpException($exception, $class))) {
         $event->setException($httpException);
     }
 }
开发者ID:bytehead,项目名称:core-bundle,代码行数:16,代码来源:ExceptionConverterListener.php

示例12: onKernelException

 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if ($exception instanceof HttpException) {
         return;
     }
     $exception = $this->decorateException($exception);
     if ($exception) {
         $event->setException($exception);
     }
 }
开发者ID:shopery,项目名称:error-bundle,代码行数:14,代码来源:ExceptionListener.php

示例13: onKernelException

 /**
  * Maps known exceptions to HTTP exceptions.
  *
  * @param GetResponseForExceptionEvent $event The event object
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $class = get_class($exception);
     if (!isset($this->mapper[$class])) {
         return;
     }
     if (null !== ($httpException = $this->convertToHttpException($exception, $this->mapper[$class]))) {
         $event->setException($httpException);
     }
 }
开发者ID:Mozan,项目名称:core-bundle,代码行数:16,代码来源:ExceptionConverterListener.php

示例14: onKernelException

 /**
  * If exception type is 404, display the Orchestra 404 node instead of Symfony exception
  * 
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ($event->getException() instanceof DisplayBlockException) {
         $event->getRequest()->setRequestFormat('fragment.' . $event->getRequest()->getRequestFormat());
         $event->setException($event->getException()->getPrevious());
     } elseif ($event->getException() instanceof HttpExceptionInterface && '404' == $event->getException()->getStatusCode()) {
         $this->setCurrentSiteInfo(trim($this->request->getHost(), '/'), trim($this->request->getPathInfo(), '/'));
         if ($html = $this->getCustom404Html()) {
             $event->setResponse(new Response($html, 404));
         }
     }
 }
开发者ID:open-orchestra,项目名称:open-orchestra-front-bundle,代码行数:17,代码来源:KernelExceptionSubscriber.php

示例15: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if ($exception instanceof HttpExceptionInterface) {
         return;
     }
     $convertedExceptionClass = $this->findConvertToExceptionClass($exception);
     if (!$convertedExceptionClass) {
         return;
     }
     $this->logException($exception);
     $convertedException = $this->convertException($exception, $convertedExceptionClass);
     $event->setException($convertedException);
 }
开发者ID:wakermahmud,项目名称:QafooLabsNoFrameworkBundle,代码行数:14,代码来源:ConvertExceptionListener.php


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