/** * 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; }
/** * 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 = array(); foreach (array('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()); } self::$client = new PlatformClient($connector); if ($autoLogin && !$connector->isLoggedIn()) { $this->login(); } } return self::$client; }