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


PHP GetResponseForExceptionEvent::isMasterRequest方法代码示例

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


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

示例1: onKernelException

 /**
  * Map an exception to an error screen.
  *
  * @param GetResponseForExceptionEvent $event The event object
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->isMasterRequest() || 'html' !== $event->getRequest()->getRequestFormat()) {
         return;
     }
     $this->handleException($event);
 }
开发者ID:bytehead,项目名称:core-bundle,代码行数:12,代码来源:PrettyErrorScreenListener.php

示例2: onKernelException

 /**
  * Handles the onKernelException event.
  *
  * @param GetResponseForExceptionEvent $event A GetResponseForExceptionEvent instance
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ($this->onlyMasterRequests && !$event->isMasterRequest()) {
         return;
     }
     $this->exception = $event->getException();
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:12,代码来源:ProfilerListener.php

示例3: onException

 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onException(GetResponseForExceptionEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $this->eventDispatcher->dispatch(Events::REQUEST_ENDS, new RequestEnded($event->getRequest(), $event->getResponse(), $event->getException()));
 }
开发者ID:Tolerance,项目名称:Tolerance,代码行数:10,代码来源:DispatchRequestEndedEvent.php

示例4: onKernelException

 /**
  * Log de l'erreur dans MongoDB
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     // don't do anything if it's not the master request
     if (!$event->isMasterRequest()) {
         return;
     }
     // Create logs
     try {
         $log = new ErrorLog();
         $exception = $event->getException();
         $request = $event->getRequest();
         // Current User
         if ($this->securityContext->getToken() && $this->securityContext->isGranted('ROLE_USER')) {
             $log->setUsername($this->securityContext->getToken()->getUser()->getUsername());
             $log->setUserid($this->securityContext->getToken()->getUser()->getId());
         } else {
             $log->setUsername(null);
         }
         // Get error code
         if (method_exists($exception, 'getStatusCode')) {
             $log->setCode($exception->getStatusCode());
         } else {
             $log->setCode($exception->getCode());
         }
         $log->setMessage($exception->getMessage());
         $log->setUrl($request->getUri());
         $log->setIp($request->getClientIp());
         $log->setReferer($request->headers->get('referer'));
         if (in_array($log->getCode(), array('0', '404', '500'))) {
             $this->em->persist($log);
             $this->em->flush();
         }
     } catch (\Exception $e) {
     }
 }
开发者ID:vtedesco,项目名称:Peary,代码行数:38,代码来源:ExceptionListener.php

示例5: onKernelException

 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $request = $event->getRequest();
     $exception = $event->getException();
     if ($exception instanceof HttpException) {
         $status = $exception->getStatusCode();
         $headers = $exception->getHeaders();
     } elseif ($exception instanceof DeserializationException) {
         $status = Response::HTTP_BAD_REQUEST;
         $headers = [];
     } else {
         $code = method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : $exception->getCode();
         $status = isset(Response::$statusTexts[$code]) ? $code : Response::HTTP_BAD_REQUEST;
         $headers = [];
     }
     // Normalize exceptions with hydra errors only for resources
     if ($request->attributes->has('_resource')) {
         $dataResponse = $this->serializer->serialize($exception, $this->format);
         $response = new Response($dataResponse, $status, $headers);
         if ($this->format === 'xml') {
             $response = new XmlResponse($dataResponse, $status, $headers);
         }
         $event->setResponse($response);
     }
 }
开发者ID:eliberty,项目名称:api-bundle,代码行数:31,代码来源:RequestExceptionListener.php

示例6: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $this->logger->notice(sprintf('Exceptions catcher listener: catch kernel.exception event (exception: %s)', $event->getException()->getMessage()));
     // If this is not a master request, skip handling
     if (!$event->isMasterRequest()) {
         $this->logger->debug('Exceptions catcher listener: this is not master request, skip');
         return;
     }
     // If content already prepared
     if ($event->hasResponse()) {
         $this->logger->debug('Exceptions catcher listener: event already has response, skip');
         return;
     }
     // Getting action
     $apiServerAction = $event->getRequest()->attributes->get('apiAction');
     /* @var $apiServerAction ApiServerAction */
     // Something wrong
     if (!$apiServerAction) {
         $this->logger->error('Request parser listener: request has no apiAction attribute, sending empty response');
         $event->setResponse(new JsonResponse([]));
         return;
     }
     // Getting api server interface
     $apiServerInterface = $apiServerAction->getApiServerInterface();
     // Creating api response
     $apiResponse = $apiServerInterface->getExceptionResponse($event->getException()->getMessage());
     // Setting response
     $event->setResponse(new JsonResponse($apiResponse->export()));
 }
开发者ID:leoza,项目名称:api-server-bundle,代码行数:29,代码来源:ExceptionsCatcher.php

示例7: onKernelException

 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $request = $event->getRequest();
     if (!$request->attributes->has('_resource_type') || self::FORMAT !== $request->attributes->get('_api_format')) {
         return;
     }
     $exception = $event->getException();
     $headers = [];
     if ($exception instanceof HttpException) {
         $status = $exception->getStatusCode();
         $headers = $exception->getHeaders();
         $data = $exception;
     } elseif ($exception instanceof ValidationException) {
         $status = Response::HTTP_BAD_REQUEST;
         $data = $exception->getConstraintViolationList();
     } elseif ($exception instanceof ExceptionInterface || $exception instanceof InvalidArgumentException) {
         $status = Response::HTTP_BAD_REQUEST;
         $data = $exception;
     } else {
         $status = Response::HTTP_INTERNAL_SERVER_ERROR;
         $data = $exception;
     }
     $event->setResponse(new Response($this->normalizer->normalize($data, 'hydra-error'), $status, $headers));
 }
开发者ID:rolebi,项目名称:DunglasApiBundle,代码行数:30,代码来源:RequestExceptionListener.php

示例8: onException

 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onException(GetResponseForExceptionEvent $event)
 {
     if (!$event->getException() instanceof NotFoundHttpException) {
         return;
     }
     if (!$event->isMasterRequest()) {
         return;
     }
     if (!($redirect = $this->getRedirectForRequest($event->getRequest()))) {
         return;
     }
     $event->setResponse($redirect);
 }
开发者ID:Vesax,项目名称:seo-bundle,代码行数:16,代码来源:RedirectListener.php

示例9: onKernelException

 /**
  * Kernel exception listener callback.
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $app = $this->app;
     if (!$app->isTestMode()) {
         if ($app['orm.em']->getConnection()->isTransactionActive()) {
             $app['orm.em']->rollback();
         }
     } else {
         $this->app->log('TestCase to onKernelException of rollback');
     }
 }
开发者ID:ec-cube,项目名称:ec-cube,代码行数:19,代码来源:TransactionListener.php

示例10: onKernelException

 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $request = $event->getRequest();
     $exception = $event->getException();
     if ($exception instanceof HttpException) {
         $status = $exception->getStatusCode();
         $headers = $exception->getHeaders();
     } elseif ($exception instanceof DeserializationException) {
         $status = Response::HTTP_BAD_REQUEST;
         $headers = [];
     } else {
         $status = Response::HTTP_INTERNAL_SERVER_ERROR;
         $headers = [];
     }
     // Normalize exceptions with hydra errors only for resources
     if ($request->attributes->has('_resource')) {
         $event->setResponse(new Response($this->normalizer->normalize($exception, 'hydra-error'), $status, $headers));
     }
 }
开发者ID:reminec,项目名称:DunglasApiBundle,代码行数:25,代码来源:RequestExceptionListener.php

示例11: onKernelException

 /**
  *
  * @author Krzysztof Bednarczyk
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $exception = $event->getException();
     $isXVRequest = (int) $event->getRequest()->headers->get('X-XV-Request', 0);
     if ($exception instanceof AccessDeniedHttpException || $exception instanceof AccessDeniedHttpException || $exception instanceof AuthenticationException) {
         $path = parse_url($event->getRequest()->getRequestUri(), PHP_URL_PATH);
         $event->setResponse(new RedirectResponse("/login/?r={$path}"));
         $event->stopPropagation();
         return;
     }
     if ($exception instanceof NotFoundHttpException) {
         $event->setResponse(new RedirectResponse("/page/404/" . ($isXVRequest ? "?dialog=true" : "")));
         $event->stopPropagation();
         return;
     }
     if ($exception instanceof CsrfHttpException) {
         $event->setResponse(new RedirectResponse("/page/csrf/"));
         $event->stopPropagation();
         return;
     }
 }
开发者ID:xvengine,项目名称:symfony-bridge,代码行数:29,代码来源:KernelListener.php


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