コード例 #1
0
 /**
  * Get the API client object.
  *
  * @param bool $autoLogin Whether to log in, if the client is not already
  *                        authenticated (default: true).
  *
  * @return PlatformClient
  */
 public function getClient($autoLogin = true)
 {
     if (!isset(self::$client)) {
         $connectorOptions = [];
         if (getenv('PLATFORM_CLI_ACCOUNTS_SITE')) {
             $connectorOptions['accounts'] = getenv('PLATFORM_CLI_ACCOUNTS_SITE');
         }
         $connectorOptions['verify'] = !getenv('PLATFORM_CLI_SKIP_SSL');
         $connectorOptions['debug'] = (bool) getenv('PLATFORM_CLI_DEBUG');
         $connectorOptions['client_id'] = 'platform-cli';
         $connectorOptions['user_agent'] = $this->getUserAgent();
         $connectorOptions['cache'] = true;
         $connector = new Connector($connectorOptions);
         $session = $connector->getSession();
         $session->setId('cli-' . $this->sessionId);
         $session->setStorage(new File());
         self::$client = new PlatformClient($connector);
         if ($autoLogin && !$connector->isLoggedIn()) {
             $this->login();
         }
     }
     return self::$client;
 }
コード例 #2
0
 /**
  * Get the API client object.
  *
  * @param bool $autoLogin Whether to log in, if the client is not already
  *                        authenticated (default: true).
  *
  * @return PlatformClient
  */
 public function getClient($autoLogin = true)
 {
     if (!isset(self::$client)) {
         $connectorOptions = [];
         if (getenv('PLATFORMSH_CLI_ACCOUNTS_SITE')) {
             $connectorOptions['accounts'] = getenv('PLATFORMSH_CLI_ACCOUNTS_SITE');
         }
         $connectorOptions['verify'] = !getenv('PLATFORMSH_CLI_SKIP_SSL');
         $connectorOptions['debug'] = (bool) getenv('PLATFORMSH_CLI_DEBUG');
         $connectorOptions['client_id'] = 'platform-cli';
         $connectorOptions['user_agent'] = $this->getUserAgent();
         // Proxy support with the http_proxy or https_proxy environment
         // variables.
         $proxies = [];
         foreach (['https', 'http'] as $scheme) {
             $proxies[$scheme] = str_replace('http://', 'tcp://', getenv($scheme . '_proxy'));
         }
         $proxies = array_filter($proxies);
         if (count($proxies)) {
             $connectorOptions['proxy'] = count($proxies) == 1 ? reset($proxies) : $proxies;
         }
         $connector = new Connector($connectorOptions);
         // If an API token is set, that's all we need to authenticate.
         if (isset(self::$apiToken)) {
             $connector->setApiToken(self::$apiToken);
         } else {
             $session = $connector->getSession();
             $session->setId('cli-' . self::$sessionId);
             $session->setStorage(new File($this->getSessionsDir()));
         }
         $this->debug('Initializing API client');
         self::$client = new PlatformClient($connector);
         if ($autoLogin && !$connector->isLoggedIn()) {
             $this->debug('The user is not logged in yet');
             $this->login();
         }
     }
     return self::$client;
 }
コード例 #3
0
ファイル: Api.php プロジェクト: commerceguys/platform-cli
 /**
  * Get the API client object.
  *
  * @param bool $autoLogin Whether to log in, if the client is not already
  *                        authenticated (default: true).
  *
  * @return PlatformClient
  */
 public function getClient($autoLogin = true)
 {
     if (!isset(self::$client)) {
         $connectorOptions = [];
         $connectorOptions['accounts'] = $this->config->get('api.accounts_api_url');
         $connectorOptions['verify'] = !$this->config->get('api.skip_ssl');
         $connectorOptions['debug'] = $this->config->get('api.debug');
         $connectorOptions['client_id'] = $this->config->get('api.oauth2_client_id');
         $connectorOptions['user_agent'] = $this->getUserAgent();
         $connectorOptions['api_token'] = self::$apiToken;
         $connectorOptions['api_token_type'] = self::$apiTokenType;
         // Proxy support with the http_proxy or https_proxy environment
         // variables.
         if (PHP_SAPI === 'cli') {
             $proxies = [];
             foreach (['https', 'http'] as $scheme) {
                 $proxies[$scheme] = str_replace('http://', 'tcp://', getenv($scheme . '_proxy'));
             }
             $proxies = array_filter($proxies);
             if (count($proxies)) {
                 $connectorOptions['proxy'] = count($proxies) == 1 ? reset($proxies) : $proxies;
             }
         }
         $connector = new Connector($connectorOptions);
         // Set up a persistent session to store OAuth2 tokens. By default,
         // this will be stored in a JSON file:
         // $HOME/.platformsh/.session/sess-cli-default/sess-cli-default.json
         $session = $connector->getSession();
         $session->setId('cli-' . self::$sessionId);
         $session->setStorage(new File($this->config->getUserConfigDir() . '/.session'));
         self::$client = new PlatformClient($connector);
         if (isset($this->dispatcher) && $autoLogin && !$connector->isLoggedIn()) {
             $this->dispatcher->dispatch('login_required');
         }
     }
     return self::$client;
 }