/**
  * {@inheritdoc}
  */
 public function factory($name, array $args = array())
 {
     $args = array_merge($args, $this->module_invoke_all('amazons3_command_prepare', $name, $args));
     $this->drupal_alter('amazons3_command_prepare', $name, $args);
     $command = parent::factory($name, $args);
     $this->drupal_alter('amazons3_command', $command);
     return $command;
 }
Esempio n. 2
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
  * @see \Aws\Common\Client\DefaultClient for a list of available 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')));
     // Add aliases for some S3 operations
     $default = CompositeFactory::getDefaultChain($client);
     $default->add(new AliasFactory($client, self::$commandAliases), 'Guzzle\\Service\\Command\\Factory\\ServiceDescriptionFactory');
     $client->setCommandFactory($default);
     return $client;
 }
Esempio n. 3
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;
 }
 /**
  * @covers Guzzle\Service\Command\Factory\CompositeFactory::getDefaultChain
  */
 public function testProvidesDefaultChainForClients()
 {
     $client = $this->getMock('Guzzle\\Service\\Client');
     $chain = CompositeFactory::getDefaultChain($client);
     $a = $chain->getIterator()->getArrayCopy();
     $this->assertEquals(1, count($a));
     $this->assertInstanceOf('Guzzle\\Service\\Command\\Factory\\ConcreteClassFactory', $a[0]);
     $description = $this->getMock('Guzzle\\Service\\Description\\ServiceDescription');
     $client->expects($this->once())->method('getDescription')->will($this->returnValue($description));
     $chain = CompositeFactory::getDefaultChain($client);
     $a = $chain->getIterator()->getArrayCopy();
     $this->assertEquals(2, count($a));
     $this->assertInstanceOf('Guzzle\\Service\\Command\\Factory\\ServiceDescriptionFactory', $a[0]);
     $this->assertInstanceOf('Guzzle\\Service\\Command\\Factory\\ConcreteClassFactory', $a[1]);
 }