當前位置: 首頁>>代碼示例>>PHP>>正文


PHP GetResponseForExceptionEvent::getException方法代碼示例

本文整理匯總了PHP中Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent::getException方法的典型用法代碼示例。如果您正苦於以下問題:PHP GetResponseForExceptionEvent::getException方法的具體用法?PHP GetResponseForExceptionEvent::getException怎麽用?PHP GetResponseForExceptionEvent::getException使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent的用法示例。


在下文中一共展示了GetResponseForExceptionEvent::getException方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

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

示例2: onKernelException

 /**
  * Register the event handler
  *
  * @param GetResponseForExceptionEvent $event
  *
  * @api
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!in_array(get_class($event->getException()), $this->checkExceptions)) {
         return;
     }
     $exceptionMessage = $event->getException()->getMessage();
     $prefixLength = mb_strlen($this->errorPrefix);
     // PDO Exception likes to place SQLState before the message
     // And do some other stuff...
     // HT000 is used for MySQL, but there is no support for 'custom errors' yet
     if ($event->getException() instanceof \PDOException) {
         if (!in_array($event->getException()->getCode(), array('P0001'))) {
             return;
         }
         // PostgreSQL
         if ('P0001' === $event->getException()->getCode() && preg_match('#^SQLSTATE\\[P0001\\]: Raise exception: \\d+ ERROR:  (.+)#', $exceptionMessage, $messageMatch)) {
             $exceptionMessage = $messageMatch[1];
         } else {
             return;
         }
         // @codeCoverageIgnoreEnd
     }
     if (mb_substr($exceptionMessage, 0, $prefixLength) === $this->errorPrefix) {
         $exceptionMessage = mb_substr($exceptionMessage, $prefixLength);
         $messageMatch = $this->parseMessage($exceptionMessage);
         $event->setException(new \Exception($this->translator->trans($messageMatch['message'], $messageMatch['params']), 0, $event->getException()));
     }
 }
開發者ID:rollerworks,項目名稱:RollerworksDBBundle,代碼行數:35,代碼來源:UserErrorExceptionListener.php

示例3: onSilexError

 public function onSilexError(GetResponseForExceptionEvent $event)
 {
     if (!$event->getException() instanceof \Bridge_Exception) {
         return;
     }
     $e = $event->getException();
     $request = $event->getRequest();
     $params = ['account' => null, 'elements' => [], 'message' => $e->getMessage(), 'error_message' => null, 'notice_message' => null, 'file' => $e->getFile(), 'line' => $e->getLine(), 'r_method' => $request->getMethod(), 'r_action' => $request->getRequestUri(), 'r_parameters' => $request->getMethod() == 'GET' ? [] : $request->request->all()];
     if ($e instanceof \Bridge_Exception_ApiConnectorNotConfigured) {
         $params = array_replace($params, ['account' => $this->app['bridge.account']]);
         $response = new Response($this->app['twig']->render('/prod/actions/Bridge/notconfigured.html.twig', $params), 200, ['X-Status-Code' => 200]);
     } elseif ($e instanceof \Bridge_Exception_ApiConnectorNotConnected) {
         $params = array_replace($params, ['account' => $this->app['bridge.account']]);
         $response = new Response($this->app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200, ['X-Status-Code' => 200]);
     } elseif ($e instanceof \Bridge_Exception_ApiConnectorAccessTokenFailed) {
         $params = array_replace($params, ['account' => $this->app['bridge.account']]);
         $response = new Response($this->app['twig']->render('/prod/actions/Bridge/disconnected.html.twig', $params), 200, ['X-Status-Code' => 200]);
     } elseif ($e instanceof \Bridge_Exception_ApiDisabled) {
         $params = array_replace($params, ['api' => $e->get_api()]);
         $response = new Response($this->app['twig']->render('/prod/actions/Bridge/deactivated.html.twig', $params), 200, ['X-Status-Code' => 200]);
     } else {
         $response = new Response($this->app['twig']->render('/prod/actions/Bridge/error.html.twig', $params), 200, ['X-Status-Code' => 200]);
     }
     $response->headers->set('Phrasea-StatusCode', 200);
     $event->setResponse($response);
 }
開發者ID:nlegoff,項目名稱:Phraseanet,代碼行數:26,代碼來源:BridgeExceptionSubscriber.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: 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);
     }
 }
開發者ID:belackriv,項目名稱:step-inventory,代碼行數:26,代碼來源:ExceptionEventListener.php

示例6: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $response = new JsonResponse(['errorMessage' => $event->getException()->getMessage(), 'stackTrace' => $event->getException()->getTraceAsString()]);
     if ($exception instanceof HttpExceptionInterface) {
         $response->setStatusCode($exception->getStatusCode());
     } else {
         if ($exception instanceof AuthenticationException) {
             $response->setData(['errorMessage' => 'You don\'t have permissions to do this.']);
             $response->setStatusCode(Response::HTTP_FORBIDDEN);
         } else {
             if ($exception instanceof InvalidFormException) {
                 $errors = [];
                 foreach ($exception->getForm()->getErrors(true) as $error) {
                     if ($error->getOrigin()) {
                         $errors[$error->getOrigin()->getName()][] = $error->getMessage();
                     }
                 }
                 $data = ['errors' => $errors, 'errorMessage' => ''];
                 $response->setData($data);
                 $response->setStatusCode(Response::HTTP_BAD_REQUEST);
             } else {
                 $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
             }
         }
     }
     $event->setResponse($response);
 }
開發者ID:Gardax,項目名稱:cookWithMeAPI,代碼行數:28,代碼來源:ExceptionListener.php

示例7: onKernelException

 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     // Skip HTTP exception
     if ($event->getException() instanceof HttpException) {
         return;
     }
     $this->setException($event->getException());
 }
開發者ID:emgiezet,項目名稱:FtrrtfRollbarBundle,代碼行數:11,代碼來源:RollbarListener.php

示例8: it_converts_numbers_to_http_status_code_exception

 /**
  * @test
  */
 public function it_converts_numbers_to_http_status_code_exception()
 {
     $logger = \Phake::mock('Psr\\Log\\LoggerInterface');
     $listener = new ConvertExceptionListener($logger, array('OutOfBoundsException' => 405));
     $listener->onKernelException($event = new GetResponseForExceptionEvent(\Phake::mock('Symfony\\Component\\HttpKernel\\KernelInterface'), \Phake::mock('Symfony\\Component\\HttpFoundation\\Request'), 0, $original = new OutOfBoundsException()));
     $this->assertInstanceOf('Symfony\\Component\\HttpKernel\\Exception\\HttpException', $event->getException());
     $this->assertEquals(405, $event->getException()->getStatusCode());
     $this->assertSame($original, $event->getException()->getPrevious());
 }
開發者ID:wakermahmud,項目名稱:QafooLabsNoFrameworkBundle,代碼行數:12,代碼來源:ConvertExceptionListenerTest.php

示例9: onKernelException

 /**
  * onKernelException
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if ($exception instanceof HttpExceptionInterface) {
         $code = $event->getException()->getStatusCode();
     } else {
         $code = 'unknown';
     }
     $this->eventDispatcher->dispatch('statsd.exception', new StatsdEvent($code));
 }
開發者ID:johndodev,項目名稱:StatsdBundle,代碼行數:15,代碼來源:Listener.php

示例10: onKernelException

 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ($this->kernel->getEnvironment() != 'dev') {
         $exception = $event->getException();
         if (!$exception instanceof HttpException) {
             $this->logger->error($exception->getMessage());
         }
         $event->setResponse(new RedirectResponse($this->router->generate('music_error', ['code' => $event->getException() instanceof HttpException ? $exception->getStatusCode() : 500])));
     }
 }
開發者ID:jackpf,項目名稱:BuffaloSessions,代碼行數:10,代碼來源:KernelListener.php

示例11: onKernelException

 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (false == $event->getException() instanceof ReplyInterface) {
         return;
     }
     $response = $this->replyToSymfonyResponseConverter->convert($event->getException());
     if (false == $response->headers->has('X-Status-Code')) {
         $response->headers->set('X-Status-Code', $response->getStatusCode());
     }
     $event->setResponse($response);
 }
開發者ID:MHaendel,項目名稱:PayumBundle,代碼行數:14,代碼來源:ReplyToHttpResponseListener.php

示例12: onKernelException

 /**
  * Exception error handler
  *
  * @param GetResponseForExceptionEvent $event
  *
  * @return void
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if ($this->isIgnored($event->getException())) {
         return;
     }
     if ($this->mailer) {
         $this->mailer->sendException($event->getRequest(), $event->getException());
     }
     if ($this->statsd) {
         $this->statsd->increment("exception");
     }
 }
開發者ID:mhor,項目名稱:SoclozMonitoringBundle,代碼行數:19,代碼來源:Exceptions.php

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

示例14: onSilexError

 /**
  * {@inheritdoc}
  */
 public function onSilexError(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $code = $exception->getCode();
     if (is_numeric($code)) {
         $code = max(1, intval($code));
     } else {
         $code = 1;
     }
     $this->app['console.status'] = $code;
     $this->app['console']->renderException($event->getException(), $this->app['console.output']);
     $event->setResponse(new Response());
 }
開發者ID:rmlasseter,項目名稱:silex-cli,代碼行數:16,代碼來源:ConsoleExceptionHandler.php

示例15: onSilexError

 public function onSilexError(GetResponseForExceptionEvent $event)
 {
     $handler = new DebugExceptionHandler($this->debug);
     if (method_exists($handler, 'getHtml')) {
         $exception = $event->getException();
         if (!$exception instanceof FlattenException) {
             $exception = FlattenException::create($exception);
         }
         $response = Response::create($handler->getHtml($exception), $exception->getStatusCode(), $exception->getHeaders())->setCharset(ini_get('default_charset'));
     } else {
         // BC with Symfony < 2.8
         $response = $handler->createResponse($event->getException());
     }
     $event->setResponse($response);
 }
開發者ID:cordje,項目名稱:Silex,代碼行數:15,代碼來源:ExceptionHandler.php


注:本文中的Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent::getException方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。