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


PHP GetResponseForExceptionEvent::stopPropagation方法代码示例

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


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

示例1: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ($event->getException() instanceof AccessDeniedException) {
         $event->setResponse(new JsonResponse(['error' => 'access_denied']));
         $event->stopPropagation();
     }
 }
开发者ID:lukaszmakuch,项目名称:question-sheet-storage,代码行数:7,代码来源:AccessDeniedJSONListener.php

示例2: onKernelException

 /**
  * Intercept Exceptions and send valid ajax errors
  * The idea is to NOT send HTML response when an issue(i.e.session expired) is encountered
  * in an ajax request.
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     // Get the exception object from the received event
     $exception = $event->getException();
     $request = $event->getRequest();
     $isAjaxRequest = $request->isXmlHttpRequest();
     if ($isAjaxRequest) {
         $headers = [];
         // handle session expired
         if ($exception instanceof AuthenticationException) {
             $loginUrl = $this->router->generate('fos_user_security_login');
             // add custom header to redirect to login page on the client
             $headers['relogin'] = true;
             $headers['login-url'] = $loginUrl;
             $response = new Response('Authentication Required', 200, $headers);
         } elseif ($exception instanceof AccessDeniedException) {
             $headers['not-authorized'] = true;
             $response = new Response('Not authorized', 403, $headers);
         } else {
             $responseData = ['status' => false, 'msg' => 'Unknown Issue Encountered', 'data' => ['exception' => ['message' => $exception->getMessage(), 'file' => "{$exception->getFile()}:{$exception->getLine()}", 'trace' => $exception->getTraceAsString()]]];
             $response = new Response(json_encode($responseData), 500, $headers);
         }
         $event->setResponse($response);
         $event->stopPropagation();
     }
 }
开发者ID:atompulse,项目名称:ran-bundle,代码行数:32,代码来源:AjaxExceptionListener.php

示例3: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ($event->getException() instanceof EntityNotFoundException) {
         $response = new Response('Entity not found', Response::HTTP_NOT_FOUND);
         $event->setResponse($response);
         $event->stopPropagation();
     }
 }
开发者ID:staspiv,项目名称:rest-bundle,代码行数:8,代码来源:HttpKernelExceptionListener.php

示例4: onKernelExceptionView

 /**
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
  *
  * @throws \Exception
  */
 public function onKernelExceptionView(GetResponseForExceptionEvent $event)
 {
     if (!$event->getRequest()->attributes->get('is_rest_request')) {
         return;
     }
     $event->setResponse($this->viewDispatcher->dispatch($event->getRequest(), $event->getException()));
     $event->stopPropagation();
 }
开发者ID:Heyfara,项目名称:ezpublish-kernel,代码行数:13,代码来源:ResponseListener.php

示例5: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $responseForExceptionEvent)
 {
     $request = $responseForExceptionEvent->getRequest();
     if ($responseForExceptionEvent->getException() instanceof MethodNotAllowedHttpException && 'OPTIONS' === $request->getMethod()) {
         $response = new JsonResponse(null, Response::HTTP_OK);
         $responseForExceptionEvent->setResponse($response);
         $responseForExceptionEvent->stopPropagation();
     }
 }
开发者ID:aixiandfriends,项目名称:postit-board-api,代码行数:9,代码来源:RequestEventListener.php

示例6: onBootException

 /**
  * Handle boot initialisation exceptions.
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onBootException(GetResponseForExceptionEvent $event)
 {
     if ($this->isProfilerRequest($event->getRequest())) {
         return;
     }
     $exception = $event->getException();
     if ($exception instanceof BootException) {
         $event->setResponse($exception->getResponse());
         $event->stopPropagation();
     }
 }
开发者ID:nbehier,项目名称:bolt,代码行数:16,代码来源:ExceptionListener.php

示例7: onKernelException

 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!($exception = $event->getException()) instanceof ApiException) {
         return;
     }
     $request = $event->getRequest();
     $attributes = array('_controller' => $this->controller, 'exception' => $exception, 'format' => $request->getRequestFormat('json'));
     $request = $request->duplicate(null, null, $attributes);
     $request->setMethod('GET');
     $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
     $event->setResponse($response);
     $event->stopPropagation();
 }
开发者ID:open-orchestra,项目名称:open-orchestra-base-api-bundle,代码行数:16,代码来源:HttpExceptionSubscriber.php

示例8: getValidationFailedExceptionResponse

 /**
  * Get correct response for validation failed exception
  *
  * @param GetResponseForExceptionEvent $event           event
  * @param EventDispatcherInterface     $eventDispatcher eventDispatcher
  * @param ValidationFailedException    $exception       exception
  *
  * @return Response|null
  */
 private function getValidationFailedExceptionResponse(GetResponseForExceptionEvent $event, EventDispatcherInterface $eventDispatcher, ValidationFailedException $exception)
 {
     $event->stopPropagation();
     $request = $event->getRequest();
     $transaction = $request->get('transaction');
     if (!$transaction) {
         return $event->getResponse();
     }
     $data = $request->get($request->get(Alias::DATA));
     $violations = $exception->getConstraintViolationList();
     $request->attributes->set('violations', $violations);
     $view = View::create($data);
     $responseEvent = new GetResponseForControllerResultEvent($event->getKernel(), $request, $request->getMethod(), $view);
     if ($view->getData() instanceof ArrayCollection) {
         $responseEvent->getRequest()->attributes->set(EmbeddedManager::KEY_EMBED, EmbeddedManager::GROUP_VIOLATION_COLLECTION);
     } else {
         $responseEvent->getRequest()->attributes->set(EmbeddedManager::KEY_EMBED, EmbeddedManager::GROUP_VIOLATION_ENTITY);
     }
     $eventDispatcher->dispatch('kernel.view', $responseEvent);
     return $responseEvent->getResponse();
 }
开发者ID:RomanShumkov,项目名称:EcentriaRestBundle,代码行数:30,代码来源:ExceptionListener.php

示例9: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     /** @var OrchestratorException $exception */
     $exception = $event->getException();
     $exceptionId = KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME . '-' . md5(microtime());
     if (!$exception instanceof OrchestratorException) {
         return;
     }
     $event->stopPropagation();
     $data = array();
     $data["status"] = $exception->getType();
     $data["message"] = $exception->getMessage();
     // getMessage
     $data["code"] = $exception->getExceptionCode();
     // getExceptionCode
     $response = new JsonResponse($data);
     $response->headers->set('Access-Control-Allow-Origin', '*');
     $response->headers->set('Content-Type', 'application/json');
     $response->setStatusCode($exception->getStatusCode() ? $exception->getStatusCode() : 400);
     $this->logger->debug($exception->getMessage(), array('exception' => $exception, 'exceptionId' => $exceptionId));
     $event->setResponse($response);
 }
开发者ID:keboola,项目名称:orchestrator-bundle,代码行数:22,代码来源:ExceptionListener.php

示例10: getValidationFailedExceptionResponse

 /**
  * Get correct response for validation failed exception
  *
  * @param GetResponseForExceptionEvent $event           event
  * @param EventDispatcherInterface     $eventDispatcher eventDispatcher
  * @param ValidationFailedException    $exception       exception
  *
  * @return Response|null
  */
 private function getValidationFailedExceptionResponse(GetResponseForExceptionEvent $event, EventDispatcherInterface $eventDispatcher, ValidationFailedException $exception)
 {
     $event->stopPropagation();
     $request = $event->getRequest();
     $transaction = $request->get('transaction');
     if (!$transaction) {
         return $event->getResponse();
     }
     $data = $request->get($request->get(Alias::DATA));
     $violations = $exception->getConstraintViolationList();
     $request->attributes->set('violations', $violations);
     $view = View::create($data);
     $responseEvent = new GetResponseForControllerResultEvent($event->getKernel(), $request, $request->getMethod(), $view);
     $eventDispatcher->dispatch('kernel.view', $responseEvent);
     $responseData = $view->getData();
     if ($responseData instanceof EmbeddedInterface) {
         $responseData->setShowAssociations(true);
     }
     if ($responseData instanceof CollectionResponse) {
         $responseData->setInheritedShowAssociations(false);
     }
     return $responseEvent->getResponse();
 }
开发者ID:RuslanZavacky,项目名称:EcentriaRestBundle,代码行数:32,代码来源:ExceptionListener.php

示例11: onKernelExceptionView

 /**
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
  *
  * @throws \Exception
  *
  * @return void
  */
 public function onKernelExceptionView(GetResponseForExceptionEvent $event)
 {
     if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
         return;
     }
     if (!$this->isRestRequest($event->getRequest())) {
         return;
     }
     $result = $event->getException();
     $event->setResponse($this->visitResult($result));
     $event->stopPropagation();
 }
开发者ID:brookinsconsulting,项目名称:ezecosystem,代码行数:19,代码来源:RestListener.php

示例12: onKernelException

 /**
  * Handles a kernel exception.
  *
  * @param GetResponseForExceptionEvent $event
  *
  * @throws \Exception
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ($event->getException() instanceof NotFoundHttpException && $this->cmsManagerSelector->isEditor()) {
         $pathInfo = $event->getRequest()->getPathInfo();
         // can only create a CMS page, so the '_route' must be null
         $creatable = !$event->getRequest()->get('_route') && $this->decoratorStrategy->isRouteUriDecorable($pathInfo);
         if ($creatable) {
             $response = new Response($this->templating->render('SonataPageBundle:Page:create.html.twig', array('pathInfo' => $pathInfo, 'site' => $this->siteSelector->retrieve(), 'creatable' => $creatable)), 404);
             $event->setResponse($response);
             $event->stopPropagation();
             return;
         }
     }
     if ($event->getException() instanceof InternalErrorException) {
         $this->handleInternalError($event);
     } else {
         $this->handleNativeError($event);
     }
 }
开发者ID:TomasVotruba,项目名称:SonataPageBundle,代码行数:26,代码来源:ExceptionListener.php

示例13: handleLegacyExceptionEvent

 /**
  * Dispatch and handle the legacy event `frontcontroller.exception`
  *
  * @deprecated removal scheduled for 2.0.0
  *
  * @param GetResponseForExceptionEvent $event
  */
 private function handleLegacyExceptionEvent(GetResponseForExceptionEvent $event)
 {
     $modinfo = \ModUtil::getInfoFromName($event->getRequest()->attributes->get('_zkModule'));
     $legacyEvent = new \Zikula\Core\Event\GenericEvent($event->getException(), array('modinfo' => $modinfo, 'type' => $event->getRequest()->attributes->get('_zkType'), 'func' => $event->getRequest()->attributes->get('_zkFunc'), 'arguments' => $event->getRequest()->attributes->all()));
     $this->dispatcher->dispatch('frontcontroller.exception', $legacyEvent);
     if ($legacyEvent->isPropagationStopped()) {
         $event->getRequest()->getSession()->getFlashBag()->add('error', __f('The \'%1$s\' module returned an error in \'%2$s\'. (%3$s)', array($event->getRequest()->attributes->get('_zkModule'), $event->getRequest()->attributes->get('_zkFunc'), $legacyEvent->getArgument('message'))), $legacyEvent->getArgument('httpcode'));
         $route = $event->getRequest()->server->get('referrer');
         $response = new RedirectResponse($route);
         $event->setResponse($response);
         $event->stopPropagation();
     }
 }
开发者ID:Silwereth,项目名称:core,代码行数:20,代码来源:ExceptionListener.php

示例14: 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::stopPropagation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。