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


PHP ConsoleExceptionEvent::stopPropagation方法代碼示例

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


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

示例1: onException

 /**
  * React to any console exceptions.
  *
  * @param ConsoleExceptionEvent    $event
  */
 public function onException(ConsoleExceptionEvent $event)
 {
     $exception = $event->getException();
     // Replace Guzzle connect exceptions with a friendlier message. This
     // also prevents the user from seeing two exceptions (one direct from
     // Guzzle, one from RingPHP).
     if ($exception instanceof ConnectException && strpos($exception->getMessage(), 'cURL error 6') !== false) {
         $request = $exception->getRequest();
         $event->setException(new ConnectionFailedException("Failed to connect to host: " . $request->getHost() . " \nRequest URL: " . $request->getUrl() . " \nPlease check your Internet connection"));
         $event->stopPropagation();
     }
     // Handle Guzzle client exceptions, i.e. HTTP 4xx errors.
     if ($exception instanceof ClientException && ($response = $exception->getResponse())) {
         $request = $exception->getRequest();
         try {
             $response->getBody()->seek(0);
             $json = $response->json();
         } catch (ParseException $e) {
             $json = [];
         }
         // Create a friendlier message for the OAuth2 "Invalid refresh token"
         // error.
         if ($response->getStatusCode() === 400 && isset($json['error_description']) && $json['error_description'] === 'Invalid refresh token') {
             $event->setException(new LoginRequiredException("Invalid refresh token: please log in again." . " \nRequest URL: " . $request->getUrl()));
             $event->stopPropagation();
         } elseif ($response->getStatusCode() === 401) {
             $event->setException(new LoginRequiredException("Unauthorized: please log in again." . " \nRequest URL: " . $request->getUrl()));
             $event->stopPropagation();
         }
     }
 }
開發者ID:ratajczak,項目名稱:platformsh-cli,代碼行數:36,代碼來源:EventSubscriber.php

示例2: onException

 /**
  * React to any console exceptions.
  *
  * @param ConsoleExceptionEvent    $event
  */
 public function onException(ConsoleExceptionEvent $event)
 {
     $exception = $event->getException();
     // Replace Guzzle connect exceptions with a friendlier message. This
     // also prevents the user from seeing two exceptions (one direct from
     // Guzzle, one from RingPHP).
     if ($exception instanceof ConnectException && strpos($exception->getMessage(), 'cURL error 6') !== false) {
         $request = $exception->getRequest();
         $event->setException(new ConnectionFailedException("Failed to connect to host: " . $request->getHost() . " \nPlease check your Internet connection.", $request));
         $event->stopPropagation();
     }
     // Handle Guzzle client exceptions, i.e. HTTP 4xx errors.
     if ($exception instanceof ClientException && ($response = $exception->getResponse())) {
         $request = $exception->getRequest();
         try {
             $response->getBody()->seek(0);
             $json = $response->json();
         } catch (ParseException $e) {
             $json = [];
         }
         // Create a friendlier message for the OAuth2 "Invalid refresh token"
         // error.
         if ($response->getStatusCode() === 400 && isset($json['error_description']) && $json['error_description'] === 'Invalid refresh token') {
             $event->setException(new LoginRequiredException("Invalid refresh token: please log in again.", $request));
             $event->stopPropagation();
         } elseif ($response->getStatusCode() === 401) {
             $event->setException(new LoginRequiredException("Unauthorized: please log in again.", $request));
             $event->stopPropagation();
         } elseif ($response->getStatusCode() === 403) {
             $event->setException(new PermissionDeniedException("Permission denied. Check your project or environment permissions.", $request));
             $event->stopPropagation();
         }
     }
     // When an environment is found to be in the wrong state, perhaps our
     // cache is old - we should invalidate it.
     if ($exception instanceof EnvironmentStateException) {
         $command = $event->getCommand();
         if ($command instanceof PlatformCommand) {
             $command->clearEnvironmentsCache();
         }
     }
 }
開發者ID:CompanyOnTheWorld,項目名稱:platformsh-cli,代碼行數:47,代碼來源:EventSubscriber.php

示例3: onException

 /**
  * React to any console exceptions.
  *
  * @param ConsoleExceptionEvent    $event
  */
 public function onException(ConsoleExceptionEvent $event)
 {
     $exception = $event->getException();
     // Replace Guzzle connect exceptions with a friendlier message. This
     // also prevents the user from seeing two exceptions (one direct from
     // Guzzle, one from RingPHP).
     if ($exception instanceof ConnectException && strpos($exception->getMessage(), 'cURL error 6') !== false) {
         $request = $exception->getRequest();
         $event->setException(new ConnectionFailedException("Failed to connect to host: " . $request->getHost() . " \nPlease check your Internet connection.", $request));
         $event->stopPropagation();
     }
     // Handle Guzzle exceptions, i.e. HTTP 4xx or 5xx errors.
     if (($exception instanceof ClientException || $exception instanceof ServerException) && ($response = $exception->getResponse())) {
         $request = $exception->getRequest();
         $response->getBody()->seek(0);
         $json = (array) json_decode($response->getBody()->getContents(), true);
         // Create a friendlier message for the OAuth2 "Invalid refresh token"
         // error.
         $loginCommand = sprintf('%s login', $this->config->get('application.executable'));
         if ($response->getStatusCode() === 400 && isset($json['error_description']) && $json['error_description'] === 'Invalid refresh token') {
             $event->setException(new LoginRequiredException("Invalid refresh token. \nPlease log in again by running: {$loginCommand}", $request, $response));
             $event->stopPropagation();
         } elseif ($response->getStatusCode() === 401) {
             $event->setException(new LoginRequiredException("Unauthorized. \nPlease log in again by running: {$loginCommand}", $request, $response));
             $event->stopPropagation();
         } elseif ($response->getStatusCode() === 403) {
             $event->setException(new PermissionDeniedException("Permission denied. Check your project or environment permissions.", $request, $response));
             $event->stopPropagation();
         } else {
             $event->setException(new HttpException(null, $request, $response));
             $event->stopPropagation();
         }
     }
     // When an environment is found to be in the wrong state, perhaps our
     // cache is old - we should invalidate it.
     if ($exception instanceof EnvironmentStateException) {
         $api = new Api();
         $api->clearEnvironmentsCache($exception->getEnvironment()->project);
     }
 }
開發者ID:commerceguys,項目名稱:platform-cli,代碼行數:45,代碼來源:EventSubscriber.php


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