You are here

public static function S3Client::factory in AmazonS3 7.2

Same name in this branch
  1. 7.2 src/S3Client.php \Drupal\amazons3\S3Client::factory()
  2. 7.2 tests/Stub/S3Client.php \Drupal\amazons3Test\Stub\S3Client::factory()

Create a new S3Client using aws_key / aws_secret $conf variables.

Parameters

array|Collection $config: An array of configuration options to pass to \Aws\S3\S3Client::factory(). If 'credentials' are set they will be used instead of aws_key and aws_secret.

string $bucket: (optional) The bucket to associate this client with. If empty, the client will default to $config['region'], and then the us-east-1 region.

Return value

\Aws\S3\S3Client

5 calls to S3Client::factory()
amazons3_file_entity_upload_destination_uri_alter in ./amazons3.module
Implements hook_file_entity_upload_destination_uri_alter().
amazons3_file_stream_wrapper_uri_normalize_alter in ./amazons3.module
Implements hook_file_stream_wrapper_uri_normalize_alter().
amazons3_form_bucket_validate in ./amazons3.module
Element validate callback to validate a bucket name.
amazons3_requirements in ./amazons3.install
Implements hook_requirements().
S3Client::factory in tests/Stub/S3Client.php
Create a new S3Client using aws_key / aws_secret $conf variables.
1 method overrides S3Client::factory()
S3Client::factory in tests/Stub/S3Client.php
Create a new S3Client using aws_key / aws_secret $conf variables.

File

src/S3Client.php, line 73
A wrapper around S3Client::factory() using aws_key / aws_secret variables.

Class

S3Client
A wrapper around S3Client::factory() using aws_key / aws_secret variables.

Namespace

Drupal\amazons3

Code

public static function factory($config = array(), $bucket = NULL) {
  if (!isset($config['credentials'])) {
    $config['credentials'] = new Credentials(static::variable_get('amazons3_key'), static::variable_get('amazons3_secret'));
  }
  if (!isset($config['endpoint'])) {
    $endpoint = static::variable_get('amazons3_hostname');
    if (!empty($endpoint)) {
      $config['endpoint'] = $endpoint;
    }
  }
  $curl_defaults = array(
    CURLOPT_CONNECTTIMEOUT => 30,
  );
  if (!isset($config['curl.options'])) {
    $config['curl.options'] = array();
  }
  $config['curl.options'] += $curl_defaults;

  // Set the default client location to the associated bucket.
  if (!isset($config['region'])) {
    $region = static::variable_get('amazons3_region');
    if (!empty($region)) {
      $config['region'] = $region;
    }
  }
  $client = AwsS3Client::factory($config);
  static::setCommandFactory($client);
  return $client;
}