Exemple #1
0
 /**
  * 客户端构造方法接受一个关联数组作为参数,以下是关联数组的可用选项:
  *
  * - credentials:(CredentialsInterface|array|bool|callable)
  *   指定用来给请求签名的凭证。可以提供:
  *   a) CredentialsInterface 对象。
  *   b) 一个包含 key,secret 和一个可选 token 的关联数组。
  *   c) `false` 不使用凭证。
  *   d) 一个 callable 类型的凭证提供者用来创建凭证或返回 null。
  *      见 CredentialProvider,里面提供了一组内建的凭证提供者列表。
  *   如果没有提供凭证,客户端将尝试从环境变量中获取它们。
  * - endpoint:(string)连接服务接口的完整 URI。只有当你需要自定义连接端点时才需要
  *   设置这个参数,否则将使用各个云服务默认的。
  * - handler:(callable) 一个接收 CommandInterface 和 RequestInterface,并返回
  *   promise 的函数,promise 代表一个完成了的 ResultInterface 或失败了的
  *   CloudAtlasException。处理器并不接收下一个处理器,它是被期望完成命令的终端。
  *   如果没有提供处理器,则使用默认的 Guzzle 处理器。
  * - profile:(string)当凭证是从配置文件中加载时,允许你指定具体使用哪一个身份信息。
  *   这个设置还会覆写 CLOUD_PROFILE 环境变量。注意:指定 profile 会导致 credentials
  *   设置中的 key 被忽略,因为 profile 意味着使用的凭证不是从构造方法中传入的。
  * - scheme:(string,默认为 "https")连接云服务时使用的 URI 方案。默认
  *   将使用 https(也就是利用 SSL/TLS 进行连接) 的 endpoint。可以通过设置 scheme 为
  *   http 而使用未加密的连接。鉴于大陆互联网环境,建议不要更改此选项。
  * - retries:(int,默认为 3)配置客户端允许的最大重试次数(设为 0 禁用重试)。
  * - validate:(bool,默认为 `true`) 设为 `false` 禁用客户端参数验证。
  * - signature_provider:(callable)接受一个签名版本号,返回一个
  *   SignatureInterface 或 null。用来为客户端请求进行签名。
  *   见 SignatureProvider,里面提供了一组内建的签名提供者列表。
  *
  * @param array $arguments
  */
 public function __construct(array $arguments)
 {
     list($arguments['service'], $arguments['exceptionClass']) = $this->parseClass();
     $this->handlerList = new HandlerList();
     $clientConstructor = new ClientResolver(static::getDefaultArguments());
     $config = $clientConstructor->resolve($arguments, $this->handlerList);
     $this->api = $config['api'];
     $this->credentialProvider = $config['credentialProvider'];
     $this->signatureProvider = $config['signatureProvider'];
     $this->endpoint = new Uri($config['endpoint']);
     $this->config = $config['config'];
     $this->defaultRequestOptions = $config['http'];
     $stack = static::getHandlerList();
     static::addSignatureMiddleware();
 }
 /**
  * 获取默认的客户端构造参数用于实例化客户端。
  *
  * @return array
  */
 public static function getDefaultArguments()
 {
     return ClientResolver::getDefaultArguments();
 }