public function __construct(CliConfig $config = null, EventDispatcherInterface $dispatcher = null)
{
$this->config = $config ?: new CliConfig();
$this->dispatcher = $dispatcher;
self::$sessionId = $this->config->get('api.session_id') ?: 'default';
if (self::$sessionId === 'api-token') {
throw new \InvalidArgumentException('Invalid session ID: ' . self::$sessionId);
}
if (!isset(self::$apiToken)) {
// Exchangeable API tokens: a token which is exchanged for a
// temporary access token.
if ($this->config->has('api.token_file')) {
self::$apiToken = $this->loadTokenFromFile($this->config->get('api.token_file'));
self::$apiTokenType = 'exchange';
self::$sessionId = 'api-token';
} elseif ($this->config->has('api.token')) {
self::$apiToken = $this->config->get('api.token');
self::$apiTokenType = 'exchange';
self::$sessionId = 'api-token';
} elseif ($this->config->has('api.access_token_file')) {
self::$apiToken = $this->loadTokenFromFile($this->config->get('api.access_token_file'));
self::$apiTokenType = 'access';
} elseif ($this->config->has('api.access_token')) {
self::$apiToken = $this->config->get('api.access_token');
self::$apiTokenType = 'access';
}
}
$this->setUpCache();
}