PluginProbe
Media Cloud Sync / 1.2.13
Media Cloud Sync v1.2.13
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / ClientResolver.php

ClientResolver.php in Media Cloud Sync 1.2.13, at includes/sdk/s3/Aws/ClientResolver.php

758 lines 49.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws;
4
5 use Dudlewebs\WPMCS\s3\Aws\Api\ApiProvider;
6 use Dudlewebs\WPMCS\s3\Aws\Api\Service;
7 use Dudlewebs\WPMCS\s3\Aws\Api\Validator;
8 use Dudlewebs\WPMCS\s3\Aws\Auth\AuthResolver;
9 use Dudlewebs\WPMCS\s3\Aws\Auth\AuthSchemeResolver;
10 use Dudlewebs\WPMCS\s3\Aws\Auth\AuthSchemeResolverInterface;
11 use Dudlewebs\WPMCS\s3\Aws\ClientSideMonitoring\ApiCallAttemptMonitoringMiddleware;
12 use Dudlewebs\WPMCS\s3\Aws\ClientSideMonitoring\ApiCallMonitoringMiddleware;
13 use Dudlewebs\WPMCS\s3\Aws\ClientSideMonitoring\Configuration;
14 use Dudlewebs\WPMCS\s3\Aws\Configuration\ConfigurationResolver;
15 use Dudlewebs\WPMCS\s3\Aws\Credentials\CredentialProvider;
16 use Dudlewebs\WPMCS\s3\Aws\Credentials\Credentials;
17 use Dudlewebs\WPMCS\s3\Aws\Credentials\CredentialsInterface;
18 use Dudlewebs\WPMCS\s3\Aws\DefaultsMode\ConfigurationInterface as ConfigModeInterface;
19 use Dudlewebs\WPMCS\s3\Aws\DefaultsMode\ConfigurationProvider as ConfigModeProvider;
20 use Dudlewebs\WPMCS\s3\Aws\Endpoint\EndpointProvider;
21 use Dudlewebs\WPMCS\s3\Aws\Endpoint\PartitionEndpointProvider;
22 use Dudlewebs\WPMCS\s3\Aws\Endpoint\UseDualstackEndpoint\Configuration as UseDualStackEndpointConfiguration;
23 use Dudlewebs\WPMCS\s3\Aws\Endpoint\UseDualstackEndpoint\ConfigurationInterface as UseDualStackEndpointConfigurationInterface;
24 use Dudlewebs\WPMCS\s3\Aws\Endpoint\UseDualstackEndpoint\ConfigurationProvider as UseDualStackConfigProvider;
25 use Dudlewebs\WPMCS\s3\Aws\Endpoint\UseFipsEndpoint\Configuration as UseFipsEndpointConfiguration;
26 use Dudlewebs\WPMCS\s3\Aws\Endpoint\UseFipsEndpoint\ConfigurationInterface as UseFipsEndpointConfigurationInterface;
27 use Dudlewebs\WPMCS\s3\Aws\Endpoint\UseFipsEndpoint\ConfigurationProvider as UseFipsConfigProvider;
28 use Dudlewebs\WPMCS\s3\Aws\EndpointDiscovery\ConfigurationInterface;
29 use Dudlewebs\WPMCS\s3\Aws\EndpointDiscovery\ConfigurationProvider;
30 use Dudlewebs\WPMCS\s3\Aws\EndpointV2\EndpointDefinitionProvider;
31 use Dudlewebs\WPMCS\s3\Aws\Exception\AwsException;
32 use Dudlewebs\WPMCS\s3\Aws\Exception\InvalidRegionException;
33 use Dudlewebs\WPMCS\s3\Aws\Retry\ConfigurationInterface as RetryConfigInterface;
34 use Dudlewebs\WPMCS\s3\Aws\Retry\ConfigurationProvider as RetryConfigProvider;
35 use Dudlewebs\WPMCS\s3\Aws\Signature\SignatureProvider;
36 use Dudlewebs\WPMCS\s3\Aws\Token\Token;
37 use Dudlewebs\WPMCS\s3\Aws\Token\TokenInterface;
38 use Dudlewebs\WPMCS\s3\Aws\Token\TokenProvider;
39 use Dudlewebs\WPMCS\s3\GuzzleHttp\Promise\PromiseInterface;
40 use InvalidArgumentException as IAE;
41 use Dudlewebs\WPMCS\s3\Psr\Http\Message\RequestInterface;
42 /**
43 * @internal Resolves a hash of client arguments to construct a client.
44 */
45 class ClientResolver
46 {
47 /** @var array */
48 private $argDefinitions;
49 /** @var array Map of types to a corresponding function */
50 private static $typeMap = ['resource' => 'is_resource', 'callable' => 'is_callable', 'int' => 'is_int', 'bool' => 'is_bool', 'boolean' => 'is_bool', 'string' => 'is_string', 'object' => 'is_object', 'array' => 'is_array'];
51 private static $defaultArgs = ['service' => ['type' => 'value', 'valid' => ['string'], 'doc' => 'Name of the service to utilize. This value will be supplied by default when using one of the SDK clients (e.g., Aws\\S3\\S3Client).', 'required' => \true, 'internal' => \true], 'exception_class' => ['type' => 'value', 'valid' => ['string'], 'doc' => 'Exception class to create when an error occurs.', 'default' => AwsException::class, 'internal' => \true], 'scheme' => ['type' => 'value', 'valid' => ['string'], 'default' => 'https', 'doc' => 'URI scheme to use when connecting connect. The SDK will utilize "https" endpoints (i.e., utilize SSL/TLS connections) by default. You can attempt to connect to a service over an unencrypted "http" endpoint by setting ``scheme`` to "http".'], 'disable_host_prefix_injection' => ['type' => 'value', 'valid' => ['bool'], 'doc' => 'Set to true to disable host prefix injection logic for services that use it. This disables the entire prefix injection, including the portions supplied by user-defined parameters. Setting this flag will have no effect on services that do not use host prefix injection.', 'default' => \false], 'ignore_configured_endpoint_urls' => ['type' => 'value', 'valid' => ['bool'], 'doc' => 'Set to true to disable endpoint urls configured using `AWS_ENDPOINT_URL` and `endpoint_url` shared config option.', 'fn' => [__CLASS__, '_apply_ignore_configured_endpoint_urls'], 'default' => [__CLASS__, '_default_ignore_configured_endpoint_urls']], 'endpoint' => ['type' => 'value', 'valid' => ['string'], 'doc' => 'The full URI of the webservice. This is only required when connecting to a custom endpoint (e.g., a local version of S3).', 'fn' => [__CLASS__, '_apply_endpoint'], 'default' => [__CLASS__, '_default_endpoint']], 'region' => ['type' => 'value', 'valid' => ['string'], 'doc' => 'Region to connect to. See http://docs.aws.amazon.com/general/latest/gr/rande.html for a list of available regions.', 'fn' => [__CLASS__, '_apply_region'], 'default' => [__CLASS__, '_default_region']], 'version' => ['type' => 'value', 'valid' => ['string'], 'doc' => 'The version of the webservice to utilize (e.g., 2006-03-01).', 'default' => 'latest'], 'signature_provider' => ['type' => 'value', 'valid' => ['callable'], 'doc' => 'A callable that accepts a signature version name (e.g., "v4"), a service name, and region, and returns a SignatureInterface object or null. This provider is used to create signers utilized by the client. See Aws\\Signature\\SignatureProvider for a list of built-in providers', 'default' => [__CLASS__, '_default_signature_provider']], 'api_provider' => ['type' => 'value', 'valid' => ['callable'], 'doc' => 'An optional PHP callable that accepts a type, service, and version argument, and returns an array of corresponding configuration data. The type value can be one of api, waiter, or paginator.', 'fn' => [__CLASS__, '_apply_api_provider'], 'default' => [ApiProvider::class, 'defaultProvider']], 'configuration_mode' => ['type' => 'value', 'valid' => [ConfigModeInterface::class, CacheInterface::class, 'string', 'closure'], 'doc' => "Sets the default configuration mode. Otherwise provide an instance of Aws\\DefaultsMode\\ConfigurationInterface, an instance of Aws\\CacheInterface, or a string containing a valid mode", 'fn' => [__CLASS__, '_apply_defaults'], 'default' => [ConfigModeProvider::class, 'defaultProvider']], 'use_fips_endpoint' => ['type' => 'value', 'valid' => ['bool', UseFipsEndpointConfiguration::class, CacheInterface::class, 'callable'], 'doc' => 'Set to true to enable the use of FIPS pseudo regions', 'fn' => [__CLASS__, '_apply_use_fips_endpoint'], 'default' => [__CLASS__, '_default_use_fips_endpoint']], 'use_dual_stack_endpoint' => ['type' => 'value', 'valid' => ['bool', UseDualStackEndpointConfiguration::class, CacheInterface::class, 'callable'], 'doc' => 'Set to true to enable the use of dual-stack endpoints', 'fn' => [__CLASS__, '_apply_use_dual_stack_endpoint'], 'default' => [__CLASS__, '_default_use_dual_stack_endpoint']], 'endpoint_provider' => ['type' => 'value', 'valid' => ['callable', EndpointV2\EndpointProviderV2::class], 'fn' => [__CLASS__, '_apply_endpoint_provider'], 'doc' => 'An optional PHP callable that accepts a hash of options including a "service" and "region" key and returns NULL or a hash of endpoint data, of which the "endpoint" key is required. See Aws\\Endpoint\\EndpointProvider for a list of built-in providers.', 'default' => [__CLASS__, '_default_endpoint_provider']], 'serializer' => ['default' => [__CLASS__, '_default_serializer'], 'fn' => [__CLASS__, '_apply_serializer'], 'internal' => \true, 'type' => 'value', 'valid' => ['callable']], 'signature_version' => ['type' => 'config', 'valid' => ['string'], 'doc' => 'A string representing a custom signature version to use with a service (e.g., v4). Note that per/operation signature version MAY override this requested signature version.', 'default' => [__CLASS__, '_default_signature_version']], 'signing_name' => ['type' => 'config', 'valid' => ['string'], 'doc' => 'A string representing a custom service name to be used when calculating a request signature.', 'default' => [__CLASS__, '_default_signing_name']], 'signing_region' => ['type' => 'config', 'valid' => ['string'], 'doc' => 'A string representing a custom region name to be used when calculating a request signature.', 'default' => [__CLASS__, '_default_signing_region']], 'profile' => ['type' => 'config', 'valid' => ['string'], 'doc' => 'Allows you to specify which profile to use when credentials are created from the AWS credentials file in your HOME directory. This setting overrides the AWS_PROFILE environment variable. Note: Specifying "profile" will cause the "credentials" and "use_aws_shared_config_files" keys to be ignored.', 'fn' => [__CLASS__, '_apply_profile']], 'credentials' => ['type' => 'value', 'valid' => [CredentialsInterface::class, CacheInterface::class, 'array', 'bool', 'callable'], 'doc' => 'Specifies the credentials used to sign requests. Provide an Aws\\Credentials\\CredentialsInterface object, an associative array of "key", "secret", and an optional "token" key, `false` to use null credentials, or a callable credentials provider used to create credentials or return null. See Aws\\Credentials\\CredentialProvider for a list of built-in credentials providers. If no credentials are provided, the SDK will attempt to load them from the environment.', 'fn' => [__CLASS__, '_apply_credentials'], 'default' => [__CLASS__, '_default_credential_provider']], 'token' => ['type' => 'value', 'valid' => [TokenInterface::class, CacheInterface::class, 'array', 'bool', 'callable'], 'doc' => 'Specifies the token used to authorize requests. Provide an Aws\\Token\\TokenInterface object, an associative array of "token", and an optional "expiration" key, `false` to use a null token, or a callable token provider used to fetch a token or return null. See Aws\\Token\\TokenProvider for a list of built-in credentials providers. If no token is provided, the SDK will attempt to load one from the environment.', 'fn' => [__CLASS__, '_apply_token'], 'default' => [__CLASS__, '_default_token_provider']], 'auth_scheme_resolver' => ['type' => 'value', 'valid' => [AuthSchemeResolverInterface::class], 'doc' => 'An instance of Aws\\Auth\\AuthSchemeResolverInterface which selects a modeled auth scheme and returns a signature version', 'default' => [__CLASS__, '_default_auth_scheme_resolver']], 'endpoint_discovery' => ['type' => 'value', 'valid' => [ConfigurationInterface::class, CacheInterface::class, 'array', 'callable'], 'doc' => 'Specifies settings for endpoint discovery. Provide an instance of Aws\\EndpointDiscovery\\ConfigurationInterface, an instance Aws\\CacheInterface, a callable that provides a promise for a Configuration object, or an associative array with the following keys: enabled: (bool) Set to true to enable endpoint discovery, false to explicitly disable it. Defaults to false; cache_limit: (int) The maximum number of keys in the endpoints cache. Defaults to 1000.', 'fn' => [__CLASS__, '_apply_endpoint_discovery'], 'default' => [__CLASS__, '_default_endpoint_discovery_provider']], 'stats' => ['type' => 'value', 'valid' => ['bool', 'array'], 'default' => \false, 'doc' => 'Set to true to gather transfer statistics on requests sent. Alternatively, you can provide an associative array with the following keys: retries: (bool) Set to false to disable reporting on retries attempted; http: (bool) Set to true to enable collecting statistics from lower level HTTP adapters (e.g., values returned in GuzzleHttp\\TransferStats). HTTP handlers must support an http_stats_receiver option for this to have an effect; timer: (bool) Set to true to enable a command timer that reports the total wall clock time spent on an operation in seconds.', 'fn' => [__CLASS__, '_apply_stats']], 'retries' => ['type' => 'value', 'valid' => ['int', RetryConfigInterface::class, CacheInterface::class, 'callable', 'array'], 'doc' => "Configures the retry mode and maximum number of allowed retries for a client (pass 0 to disable retries). Provide an integer for 'legacy' mode with the specified number of retries. Otherwise provide an instance of Aws\\Retry\\ConfigurationInterface, an instance of Aws\\CacheInterface, a callable function, or an array with the following keys: mode: (string) Set to 'legacy', 'standard' (uses retry quota management), or 'adapative' (an experimental mode that adds client-side rate limiting to standard mode); max_attempts: (int) The maximum number of attempts for a given request. ", 'fn' => [__CLASS__, '_apply_retries'], 'default' => [RetryConfigProvider::class, 'defaultProvider']], 'validate' => ['type' => 'value', 'valid' => ['bool', 'array'], 'default' => \true, 'doc' => 'Set to false to disable client-side parameter validation. Set to true to utilize default validation constraints. Set to an associative array of validation options to enable specific validation constraints.', 'fn' => [__CLASS__, '_apply_validate']], 'debug' => ['type' => 'value', 'valid' => ['bool', 'array'], 'doc' => 'Set to true to display debug information when sending requests. Alternatively, you can provide an associative array with the following keys: logfn: (callable) Function that is invoked with log messages; stream_size: (int) When the size of a stream is greater than this number, the stream data will not be logged (set to "0" to not log any stream data); scrub_auth: (bool) Set to false to disable the scrubbing of auth data from the logged messages; http: (bool) Set to false to disable the "debug" feature of lower level HTTP adapters (e.g., verbose curl output).', 'fn' => [__CLASS__, '_apply_debug']], 'disable_request_compression' => ['type' => 'value', 'valid' => ['bool', 'callable'], 'doc' => 'Set to true to disable request compression for supported operations', 'fn' => [__CLASS__, '_apply_disable_request_compression'], 'default' => [__CLASS__, '_default_disable_request_compression']], 'request_min_compression_size_bytes' => ['type' => 'value', 'valid' => ['int', 'callable'], 'doc' => 'Set to a value between between 0 and 10485760 bytes, inclusive. This value will be ignored if `disable_request_compression` is set to `true`', 'fn' => [__CLASS__, '_apply_min_compression_size'], 'default' => [__CLASS__, '_default_min_compression_size']], 'csm' => ['type' => 'value', 'valid' => [\Dudlewebs\WPMCS\s3\Aws\ClientSideMonitoring\ConfigurationInterface::class, 'callable', 'array', 'bool'], 'doc' => 'CSM options for the client. Provides a callable wrapping a promise, a boolean "false", an instance of ConfigurationInterface, or an associative array of "enabled", "host", "port", and "client_id".', 'fn' => [__CLASS__, '_apply_csm'], 'default' => [\Dudlewebs\WPMCS\s3\Aws\ClientSideMonitoring\ConfigurationProvider::class, 'defaultProvider']], 'http' => ['type' => 'value', 'valid' => ['array'], 'default' => [], 'doc' => 'Set to an array of SDK request options to apply to each request (e.g., proxy, verify, etc.).'], 'http_handler' => ['type' => 'value', 'valid' => ['callable'], 'doc' => 'An HTTP handler is a function that accepts a PSR-7 request object and returns a promise that is fulfilled with a PSR-7 response object or rejected with an array of exception data. NOTE: This option supersedes any provided "handler" option.', 'fn' => [__CLASS__, '_apply_http_handler']], 'handler' => ['type' => 'value', 'valid' => ['callable'], 'doc' => 'A handler that accepts a command object, request object and returns a promise that is fulfilled with an Aws\\ResultInterface object or rejected with an Aws\\Exception\\AwsException. A handler does not accept a next handler as it is terminal and expected to fulfill a command. If no handler is provided, a default Guzzle handler will be utilized.', 'fn' => [__CLASS__, '_apply_handler'], 'default' => [__CLASS__, '_default_handler']], 'app_id' => ['type' => 'value', 'valid' => ['string'], 'doc' => 'app_id(AppId) is an optional application specific identifier that can be set.
52 When set it will be appended to the User-Agent header of every request in the form of App/{AppId}.
53 This value is also sourced from environment variable AWS_SDK_UA_APP_ID or the shared config profile attribute sdk_ua_app_id.', 'fn' => [__CLASS__, '_apply_app_id'], 'default' => [__CLASS__, '_default_app_id']], 'ua_append' => ['type' => 'value', 'valid' => ['string', 'array'], 'doc' => 'Provide a string or array of strings to send in the User-Agent header.', 'fn' => [__CLASS__, '_apply_user_agent'], 'default' => []], 'idempotency_auto_fill' => ['type' => 'value', 'valid' => ['bool', 'callable'], 'doc' => 'Set to false to disable SDK to populate parameters that enabled \'idempotencyToken\' trait with a random UUID v4 value on your behalf. Using default value \'true\' still allows parameter value to be overwritten when provided. Note: auto-fill only works when cryptographically secure random bytes generator functions(random_bytes, openssl_random_pseudo_bytes or mcrypt_create_iv) can be found. You may also provide a callable source of random bytes.', 'default' => \true, 'fn' => [__CLASS__, '_apply_idempotency_auto_fill']], 'use_aws_shared_config_files' => ['type' => 'value', 'valid' => ['bool'], 'doc' => 'Set to false to disable checking for shared aws config files usually located in \'~/.aws/config\' and \'~/.aws/credentials\'. This will be ignored if you set the \'profile\' setting.', 'default' => \true], 'account_id_endpoint_mode' => ['type' => 'value', 'valid' => ['string'], 'doc' => 'Decides whether account_id must a be a required resolved credentials property. If this configuration is set to disabled, then account_id is not required. If set to preferred a warning will be logged when account_id is not resolved, and when set to required an exception will be thrown if account_id is not resolved.', 'default' => [__CLASS__, '_default_account_id_endpoint_mode'], 'fn' => [__CLASS__, '_apply_account_id_endpoint_mode']], 'sigv4a_signing_region_set' => ['type' => 'value', 'valid' => ['array', 'string'], 'doc' => 'A comma-delimited list of supported regions sent in sigv4a requests.', 'fn' => [__CLASS__, '_apply_sigv4a_signing_region_set'], 'default' => [__CLASS__, '_default_sigv4a_signing_region_set']]];
54 /**
55 * Gets an array of default client arguments, each argument containing a
56 * hash of the following:
57 *
58 * - type: (string, required) option type described as follows:
59 * - value: The default option type.
60 * - config: The provided value is made available in the client's
61 * getConfig() method.
62 * - valid: (array, required) Valid PHP types or class names. Note: null
63 * is not an allowed type.
64 * - required: (bool, callable) Whether or not the argument is required.
65 * Provide a function that accepts an array of arguments and returns a
66 * string to provide a custom error message.
67 * - default: (mixed) The default value of the argument if not provided. If
68 * a function is provided, then it will be invoked to provide a default
69 * value. The function is provided the array of options and is expected
70 * to return the default value of the option. The default value can be a
71 * closure and can not be a callable string that is not part of the
72 * defaultArgs array.
73 * - doc: (string) The argument documentation string.
74 * - fn: (callable) Function used to apply the argument. The function
75 * accepts the provided value, array of arguments by reference, and an
76 * event emitter.
77 *
78 * Note: Order is honored and important when applying arguments.
79 *
80 * @return array
81 */
82 public static function getDefaultArguments()
83 {
84 return self::$defaultArgs;
85 }
86 /**
87 * @param array $argDefinitions Client arguments.
88 */
89 public function __construct(array $argDefinitions)
90 {
91 $this->argDefinitions = $argDefinitions;
92 }
93 /**
94 * Resolves client configuration options and attached event listeners.
95 * Check for missing keys in passed arguments
96 *
97 * @param array $args Provided constructor arguments.
98 * @param HandlerList $list Handler list to augment.
99 *
100 * @return array Returns the array of provided options.
101 * @throws \InvalidArgumentException
102 * @see Aws\AwsClient::__construct for a list of available options.
103 */
104 public function resolve(array $args, HandlerList $list)
105 {
106 $args['config'] = [];
107 foreach ($this->argDefinitions as $key => $a) {
108 // Add defaults, validate required values, and skip if not set.
109 if (!isset($args[$key])) {
110 if (isset($a['default'])) {
111 // Merge defaults in when not present.
112 if (\is_callable($a['default']) && (\is_array($a['default']) || $a['default'] instanceof \Closure)) {
113 $args[$key] = $a['default']($args);
114 } else {
115 $args[$key] = $a['default'];
116 }
117 } elseif (empty($a['required'])) {
118 continue;
119 } else {
120 $this->throwRequired($args);
121 }
122 }
123 // Validate the types against the provided value.
124 foreach ($a['valid'] as $check) {
125 if (isset(self::$typeMap[$check])) {
126 $fn = self::$typeMap[$check];
127 if ($fn($args[$key])) {
128 goto is_valid;
129 }
130 } elseif ($args[$key] instanceof $check) {
131 goto is_valid;
132 }
133 }
134 $this->invalidType($key, $args[$key]);
135 // Apply the value
136 is_valid:
137 if (isset($a['fn'])) {
138 $a['fn']($args[$key], $args, $list);
139 }
140 if ($a['type'] === 'config') {
141 $args['config'][$key] = $args[$key];
142 }
143 }
144 $this->_apply_client_context_params($args);
145 return $args;
146 }
147 /**
148 * Creates a verbose error message for an invalid argument.
149 *
150 * @param string $name Name of the argument that is missing.
151 * @param array $args Provided arguments
152 * @param bool $useRequired Set to true to show the required fn text if
153 * available instead of the documentation.
154 * @return string
155 */
156 private function getArgMessage($name, $args = [], $useRequired = \false)
157 {
158 $arg = $this->argDefinitions[$name];
159 $msg = '';
160 $modifiers = [];
161 if (isset($arg['valid'])) {
162 $modifiers[] = \implode('|', $arg['valid']);
163 }
164 if (isset($arg['choice'])) {
165 $modifiers[] = 'One of ' . \implode(', ', $arg['choice']);
166 }
167 if ($modifiers) {
168 $msg .= '(' . \implode('; ', $modifiers) . ')';
169 }
170 $msg = \wordwrap("{$name}: {$msg}", 75, "\n ");
171 if ($useRequired && \is_callable($arg['required'])) {
172 $msg .= "\n\n ";
173 $msg .= \str_replace("\n", "\n ", \call_user_func($arg['required'], $args));
174 } elseif (isset($arg['doc'])) {
175 $msg .= \wordwrap("\n\n {$arg['doc']}", 75, "\n ");
176 }
177 return $msg;
178 }
179 /**
180 * Throw when an invalid type is encountered.
181 *
182 * @param string $name Name of the value being validated.
183 * @param mixed $provided The provided value.
184 * @throws \InvalidArgumentException
185 */
186 private function invalidType($name, $provided)
187 {
188 $expected = \implode('|', $this->argDefinitions[$name]['valid']);
189 $msg = "Invalid configuration value " . "provided for \"{$name}\". Expected {$expected}, but got " . describe_type($provided) . "\n\n" . $this->getArgMessage($name);
190 throw new IAE($msg);
191 }
192 /**
193 * Throws an exception for missing required arguments.
194 *
195 * @param array $args Passed in arguments.
196 * @throws \InvalidArgumentException
197 */
198 private function throwRequired(array $args)
199 {
200 $missing = [];
201 foreach ($this->argDefinitions as $k => $a) {
202 if (empty($a['required']) || isset($a['default']) || isset($args[$k])) {
203 continue;
204 }
205 $missing[] = $this->getArgMessage($k, $args, \true);
206 }
207 $msg = "Missing required client configuration options: \n\n";
208 $msg .= \implode("\n\n", $missing);
209 throw new IAE($msg);
210 }
211 public static function _apply_retries($value, array &$args, HandlerList $list)
212 {
213 // A value of 0 for the config option disables retries
214 if ($value) {
215 $config = RetryConfigProvider::unwrap($value);
216 if ($config->getMode() === 'legacy') {
217 // # of retries is 1 less than # of attempts
218 $decider = RetryMiddleware::createDefaultDecider($config->getMaxAttempts() - 1);
219 $list->appendSign(Middleware::retry($decider, null, $args['stats']['retries']), 'retry');
220 } else {
221 $list->appendSign(RetryMiddlewareV2::wrap($config, ['collect_stats' => $args['stats']['retries']]), 'retry');
222 }
223 }
224 }
225 public static function _apply_defaults($value, array &$args, HandlerList $list)
226 {
227 $config = ConfigModeProvider::unwrap($value);
228 if ($config->getMode() !== 'legacy') {
229 if (!isset($args['retries']) && !\is_null($config->getRetryMode())) {
230 $args['retries'] = ['mode' => $config->getRetryMode()];
231 }
232 if (!isset($args['sts_regional_endpoints']) && !\is_null($config->getStsRegionalEndpoints())) {
233 $args['sts_regional_endpoints'] = ['mode' => $config->getStsRegionalEndpoints()];
234 }
235 if (!isset($args['s3_us_east_1_regional_endpoint']) && !\is_null($config->getS3UsEast1RegionalEndpoints())) {
236 $args['s3_us_east_1_regional_endpoint'] = ['mode' => $config->getS3UsEast1RegionalEndpoints()];
237 }
238 if (!isset($args['http'])) {
239 $args['http'] = [];
240 }
241 if (!isset($args['http']['connect_timeout']) && !\is_null($config->getConnectTimeoutInMillis())) {
242 $args['http']['connect_timeout'] = $config->getConnectTimeoutInMillis() / 1000;
243 }
244 if (!isset($args['http']['timeout']) && !\is_null($config->getHttpRequestTimeoutInMillis())) {
245 $args['http']['timeout'] = $config->getHttpRequestTimeoutInMillis() / 1000;
246 }
247 }
248 }
249 public static function _apply_disable_request_compression($value, array &$args)
250 {
251 if (\is_callable($value)) {
252 $value = $value();
253 }
254 if (!\is_bool($value)) {
255 throw new IAE("Invalid configuration value provided for 'disable_request_compression'." . " value must be a bool.");
256 }
257 $args['config']['disable_request_compression'] = $value;
258 }
259 public static function _default_disable_request_compression(array &$args)
260 {
261 return ConfigurationResolver::resolve('disable_request_compression', \false, 'bool', $args);
262 }
263 public static function _apply_min_compression_size($value, array &$args)
264 {
265 if (\is_callable($value)) {
266 $value = $value();
267 }
268 if (!\is_int($value) || \is_int($value) && ($value < 0 || $value > 10485760)) {
269 throw new IAE(" Invalid configuration value provided for 'min_compression_size_bytes'." . " value must be an integer between 0 and 10485760, inclusive.");
270 }
271 $args['config']['request_min_compression_size_bytes'] = $value;
272 }
273 public static function _default_min_compression_size(array &$args)
274 {
275 return ConfigurationResolver::resolve('request_min_compression_size_bytes', 10240, 'int', $args);
276 }
277 public static function _apply_credentials($value, array &$args)
278 {
279 if (\is_callable($value)) {
280 return;
281 }
282 if ($value instanceof CredentialsInterface) {
283 $args['credentials'] = CredentialProvider::fromCredentials($value);
284 } elseif (\is_array($value) && isset($value['key']) && isset($value['secret'])) {
285 $args['credentials'] = CredentialProvider::fromCredentials(new Credentials($value['key'], $value['secret'], $value['token'] ?? null, $value['expires'] ?? null, $value['accountId'] ?? null));
286 } elseif ($value === \false) {
287 $args['credentials'] = CredentialProvider::fromCredentials(new Credentials('', ''));
288 $args['config']['signature_version'] = 'anonymous';
289 $args['config']['configured_signature_version'] = \true;
290 } elseif ($value instanceof CacheInterface) {
291 $args['credentials'] = CredentialProvider::defaultProvider($args);
292 } else {
293 throw new IAE('Credentials must be an instance of ' . "'" . CredentialsInterface::class . ', an associative ' . 'array that contains "key", "secret", and an optional "token" ' . 'key-value pairs, a credentials provider function, or false.');
294 }
295 }
296 public static function _default_credential_provider(array $args)
297 {
298 return CredentialProvider::defaultProvider($args);
299 }
300 public static function _apply_token($value, array &$args)
301 {
302 if (\is_callable($value)) {
303 return;
304 }
305 if ($value instanceof Token) {
306 $args['token'] = TokenProvider::fromToken($value);
307 } elseif (\is_array($value) && isset($value['token'])) {
308 $args['token'] = TokenProvider::fromToken(new Token($value['token'], $value['expires'] ?? null));
309 } elseif ($value instanceof CacheInterface) {
310 $args['token'] = TokenProvider::defaultProvider($args);
311 } else {
312 throw new IAE('Token must be an instance of ' . TokenInterface::class . ', an associative ' . 'array that contains "token" and an optional "expires" ' . 'key-value pairs, a token provider function, or false.');
313 }
314 }
315 public static function _default_token_provider(array $args)
316 {
317 return TokenProvider::defaultProvider($args);
318 }
319 public static function _apply_csm($value, array &$args, HandlerList $list)
320 {
321 if ($value === \false) {
322 $value = new Configuration(\false, \Dudlewebs\WPMCS\s3\Aws\ClientSideMonitoring\ConfigurationProvider::DEFAULT_HOST, \Dudlewebs\WPMCS\s3\Aws\ClientSideMonitoring\ConfigurationProvider::DEFAULT_PORT, \Dudlewebs\WPMCS\s3\Aws\ClientSideMonitoring\ConfigurationProvider::DEFAULT_CLIENT_ID);
323 $args['csm'] = $value;
324 }
325 $list->appendBuild(ApiCallMonitoringMiddleware::wrap($args['credentials'], $value, $args['region'], $args['api']->getServiceId()), 'ApiCallMonitoringMiddleware');
326 $list->appendAttempt(ApiCallAttemptMonitoringMiddleware::wrap($args['credentials'], $value, $args['region'], $args['api']->getServiceId()), 'ApiCallAttemptMonitoringMiddleware');
327 }
328 public static function _apply_api_provider(callable $value, array &$args)
329 {
330 $api = new Service(ApiProvider::resolve($value, 'api', $args['service'], $args['version']), $value);
331 if (empty($args['config']['signing_name']) && isset($api['metadata']['signingName'])) {
332 $args['config']['signing_name'] = $api['metadata']['signingName'];
333 }
334 $args['api'] = $api;
335 $args['parser'] = Service::createParser($api);
336 $args['error_parser'] = Service::createErrorParser($api->getProtocol(), $api);
337 }
338 public static function _apply_endpoint_provider($value, array &$args)
339 {
340 if (!isset($args['endpoint'])) {
341 if ($value instanceof \Dudlewebs\WPMCS\s3\Aws\EndpointV2\EndpointProviderV2) {
342 $options = self::getEndpointProviderOptions($args);
343 $value = PartitionEndpointProvider::defaultProvider($options)->getPartition($args['region'], $args['service']);
344 }
345 $endpointPrefix = $args['api']['metadata']['endpointPrefix'] ?? $args['service'];
346 // Check region is a valid host label when it is being used to
347 // generate an endpoint
348 if (!self::isValidRegion($args['region'])) {
349 throw new InvalidRegionException('Region must be a valid RFC' . ' host label.');
350 }
351 $serviceEndpoints = \is_array($value) && isset($value['services'][$args['service']]['endpoints']) ? $value['services'][$args['service']]['endpoints'] : null;
352 if (isset($serviceEndpoints[$args['region']]['deprecated'])) {
353 \trigger_error("The service " . $args['service'] . "has " . " deprecated the region " . $args['region'] . ".", \E_USER_WARNING);
354 }
355 $args['region'] = \Dudlewebs\WPMCS\s3\Aws\strip_fips_pseudo_regions($args['region']);
356 // Invoke the endpoint provider and throw if it does not resolve.
357 $result = EndpointProvider::resolve($value, ['service' => $endpointPrefix, 'region' => $args['region'], 'scheme' => $args['scheme'], 'options' => self::getEndpointProviderOptions($args)]);
358 $args['endpoint'] = $result['endpoint'];
359 if (empty($args['config']['signature_version'])) {
360 if (isset($args['api']) && $args['api']->getSignatureVersion() == 'bearer') {
361 $args['config']['signature_version'] = 'bearer';
362 } elseif (isset($result['signatureVersion'])) {
363 $args['config']['signature_version'] = $result['signatureVersion'];
364 }
365 }
366 if (empty($args['config']['signing_region']) && isset($result['signingRegion'])) {
367 $args['config']['signing_region'] = $result['signingRegion'];
368 }
369 if (empty($args['config']['signing_name']) && isset($result['signingName'])) {
370 $args['config']['signing_name'] = $result['signingName'];
371 }
372 }
373 }
374 public static function _apply_endpoint_discovery($value, array &$args)
375 {
376 $args['endpoint_discovery'] = $value;
377 }
378 public static function _default_endpoint_discovery_provider(array $args)
379 {
380 return ConfigurationProvider::defaultProvider($args);
381 }
382 public static function _apply_use_fips_endpoint($value, array &$args)
383 {
384 if ($value instanceof CacheInterface) {
385 $value = UseFipsConfigProvider::defaultProvider($args);
386 }
387 if (\is_callable($value)) {
388 $value = $value();
389 }
390 if ($value instanceof PromiseInterface) {
391 $value = $value->wait();
392 }
393 if ($value instanceof UseFipsEndpointConfigurationInterface) {
394 $args['config']['use_fips_endpoint'] = $value;
395 } else {
396 // The Configuration class itself will validate other inputs
397 $args['config']['use_fips_endpoint'] = new UseFipsEndpointConfiguration($value);
398 }
399 }
400 public static function _default_use_fips_endpoint(array &$args)
401 {
402 return UseFipsConfigProvider::defaultProvider($args);
403 }
404 public static function _apply_use_dual_stack_endpoint($value, array &$args)
405 {
406 if ($value instanceof CacheInterface) {
407 $value = UseDualStackConfigProvider::defaultProvider($args);
408 }
409 if (\is_callable($value)) {
410 $value = $value();
411 }
412 if ($value instanceof PromiseInterface) {
413 $value = $value->wait();
414 }
415 if ($value instanceof UseDualStackEndpointConfigurationInterface) {
416 $args['config']['use_dual_stack_endpoint'] = $value;
417 } else {
418 // The Configuration class itself will validate other inputs
419 $args['config']['use_dual_stack_endpoint'] = new UseDualStackEndpointConfiguration($value, $args['region']);
420 }
421 }
422 public static function _default_use_dual_stack_endpoint(array &$args)
423 {
424 return UseDualStackConfigProvider::defaultProvider($args);
425 }
426 public static function _apply_serializer($value, array &$args, HandlerList $list)
427 {
428 $list->prependBuild(Middleware::requestBuilder($value), 'builder');
429 }
430 public static function _apply_debug($value, array &$args, HandlerList $list)
431 {
432 if ($value !== \false) {
433 $list->interpose(new TraceMiddleware($value === \true ? [] : $value, $args['api']));
434 }
435 }
436 public static function _apply_stats($value, array &$args, HandlerList $list)
437 {
438 // Create an array of stat collectors that are disabled (set to false)
439 // by default. If the user has passed in true, enable all stat
440 // collectors.
441 $defaults = \array_fill_keys(['http', 'retries', 'timer'], $value === \true);
442 $args['stats'] = \is_array($value) ? \array_replace($defaults, $value) : $defaults;
443 if ($args['stats']['timer']) {
444 $list->prependInit(Middleware::timer(), 'timer');
445 }
446 }
447 public static function _apply_profile($_, array &$args)
448 {
449 $args['credentials'] = CredentialProvider::ini($args['profile']);
450 }
451 public static function _apply_validate($value, array &$args, HandlerList $list)
452 {
453 if ($value === \false) {
454 return;
455 }
456 $validator = $value === \true ? new Validator() : new Validator($value);
457 $list->appendValidate(Middleware::validation($args['api'], $validator), 'validation');
458 }
459 public static function _apply_handler($value, array &$args, HandlerList $list)
460 {
461 $list->setHandler($value);
462 }
463 public static function _default_handler(array &$args)
464 {
465 return new WrappedHttpHandler(default_http_handler(), $args['parser'], $args['error_parser'], $args['exception_class'], $args['stats']['http']);
466 }
467 public static function _apply_http_handler($value, array &$args, HandlerList $list)
468 {
469 $args['handler'] = new WrappedHttpHandler($value, $args['parser'], $args['error_parser'], $args['exception_class'], $args['stats']['http']);
470 }
471 public static function _apply_app_id($value, array &$args)
472 {
473 // AppId should not be longer than 50 chars
474 static $MAX_APP_ID_LENGTH = 50;
475 if (\strlen($value) > $MAX_APP_ID_LENGTH) {
476 \trigger_error("The provided or configured value for `AppId`, " . "which is an user agent parameter, exceeds the maximum length of " . "{$MAX_APP_ID_LENGTH} characters.", \E_USER_WARNING);
477 }
478 $args['app_id'] = $value;
479 }
480 public static function _default_app_id(array $args)
481 {
482 return ConfigurationResolver::resolve('sdk_ua_app_id', '', 'string', $args);
483 }
484 public static function _apply_user_agent($inputUserAgent, array &$args, HandlerList $list)
485 {
486 // Add SDK version
487 $userAgent = ['aws-sdk-php/' . Sdk::VERSION];
488 // User Agent Metadata
489 $userAgent[] = 'ua/2.0';
490 // If on HHVM add the HHVM version
491 if (\defined('Dudlewebs\\WPMCS\\s3\\HHVM_VERSION')) {
492 $userAgent[] = 'HHVM/' . HHVM_VERSION;
493 }
494 // Add OS version
495 $disabledFunctions = \explode(',', \ini_get('disable_functions'));
496 if (\function_exists('php_uname') && !\in_array('php_uname', $disabledFunctions, \true)) {
497 $osName = "OS/" . \php_uname('s') . '#' . \php_uname('r');
498 if (!empty($osName)) {
499 $userAgent[] = $osName;
500 }
501 }
502 // Add the language version
503 $userAgent[] = 'lang/php#' . \phpversion();
504 // Add exec environment if present
505 if ($executionEnvironment = \getenv('AWS_EXECUTION_ENV')) {
506 $userAgent[] = $executionEnvironment;
507 }
508 // Add endpoint discovery if set
509 if (isset($args['endpoint_discovery'])) {
510 if ($args['endpoint_discovery'] instanceof \Dudlewebs\WPMCS\s3\Aws\EndpointDiscovery\Configuration && $args['endpoint_discovery']->isEnabled()) {
511 $userAgent[] = 'cfg/endpoint-discovery';
512 } elseif (\is_array($args['endpoint_discovery']) && isset($args['endpoint_discovery']['enabled']) && $args['endpoint_discovery']['enabled']) {
513 $userAgent[] = 'cfg/endpoint-discovery';
514 }
515 }
516 // Add retry mode if set
517 if (isset($args['retries'])) {
518 if ($args['retries'] instanceof \Dudlewebs\WPMCS\s3\Aws\Retry\Configuration) {
519 $userAgent[] = 'cfg/retry-mode#' . $args["retries"]->getMode();
520 } elseif (\is_array($args['retries']) && isset($args["retries"]["mode"])) {
521 $userAgent[] = 'cfg/retry-mode#' . $args["retries"]["mode"];
522 }
523 }
524 // AppID Metadata
525 if (!empty($args['app_id'])) {
526 $userAgent[] = 'app/' . $args['app_id'];
527 }
528 // Add the input to the end
529 if ($inputUserAgent) {
530 if (!\is_array($inputUserAgent)) {
531 $inputUserAgent = [$inputUserAgent];
532 }
533 $inputUserAgent = \array_map('strval', $inputUserAgent);
534 $userAgent = \array_merge($userAgent, $inputUserAgent);
535 }
536 $args['ua_append'] = $userAgent;
537 $list->appendBuild(static function (callable $handler) use($userAgent) {
538 return function (CommandInterface $command, RequestInterface $request) use($handler, $userAgent) {
539 return $handler($command, $request->withHeader('X-Amz-User-Agent', \implode(' ', \array_merge($userAgent, $request->getHeader('X-Amz-User-Agent'))))->withHeader('User-Agent', \implode(' ', \array_merge($userAgent, $request->getHeader('User-Agent')))));
540 };
541 });
542 }
543 public static function _apply_endpoint($value, array &$args, HandlerList $list)
544 {
545 if (empty($value)) {
546 unset($args['endpoint']);
547 return;
548 }
549 $args['endpoint'] = $value;
550 }
551 public static function _apply_idempotency_auto_fill($value, array &$args, HandlerList $list)
552 {
553 $enabled = \false;
554 $generator = null;
555 if (\is_bool($value)) {
556 $enabled = $value;
557 } elseif (\is_callable($value)) {
558 $enabled = \true;
559 $generator = $value;
560 }
561 if ($enabled) {
562 $list->prependInit(IdempotencyTokenMiddleware::wrap($args['api'], $generator), 'idempotency_auto_fill');
563 }
564 }
565 public static function _default_account_id_endpoint_mode($args)
566 {
567 return ConfigurationResolver::resolve('account_id_endpoint_mode', 'preferred', 'string', $args);
568 }
569 public static function _apply_account_id_endpoint_mode($value, array &$args)
570 {
571 static $accountIdEndpointModes = ['disabled', 'required', 'preferred'];
572 if (!\in_array($value, $accountIdEndpointModes)) {
573 throw new IAE("The value provided for the config account_id_endpoint_mode is invalid." . "Valid values are: " . \implode(", ", $accountIdEndpointModes));
574 }
575 $args['account_id_endpoint_mode'] = $value;
576 }
577 public static function _default_endpoint_provider(array $args)
578 {
579 $service = $args['api'] ?? null;
580 $serviceName = isset($service) ? $service->getServiceName() : null;
581 $apiVersion = isset($service) ? $service->getApiVersion() : null;
582 if (self::isValidService($serviceName) && self::isValidApiVersion($serviceName, $apiVersion)) {
583 $ruleset = EndpointDefinitionProvider::getEndpointRuleset($service->getServiceName(), $service->getApiVersion());
584 return new \Dudlewebs\WPMCS\s3\Aws\EndpointV2\EndpointProviderV2($ruleset, EndpointDefinitionProvider::getPartitions());
585 }
586 $options = self::getEndpointProviderOptions($args);
587 return PartitionEndpointProvider::defaultProvider($options)->getPartition($args['region'], $args['service']);
588 }
589 public static function _default_serializer(array $args)
590 {
591 return Service::createSerializer($args['api'], $args['endpoint']);
592 }
593 public static function _default_signature_provider()
594 {
595 return SignatureProvider::defaultProvider();
596 }
597 public static function _default_auth_scheme_resolver(array $args)
598 {
599 return new AuthSchemeResolver($args['credentials'], $args['token']);
600 }
601 public static function _default_signature_version(array &$args)
602 {
603 if (isset($args['config']['signature_version'])) {
604 return $args['config']['signature_version'];
605 }
606 $args['__partition_result'] = isset($args['__partition_result']) ? isset($args['__partition_result']) : \call_user_func(PartitionEndpointProvider::defaultProvider(), ['service' => $args['service'], 'region' => $args['region']]);
607 return isset($args['__partition_result']['signatureVersion']) ? $args['__partition_result']['signatureVersion'] : $args['api']->getSignatureVersion();
608 }
609 public static function _default_signing_name(array &$args)
610 {
611 if (isset($args['config']['signing_name'])) {
612 return $args['config']['signing_name'];
613 }
614 $args['__partition_result'] = isset($args['__partition_result']) ? isset($args['__partition_result']) : \call_user_func(PartitionEndpointProvider::defaultProvider(), ['service' => $args['service'], 'region' => $args['region']]);
615 if (isset($args['__partition_result']['signingName'])) {
616 return $args['__partition_result']['signingName'];
617 }
618 if ($signingName = $args['api']->getSigningName()) {
619 return $signingName;
620 }
621 return $args['service'];
622 }
623 public static function _default_signing_region(array &$args)
624 {
625 if (isset($args['config']['signing_region'])) {
626 return $args['config']['signing_region'];
627 }
628 $args['__partition_result'] = isset($args['__partition_result']) ? isset($args['__partition_result']) : \call_user_func(PartitionEndpointProvider::defaultProvider(), ['service' => $args['service'], 'region' => $args['region']]);
629 return $args['__partition_result']['signingRegion'] ?? $args['region'];
630 }
631 public static function _apply_ignore_configured_endpoint_urls($value, array &$args)
632 {
633 $args['config']['ignore_configured_endpoint_urls'] = $value;
634 }
635 public static function _default_ignore_configured_endpoint_urls(array &$args)
636 {
637 return ConfigurationResolver::resolve('ignore_configured_endpoint_urls', \false, 'bool', $args);
638 }
639 public static function _default_endpoint(array &$args)
640 {
641 if ($args['config']['ignore_configured_endpoint_urls'] || !self::isValidService($args['service'])) {
642 return '';
643 }
644 $serviceIdentifier = \Dudlewebs\WPMCS\s3\Aws\manifest($args['service'])['serviceIdentifier'];
645 $value = ConfigurationResolver::resolve('endpoint_url_' . $serviceIdentifier, '', 'string', $args + ['ini_resolver_options' => ['section' => 'services', 'subsection' => $serviceIdentifier, 'key' => 'endpoint_url']]);
646 if (empty($value)) {
647 $value = ConfigurationResolver::resolve('endpoint_url', '', 'string', $args);
648 }
649 if (!empty($value)) {
650 $args['config']['configured_endpoint_url'] = \true;
651 }
652 return $value;
653 }
654 public static function _apply_sigv4a_signing_region_set($value, array &$args)
655 {
656 if (empty($value)) {
657 $args['sigv4a_signing_region_set'] = null;
658 } elseif (\is_array($value)) {
659 $args['sigv4a_signing_region_set'] = \implode(', ', $value);
660 } else {
661 $args['sigv4a_signing_region_set'] = $value;
662 }
663 }
664 public static function _default_sigv4a_signing_region_set(array &$args)
665 {
666 return ConfigurationResolver::resolve('sigv4a_signing_region_set', '', 'string');
667 }
668 public static function _apply_region($value, array &$args)
669 {
670 if (empty($value)) {
671 self::_missing_region($args);
672 }
673 $args['region'] = $value;
674 }
675 public static function _default_region(&$args)
676 {
677 return ConfigurationResolver::resolve('region', '', 'string');
678 }
679 public static function _missing_region(array $args)
680 {
681 $service = $args['service'] ?? '';
682 $msg = <<<EOT
683 Missing required client configuration options:
684
685 region: (string)
686
687 A "region" configuration value is required for the "{$service}" service
688 (e.g., "us-west-2"). A list of available public regions and endpoints can be
689 found at http://docs.aws.amazon.com/general/latest/gr/rande.html.
690 EOT;
691 throw new IAE($msg);
692 }
693 /**
694 * Extracts client options for the endpoint provider to its own array
695 *
696 * @param array $args
697 * @return array
698 */
699 private static function getEndpointProviderOptions(array $args)
700 {
701 $options = [];
702 $optionKeys = ['sts_regional_endpoints', 's3_us_east_1_regional_endpoint'];
703 $configKeys = ['use_dual_stack_endpoint', 'use_fips_endpoint'];
704 foreach ($optionKeys as $key) {
705 if (isset($args[$key])) {
706 $options[$key] = $args[$key];
707 }
708 }
709 foreach ($configKeys as $key) {
710 if (isset($args['config'][$key])) {
711 $options[$key] = $args['config'][$key];
712 }
713 }
714 return $options;
715 }
716 /**
717 * Validates a region to be used for endpoint construction
718 *
719 * @param $region
720 * @return bool
721 */
722 private static function isValidRegion($region)
723 {
724 return is_valid_hostlabel($region);
725 }
726 private function _apply_client_context_params(array $args)
727 {
728 if (isset($args['api']) && !empty($args['api']->getClientContextParams())) {
729 $clientContextParams = $args['api']->getClientContextParams();
730 foreach ($clientContextParams as $paramName => $paramDefinition) {
731 $definition = ['type' => 'value', 'valid' => [$paramDefinition['type']], 'doc' => $paramDefinition['documentation'] ?? null];
732 $this->argDefinitions[$paramName] = $definition;
733 if (isset($args[$paramName])) {
734 $fn = self::$typeMap[$paramDefinition['type']];
735 if (!$fn($args[$paramName])) {
736 $this->invalidType($paramName, $args[$paramName]);
737 }
738 }
739 }
740 }
741 }
742 private static function isValidService($service)
743 {
744 if (\is_null($service)) {
745 return \false;
746 }
747 $services = \Dudlewebs\WPMCS\s3\Aws\manifest();
748 return isset($services[$service]);
749 }
750 private static function isValidApiVersion($service, $apiVersion)
751 {
752 if (\is_null($apiVersion)) {
753 return \false;
754 }
755 return \is_dir(__DIR__ . "/data/{$service}/{$apiVersion}");
756 }
757 }
758