

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 在适用于 PHP 的 SDK 中链接凭证提供程序


可以使用 `Aws\Credentials\CredentialProvider::chain()` 函数将凭证提供程序链接起来。此函数接受可变数量的参数，每个参数都是凭证提供程序函数。然后，此函数会返回一个由提供的函数构成的新函数，这样便可以一个接一个地调用这些函数，直至其中一个提供程序返回已成功执行的 Promise。

`defaultProvider` 在失败之前使用此组合来检查多个提供程序。`defaultProvider` 的源代码演示了 `chain` 函数的使用。

```
// This function returns a provider
public static function defaultProvider(array $config = [])
{
    // This function is the provider, which is actually the composition
    // of multiple providers. Notice that we are also memoizing the result by
    // default.
    return self::memoize(
        self::chain(
            self::env(),
            self::ini(),
            self::instanceProfile($config)
        )
    );
}
```