You are here

public static function S3::mergeClientConfiguration in Flysystem - S3 8

Same name and namespace in other branches
  1. 2.0.x src/Flysystem/S3.php \Drupal\flysystem_s3\Flysystem\S3::mergeClientConfiguration()

Returns an S3 client configuration based on a Flysystem configuration.

Parameters

\Symfony\Component\DependencyInjection\ContainerInterface $container: The container to pull out services used in the plugin.

array $configuration: A configuration array containing information about the plugin instance.

Return value

array The client configuration.

2 calls to S3::mergeClientConfiguration()
S3::create in src/Flysystem/S3.php
Creates an instance of the plugin.
S3Test::testMergeConfiguration in tests/src/Unit/Flysystem/S3Test.php
Tests merging defaults into configuration arrays.

File

src/Flysystem/S3.php, line 115

Class

S3
Drupal plugin for the "S3" Flysystem adapter.

Namespace

Drupal\flysystem_s3\Flysystem

Code

public static function mergeClientConfiguration(ContainerInterface $container, array $configuration) {
  $client_config = [
    'version' => 'latest',
    'region' => $configuration['region'],
    'endpoint' => $configuration['endpoint'],
  ];

  // Add config for S3Client if the exists.
  if (isset($configuration['bucket_endpoint'])) {
    $client_config['bucket_endpoint'] = $configuration['bucket_endpoint'];
  }
  if (isset($configuration['use_accelerate_endpoint'])) {
    $client_config['use_accelerate_endpoint'] = $configuration['use_accelerate_endpoint'];
  }
  if (isset($configuration['use_dual_stack_endpoint'])) {
    $client_config['use_dual_stack_endpoint'] = $configuration['use_dual_stack_endpoint'];
  }
  if (isset($configuration['use_path_style_endpoint'])) {
    $client_config['use_path_style_endpoint'] = $configuration['use_path_style_endpoint'];
  }

  // Allow authentication with standard secret/key or IAM roles.
  if (isset($configuration['key']) && isset($configuration['secret'])) {
    $client_config['credentials'] = new Credentials($configuration['key'], $configuration['secret']);
    return $client_config;
  }
  $client_config['credentials.cache'] = new AwsCacheAdapter($container
    ->get('cache.default'), 'flysystem_s3:');
  return $client_config;
}