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


PHP Event\GetResponseForExceptionEvent类代码示例

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


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

示例1: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     // only reply to /api URLs
     if (strpos($event->getRequest()->getPathInfo(), '/api') !== 0) {
         return;
     }
     $e = $event->getException();
     $statusCode = $e instanceof HttpExceptionInterface ? $e->getStatusCode() : 500;
     // allow 500 errors to be thrown
     if ($this->debug && $statusCode >= 500) {
         return;
     }
     if ($e instanceof ApiProblemException) {
         $apiProblem = $e->getApiProblem();
     } else {
         $apiProblem = new ApiProblem($statusCode);
         /*
          * If it's an HttpException message (e.g. for 404, 403),
          * we'll say as a rule that the exception message is safe
          * for the client. Otherwise, it could be some sensitive
          * low-level exception, which should *not* be exposed
          */
         if ($e instanceof HttpExceptionInterface) {
             $apiProblem->set('detail', $e->getMessage());
         }
     }
     $response = $this->responseFactory->createResponse($apiProblem);
     $event->setResponse($response);
 }
开发者ID:juuuuuu,项目名称:budget,代码行数:29,代码来源:ApiExceptionSubscriber.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

 /**
  * Catches a form AJAX exception and build a response from it.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
  *   The event to process.
  */
 public function onException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $request = $event->getRequest();
     // Render a nice error message in case we have a file upload which exceeds
     // the configured upload limit.
     if ($exception instanceof BrokenPostRequestException && $request->query->has(FormBuilderInterface::AJAX_FORM_REQUEST)) {
         $this->drupalSetMessage($this->t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', ['@size' => $this->formatSize($exception->getSize())]), 'error');
         $response = new AjaxResponse();
         $status_messages = ['#type' => 'status_messages'];
         $response->addCommand(new ReplaceCommand(NULL, $status_messages));
         $response->headers->set('X-Status-Code', 200);
         $event->setResponse($response);
         return;
     }
     // Extract the form AJAX exception (it may have been passed to another
     // exception before reaching here).
     if ($exception = $this->getFormAjaxException($exception)) {
         $request = $event->getRequest();
         $form = $exception->getForm();
         $form_state = $exception->getFormState();
         // Set the build ID from the request as the old build ID on the form.
         $form['#build_id_old'] = $request->get('form_build_id');
         try {
             $response = $this->formAjaxResponseBuilder->buildResponse($request, $form, $form_state, []);
             // Since this response is being set in place of an exception, explicitly
             // mark this as a 200 status.
             $response->headers->set('X-Status-Code', 200);
             $event->setResponse($response);
         } catch (\Exception $e) {
             // Otherwise, replace the existing exception with the new one.
             $event->setException($e);
         }
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:41,代码来源:FormAjaxSubscriber.php

示例4: 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

示例5: onKernelException

 /**
  * Replaces the response in case an EnforcedResponseException was thrown.
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ($response = EnforcedResponse::createFromException($event->getException())) {
         // Setting the response stops the event propagation.
         $event->setResponse($response);
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:10,代码来源:EnforcedFormResponseSubscriber.php

示例6: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $e = $event->getException();
     $statusCode = $e instanceof HttpExceptionInterface ? $e->getStatusCode() : 500;
     // allow 500 errors to be thrown
     if ($this->debug && $statusCode >= 500) {
         return;
     }
     if ($e instanceof ApiProblemException) {
         $apiProblem = $e->getApiProblem();
     } else {
         $apiProblem = new ApiProblem($statusCode);
         /*
          * If it's an HttpException message (e.g. for 404, 403),
          * we'll say as a rule that the exception message is safe
          * for the client. Otherwise, it could be some sensitive
          * low-level exception, which should *not* be exposed
          */
         if ($e instanceof HttpExceptionInterface) {
             $apiProblem->set('detail', $e->getMessage());
         }
     }
     $data = $apiProblem->toArray();
     $response = new JsonResponse($data, $apiProblem->getStatusCode());
     $response->headers->set('Content-Type', 'application/json');
     $event->setResponse($response);
 }
开发者ID:bitecodes,项目名称:rest-api-generator-bundle,代码行数:27,代码来源:ApiExceptionSubscriber.php

示例7: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $flattenException = FlattenException::create($exception);
     $msg = 'Something went wrong! (' . $flattenException->getMessage() . ')';
     $event->setResponse(new Response($msg, $flattenException->getStatusCode()));
 }
开发者ID:voxsim,项目名称:minima,代码行数:7,代码来源:ExceptionListener.php

示例8: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $whoops = $this->handler->handle($event->getRequest(), $exception->getCode());
     $whoopsResponse = $whoops->handleException($exception);
     $event->setResponse(new Response($whoopsResponse));
 }
开发者ID:slayful,项目名称:WhoopsBundle,代码行数:7,代码来源:Listener.php

示例9: 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

示例10: 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

示例11: onKernelException

 /**
  * @param GetResponseForExceptionEvent $event
  *
  * @return RedirectResponse|null
  *
  * @throws \LogicException If the current page is inside the page range
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if (!$exception instanceof OutOfBoundsException) {
         return;
     }
     $pageNumber = $exception->getPageNumber();
     $pageCount = $exception->getPageCount();
     if ($pageCount < 1) {
         return;
         // No pages...so let the exception fall through.
     }
     $queryBag = clone $event->getRequest()->query;
     if ($pageNumber > $pageCount) {
         $queryBag->set($exception->getRedirectKey(), $pageCount);
     } elseif ($pageNumber < 1) {
         $queryBag->set($exception->getRedirectKey(), 1);
     } else {
         return;
         // Super weird, because current page is within the bounds, fall through.
     }
     if (null !== ($qs = http_build_query($queryBag->all(), '', '&'))) {
         $qs = '?' . $qs;
     }
     // Create identical uri except for the page key in the query string which
     // was changed by this listener.
     //
     // @see Symfony\Component\HttpFoundation\Request::getUri()
     $request = $event->getRequest();
     $uri = $request->getSchemeAndHttpHost() . $request->getBaseUrl() . $request->getPathInfo() . $qs;
     $event->setResponse(new RedirectResponse($uri));
 }
开发者ID:kgilden,项目名称:pager,代码行数:39,代码来源:OutOfBoundsRedirector.php

示例12: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     static $handling;
     if (true === $handling) {
         return false;
     }
     $handling = true;
     $exception = $event->getException();
     $request = $event->getRequest();
     $this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
     $attributes = array('_controller' => $this->controller, 'exception' => FlattenException::create($exception), 'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null, 'format' => $request->getRequestFormat());
     $request = $request->duplicate(null, null, $attributes);
     $request->setMethod('GET');
     try {
         $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
     } catch (\Exception $e) {
         $this->logException($exception, sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()), false);
         // set handling to false otherwise it wont be able to handle further more
         $handling = false;
         // re-throw the exception from within HttpKernel as this is a catch-all
         return;
     }
     $event->setResponse($response);
     $handling = false;
 }
开发者ID:llinder,项目名称:FrameworkBenchmarks,代码行数:25,代码来源:ExceptionListener.php

示例13: 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

示例14: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ($event->getException() instanceof NotFoundHttpException) {
         $response = new RedirectResponse('karkeu');
         $event->setResponse($response);
     }
 }
开发者ID:potogan,项目名称:mobile-wine,代码行数:7,代码来源:ExceptionListener.php

示例15: onKernelException

 /**
  * Event handler that renders custom pages in case of a NotFoundHttpException (404)
  * or a AccessDeniedHttpException (403).
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ('dev' == $this->kernel->getEnvironment()) {
         return;
     }
     $exception = $event->getException();
     $this->request->setLocale($this->defaultLocale);
     $this->request->setDefaultLocale($this->defaultLocale);
     if ($exception instanceof NotFoundHttpException) {
         $section = $this->getExceptionSection(404, '404 Error');
         $this->core->addNavigationElement($section);
         $unifikRequest = $this->generateUnifikRequest($section);
         $this->setUnifikRequestAttributes($unifikRequest);
         $this->request->setLocale($this->request->attributes->get('_locale', $this->defaultLocale));
         $this->request->setDefaultLocale($this->request->attributes->get('_locale', $this->defaultLocale));
         $this->entityManager->getRepository('UnifikSystemBundle:Section')->setLocale($this->request->attributes->get('_locale'));
         $response = $this->templating->renderResponse('UnifikSystemBundle:Frontend/Exception:404.html.twig', array('section' => $section));
         $response->setStatusCode(404);
         $event->setResponse($response);
     } elseif ($exception instanceof AccessDeniedHttpException) {
         $section = $this->getExceptionSection(403, '403 Error');
         $this->core->addNavigationElement($section);
         $unifikRequest = $this->generateUnifikRequest($section);
         $this->setUnifikRequestAttributes($unifikRequest);
         $response = $this->templating->renderResponse('UnifikSystemBundle:Frontend/Exception:403.html.twig', array('section' => $section));
         $response->setStatusCode(403);
         $event->setResponse($response);
     }
 }
开发者ID:pmdc,项目名称:UnifikSystemBundle,代码行数:35,代码来源:ExceptionListener.php


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