Example #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;
 }
Example #2
0
 /**
  * Get the command factory associated with the client
  *
  * @return CommandFactoryInterface
  */
 protected function getCommandFactory()
 {
     if (!$this->commandFactory) {
         $this->commandFactory = CompositeFactory::getDefaultChain($this);
     }
     return $this->commandFactory;
 }