

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# `process` 適用於 PHP 的 SDK 中的 提供者
<a name="process-provider"></a>

 `Aws\Credentials\CredentialProvider::process` 會嘗試透過執行[共用 AWS 組態檔案中](https://docs.aws.amazon.com/sdkref/latest/guide/file-format.html)設定檔中指定的`credential_process`值來載入登入資料。

根據預設，軟體開發套件會先嘗試從位於 的共用 AWS `credentials`檔案載入「預設」描述檔`~/.aws/credentials`。如果在共用`credentials`檔案中找不到「預設」設定檔，軟體開發套件會在共用`config`檔案中尋找預設設定檔。以下是共用`credentials`檔案的組態範例。

```
[default]
credential_process = /path/to/file/credential_returning_executable.sh --custom-command custom_parameter
```

SDK 會使用 PHP 的 `shell_exec`函數完全呼叫 `credential_process`命令，然後從 stdout 讀取 JSON 資料。`credential_process` 必須以下列格式將登入資料寫入 stdout：

```
{
    "Version": 1,
    "AccessKeyId": "",
    "SecretAccessKey": "",
    "SessionToken": "",
    "Expiration": ""
}
```

 `SessionToken` 和 `Expiration` 為選用。如果存在，則該登入資料會被視為臨時。

```
use Aws\Credentials\CredentialProvider;
use Aws\S3\S3Client;

$provider = CredentialProvider::process();
// Cache the results in a memoize function to avoid loading and parsing
// the ini file on every API operation
$provider = CredentialProvider::memoize($provider);

$client = new S3Client([
    'region'      => 'us-west-2',
    'version'     => '2006-03-01',
    'credentials' => $provider
]);
```

您可以將引數提供給建立供應商的函數，以使用自訂描述檔或 .ini 檔案位置。

```
$profile = 'production';
$path = '/full/path/to/credentials.ini';

$provider = CredentialProvider::process($profile, $path);
$provider = CredentialProvider::memoize($provider);

$client = new S3Client([
    'region'      => 'us-west-2',
    'version'     => '2006-03-01',
    'credentials' => $provider
]);
```