Beispiel #1
0
 /**
  * Factory method to create a new Amazon S3 client using an array of configuration options.
  *
  * @param array|Collection $config Client configuration data
  *
  * @return self
  * @link http://docs.aws.amazon.com/aws-sdk-php/guide/latest/configuration.html#client-configuration-options
  */
 public static function factory($config = array())
 {
     $exceptionParser = new S3ExceptionParser();
     // Configure the custom exponential backoff plugin for retrying S3 specific errors
     if (!isset($config[Options::BACKOFF])) {
         $config[Options::BACKOFF] = self::createBackoffPlugin($exceptionParser);
     }
     $config[Options::SIGNATURE] = $signature = self::createSignature($config);
     $client = ClientBuilder::factory(__NAMESPACE__)->setConfig($config)->setConfigDefaults(array(Options::VERSION => self::LATEST_API_VERSION, Options::SERVICE_DESCRIPTION => __DIR__ . '/Resources/s3-%s.php'))->setExceptionParser($exceptionParser)->setIteratorsConfig(array('more_key' => 'IsTruncated', 'operations' => array('ListBuckets', 'ListMultipartUploads' => array('limit_param' => 'MaxUploads', 'token_param' => array('KeyMarker', 'UploadIdMarker'), 'token_key' => array('NextKeyMarker', 'NextUploadIdMarker')), 'ListObjects' => array('limit_param' => 'MaxKeys', 'token_param' => 'Marker', 'token_key' => 'NextMarker'), 'ListObjectVersions' => array('limit_param' => 'MaxKeys', 'token_param' => array('KeyMarker', 'VersionIdMarker'), 'token_key' => array('nextKeyMarker', 'nextVersionIdMarker')), 'ListParts' => array('limit_param' => 'MaxParts', 'result_key' => 'Parts', 'token_param' => 'PartNumberMarker', 'token_key' => 'NextPartNumberMarker'))))->build();
     // Use virtual hosted buckets when possible
     $client->addSubscriber(new BucketStyleListener());
     // Ensure that ACP headers are applied when needed
     $client->addSubscriber(new AcpListener());
     // Validate and add required Content-MD5 hashes (e.g. DeleteObjects)
     $client->addSubscriber(new S3Md5Listener($signature));
     // Allow for specifying bodies with file paths and file handles
     $client->addSubscriber(new UploadBodyListener(array('PutObject', 'UploadPart')));
     // Ensures that if a SSE-CPK key is provided, the key and md5 are formatted correctly
     $client->addSubscriber(new SseCpkListener());
     // Add aliases for some S3 operations
     $default = CompositeFactory::getDefaultChain($client);
     $default->add(new AliasFactory($client, self::$commandAliases), 'Akeeba\\ARS\\Amazon\\Guzzle\\Service\\Command\\Factory\\ServiceDescriptionFactory');
     $client->setCommandFactory($default);
     return $client;
 }
Beispiel #2
0
 /**
  * Factory method to create a default client using an array of configuration options.
  *
  * The following array keys and values are available options:
  *
  * Credential options ((`key`, `secret`, and optional `token`) OR `credentials` is required):
  *
  * - key: AWS Access Key ID
  * - secret: AWS secret access key
  * - credentials: You can optionally provide a custom `Aws\Common\Credentials\CredentialsInterface` object
  * - token: Custom AWS security token to use with request authentication. Please note that not all services accept temporary credentials. See http://docs.aws.amazon.com/STS/latest/UsingSTS/UsingTokens.html
  * - token.ttd: UNIX timestamp for when the custom credentials expire
  * - credentials.cache.key: Optional custom cache key to use with the credentials
  * - credentials.client: Pass this option to specify a custom `Guzzle\Http\ClientInterface` to use if your credentials require a HTTP request (e.g. RefreshableInstanceProfileCredentials)
  *
  * Region and endpoint options (Some services do not require a region while others do. Check the service specific user guide documentation for details):
  *
  * - region: Region name (e.g. 'us-east-1', 'us-west-1', 'us-west-2', 'eu-west-1', etc...)
  * - scheme: URI Scheme of the base URL (e.g. 'https', 'http') used when base_url is not supplied
  * - base_url: Allows you to specify a custom endpoint instead of building one from the region and scheme
  *
  * Generic client options:
  *
  * - signature: Overrides the signature used by the client. Clients will always choose an appropriate default signature. However, it can be useful to override this with a custom setting. This can be set to "v4", "v3https", "v2" or an instance of Aws\Common\Signature\SignatureInterface.
  * - ssl.certificate_authority: Set to true to use the bundled CA cert or pass the full path to an SSL certificate bundle
  * - curl.options: Associative of CURLOPT_* cURL options to add to each request
  * - client.backoff.logger: `Guzzle\Log\LogAdapterInterface` object used to log backoff retries. Use 'debug' to emit PHP warnings when a retry is issued.
  * - client.backoff.logger.template: Optional template to use for exponential backoff log messages. See `Guzzle\Plugin\Backoff\BackoffLogger` for formatting information.
  *
  * @param array|Collection $config Client configuration data
  *
  * @return self
  */
 public static function factory($config = array())
 {
     return ClientBuilder::factory()->setConfig($config)->setConfigDefaults(array(Options::SCHEME => 'https'))->build();
 }