SDK for PHP 3.x

ConfigurationProvider extends AbstractConfigurationProvider
in package
implements ConfigurationProviderInterface

A configuration provider is a function that returns a promise that is fulfilled with a {@see \Aws\DefaultsMode\ConfigurationInterface} or rejected with an {@see \Aws\DefaultsMode\Exception\ConfigurationException}.

use Aws\Sts\RegionalEndpoints\ConfigurationProvider; $provider = ConfigurationProvider::defaultProvider(); // Returns a ConfigurationInterface or throws. $config = $provider()->wait();

Configuration providers can be composed to create configuration using conditional logic that can create different configurations in different environments. You can compose multiple providers into a single provider using ConfigurationProvider::chain. This function accepts providers as variadic arguments and returns a new function that will invoke each provider until a successful configuration is returned.

// First try an INI file at this location. $a = ConfigurationProvider::ini(null, '/path/to/file.ini'); // Then try an INI file at this location. $b = ConfigurationProvider::ini(null, '/path/to/other-file.ini'); // Then try loading from environment variables. $c = ConfigurationProvider::env(); // Combine the three providers together. $composed = ConfigurationProvider::chain($a, $b, $c); // Returns a promise that is fulfilled with a configuration or throws. $promise = $composed(); // Wait on the configuration to resolve. $config = $promise->wait();

Table of Contents

Interfaces

ConfigurationProviderInterface

Constants

DEFAULT_MODE  = 'legacy'
ENV_CONFIG_FILE  = 'AWS_CONFIG_FILE'
ENV_MODE  = 'AWS_DEFAULTS_MODE'
ENV_PROFILE  = 'AWS_PROFILE'
INI_MODE  = 'defaults_mode'

Properties

$cacheKey  : mixed

Methods

cache()  : callable
Wraps a config provider and saves provided configuration in an instance of Aws\CacheInterface. Forwards calls when no config found in cache and updates cache with the results.
chain()  : callable
Creates an aggregate configuration provider that invokes the provided variadic providers one after the other until a provider returns configuration.
defaultProvider()  : callable
Create a default config provider that first checks for environment variables, then checks for a specified profile in the environment-defined config file location (env variable is 'AWS_CONFIG_FILE', file location defaults to ~/.aws/config), then checks for the "default" profile in the environment-defined config file location, and failing those uses a default fallback set of configuration options.
env()  : callable
Provider that creates config from environment variables.
fallback()  : callable
Fallback config options when other sources are not set.
ini()  : callable
Config provider that creates config using a config file whose location is specified by an environment variable 'AWS_CONFIG_FILE', defaulting to ~/.aws/config if not specified
memoize()  : callable
Wraps a config provider and caches previously provided configuration.
unwrap()  : ConfigurationInterface
Unwraps a configuration object in whatever valid form it is in, always returning a ConfigurationInterface object.

Constants

DEFAULT_MODE

public mixed DEFAULT_MODE = 'legacy'

ENV_CONFIG_FILE

public mixed ENV_CONFIG_FILE = 'AWS_CONFIG_FILE'

ENV_MODE

public mixed ENV_MODE = 'AWS_DEFAULTS_MODE'

ENV_PROFILE

public mixed ENV_PROFILE = 'AWS_PROFILE'

INI_MODE

public mixed INI_MODE = 'defaults_mode'

Properties

$cacheKey

public static mixed $cacheKey = 'aws_defaults_mode'

Methods

cache()

Wraps a config provider and saves provided configuration in an instance of Aws\CacheInterface. Forwards calls when no config found in cache and updates cache with the results.

public static cache(callable $provider, CacheInterface $cache[, string|null $cacheKey = null ]) : callable
Parameters
$provider : callable

Configuration provider function to wrap

$cache : CacheInterface

Cache to store configuration

$cacheKey : string|null = null

(optional) Cache key to use

Return values
callable

chain()

Creates an aggregate configuration provider that invokes the provided variadic providers one after the other until a provider returns configuration.

public static chain() : callable
Return values
callable

defaultProvider()

Create a default config provider that first checks for environment variables, then checks for a specified profile in the environment-defined config file location (env variable is 'AWS_CONFIG_FILE', file location defaults to ~/.aws/config), then checks for the "default" profile in the environment-defined config file location, and failing those uses a default fallback set of configuration options.

public static defaultProvider([array<string|int, mixed> $config = [] ]) : callable

This provider is automatically wrapped in a memoize function that caches previously provided config options.

Parameters
$config : array<string|int, mixed> = []
Return values
callable

env()

Provider that creates config from environment variables.

public static env() : callable
Return values
callable

fallback()

Fallback config options when other sources are not set.

public static fallback() : callable
Return values
callable

ini()

Config provider that creates config using a config file whose location is specified by an environment variable 'AWS_CONFIG_FILE', defaulting to ~/.aws/config if not specified

public static ini([string|null $profile = null ][, string|null $filename = null ]) : callable
Parameters
$profile : string|null = null

Profile to use. If not specified will use the "default" profile.

$filename : string|null = null

If provided, uses a custom filename rather than looking in the default directory.

Return values
callable

memoize()

Wraps a config provider and caches previously provided configuration.

public static memoize(callable $provider) : callable
Parameters
$provider : callable

Config provider function to wrap.

Return values
callable

unwrap()

Unwraps a configuration object in whatever valid form it is in, always returning a ConfigurationInterface object.

public static unwrap(mixed $config) : ConfigurationInterface
Parameters
$config : mixed
Tags
throws
InvalidArgumentException
Return values
ConfigurationInterface
On this page