From 0c8af4992cb0f7589dcafaad65ada12753c64594 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 23 Nov 2022 21:14:33 +0300 Subject: initial --- .../src/AbstractConfigurationProvider.php | 157 +++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 vendor/aws/aws-sdk-php/src/AbstractConfigurationProvider.php (limited to 'vendor/aws/aws-sdk-php/src/AbstractConfigurationProvider.php') diff --git a/vendor/aws/aws-sdk-php/src/AbstractConfigurationProvider.php b/vendor/aws/aws-sdk-php/src/AbstractConfigurationProvider.php new file mode 100644 index 0000000..78a5cda --- /dev/null +++ b/vendor/aws/aws-sdk-php/src/AbstractConfigurationProvider.php @@ -0,0 +1,157 @@ +get($cacheKey); + if ($found instanceof static::$interfaceClass) { + return Promise\Create::promiseFor($found); + } + + return $provider() + ->then(function ($config) use ( + $cache, + $cacheKey + ) { + $cache->set($cacheKey, $config); + return $config; + }); + }; + } + + /** + * Creates an aggregate configuration provider that invokes the provided + * variadic providers one after the other until a provider returns + * configuration. + * + * @return callable + */ + public static function chain() + { + $links = func_get_args(); + if (empty($links)) { + throw new \InvalidArgumentException('No providers in chain'); + } + + return function () use ($links) { + /** @var callable $parent */ + $parent = array_shift($links); + $promise = $parent(); + while ($next = array_shift($links)) { + $promise = $promise->otherwise($next); + } + return $promise; + }; + } + + /** + * Gets the environment's HOME directory if available. + * + * @return null|string + */ + protected static function getHomeDir() + { + // On Linux/Unix-like systems, use the HOME environment variable + if ($homeDir = getenv('HOME')) { + return $homeDir; + } + + // Get the HOMEDRIVE and HOMEPATH values for Windows hosts + $homeDrive = getenv('HOMEDRIVE'); + $homePath = getenv('HOMEPATH'); + + return ($homeDrive && $homePath) ? $homeDrive . $homePath : null; + } + + /** + * Gets default config file location from environment, falling back to aws + * default location + * + * @return string + */ + protected static function getDefaultConfigFilename() + { + if ($filename = getenv(self::ENV_CONFIG_FILE)) { + return $filename; + } + return self::getHomeDir() . '/.aws/config'; + } + + /** + * Wraps a config provider and caches previously provided configuration. + * + * @param callable $provider Config provider function to wrap. + * + * @return callable + */ + public static function memoize(callable $provider) + { + return function () use ($provider) { + static $result; + static $isConstant; + + // Constant config will be returned constantly. + if ($isConstant) { + return $result; + } + + // Create the initial promise that will be used as the cached value + if (null === $result) { + $result = $provider(); + } + + // Return config and set flag that provider is already set + return $result + ->then(function ($config) use (&$isConstant) { + $isConstant = true; + return $config; + }); + }; + } + + /** + * Reject promise with standardized exception. + * + * @param $msg + * @return Promise\RejectedPromise + */ + protected static function reject($msg) + { + $exceptionClass = static::$exceptionClass; + return new Promise\RejectedPromise(new $exceptionClass($msg)); + } +} -- cgit v1.2.3