123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- <?php
- namespace Aws\S3Control;
- use Aws\AwsClient;
- use Aws\CacheInterface;
- use Aws\HandlerList;
- use Aws\S3\UseArnRegion\Configuration;
- use Aws\S3\UseArnRegion\ConfigurationInterface;
- use Aws\S3\UseArnRegion\ConfigurationProvider as UseArnRegionConfigurationProvider;
- use GuzzleHttp\Promise\PromiseInterface;
- class S3ControlClient extends AwsClient
- {
- public static function getArguments()
- {
- $args = parent::getArguments();
- return $args + [
- 'use_dual_stack_endpoint' => [
- 'type' => 'config',
- 'valid' => ['bool'],
- 'doc' => 'Set to true to send requests to an S3 Control Dual Stack'
- . ' endpoint by default, which enables IPv6 Protocol.'
- . ' Can be enabled or disabled on individual operations by setting'
- . ' \'@use_dual_stack_endpoint\' to true or false.',
- 'default' => false,
- ],
- 'use_arn_region' => [
- 'type' => 'config',
- 'valid' => [
- 'bool',
- Configuration::class,
- CacheInterface::class,
- 'callable'
- ],
- 'doc' => 'Set to true to allow passed in ARNs to override'
- . ' client region. Accepts...',
- 'fn' => [__CLASS__, '_apply_use_arn_region'],
- 'default' => [UseArnRegionConfigurationProvider::class, 'defaultProvider'],
- ],
- ];
- }
- public static function _apply_use_arn_region($value, array &$args, HandlerList $list)
- {
- if ($value instanceof CacheInterface) {
- $value = UseArnRegionConfigurationProvider::defaultProvider($args);
- }
- if (is_callable($value)) {
- $value = $value();
- }
- if ($value instanceof PromiseInterface) {
- $value = $value->wait();
- }
- if ($value instanceof ConfigurationInterface) {
- $args['use_arn_region'] = $value;
- } else {
-
- $args['use_arn_region'] = new Configuration($value);
- }
- }
-
- public function __construct(array $args)
- {
- parent::__construct($args);
- if ($this->isUseEndpointV2()) {
- $this->processEndpointV2Model();
- }
- $stack = $this->getHandlerList();
- $stack->appendBuild(
- EndpointArnMiddleware::wrap(
- $this->getApi(),
- $this->getRegion(),
- [
- 'use_arn_region' => $this->getConfig('use_arn_region'),
- 'dual_stack' =>
- $this->getConfig('use_dual_stack_endpoint')->isUseDualStackEndpoint(),
- 'endpoint' => isset($args['endpoint'])
- ? $args['endpoint']
- : null,
- 'use_fips_endpoint' => $this->getConfig('use_fips_endpoint'),
- ],
- $this->isUseEndpointV2()
- ),
- 's3control.endpoint_arn_middleware'
- );
- }
-
- private function processEndpointV2Model()
- {
- $definition = $this->getApi()->getDefinition();
- $this->removeHostPrefix($definition);
- $this->removeRequiredMember($definition);
- $this->getApi()->setDefinition($definition);
- }
- private function removeHostPrefix(&$definition)
- {
- foreach($definition['operations'] as &$operation) {
- if (isset($operation['endpoint']['hostPrefix'])
- && $operation['endpoint']['hostPrefix'] === '{AccountId}.'
- ) {
- $operation['endpoint']['hostPrefix'] = str_replace(
- '{AccountId}.',
- '',
- $operation['endpoint']['hostPrefix']
- );
- }
- }
- }
- private function removeRequiredMember(&$definition)
- {
- foreach($definition['shapes'] as &$shape) {
- if (isset($shape['required'])
- ) {
- $found = array_search('AccountId', $shape['required']);
- if ($found !== false) {
- unset($shape['required'][$found]);
- }
- }
- }
- }
- }
|