Example #1
0
 /**
  * Perform the configured copy asynchronously. Returns a promise that is
  * fulfilled with the result of the CompleteMultipartUpload or CopyObject
  * operation or rejected with an exception.
  *
  * @return \GuzzleHttp\Promise\Promise
  */
 public function promise()
 {
     return \GuzzleHttp\Promise\coroutine(function () {
         $objectStats = (yield $this->client->executeAsync($this->client->getCommand('HeadObject', $this->source)));
         if ($objectStats['ContentLength'] > $this->options['mup_threshold']) {
             $mup = new MultipartCopy($this->client, $this->getSourcePath(), ['source_metadata' => $objectStats, 'acl' => $this->acl] + $this->destination + $this->options);
             (yield $mup->promise());
         } else {
             $defaults = ['ACL' => $this->acl, 'MetadataDirective' => 'COPY', 'CopySource' => $this->getSourcePath()];
             $params = array_diff_key($this->options, self::$defaults) + $this->destination + $defaults + $this->options['params'];
             (yield $this->client->executeAsync($this->client->getCommand('CopyObject', $params)));
         }
     });
 }
 public function callAsync($name, array $arguments, array $options = null, $inputHeaders = null, array &$outputHeaders = null)
 {
     return \GuzzleHttp\Promise\coroutine(function () use($name, $arguments, $options, $inputHeaders, &$outputHeaders) {
         /** @var HttpBinding $httpBinding */
         $httpBinding = (yield $this->deferredHttpBinding);
         $request = $httpBinding->request($name, $arguments, $options, $inputHeaders);
         try {
             $requestOptions = isset($options['request_options']) ? $options['request_options'] : [];
             $response = (yield $this->client->sendAsync($request, $requestOptions));
             (yield $this->parseResponse($httpBinding, $response, $name, $outputHeaders));
         } catch (RequestException $exception) {
             if ($exception->hasResponse()) {
                 $response = $exception->getResponse();
                 (yield $this->parseResponse($httpBinding, $response, $name, $outputHeaders));
             } else {
                 throw $exception;
             }
         } finally {
             $request->getBody()->close();
         }
     });
 }
 /**
  * Creates a BatchDelete object from an iterator that yields results.
  *
  * @param AwsClientInterface $client  AWS Client to use to execute commands
  * @param string             $bucket  Bucket where the objects are stored
  * @param \Iterator          $iter    Iterator that yields assoc arrays
  * @param array              $options BatchDelete options
  *
  * @return BatchDelete
  */
 public static function fromIterator(AwsClientInterface $client, $bucket, \Iterator $iter, array $options = [])
 {
     $fn = function (BatchDelete $that) use($iter) {
         return \GuzzleHttp\Promise\coroutine(function () use($that, $iter) {
             foreach ($iter as $obj) {
                 if ($promise = $that->enqueue($obj)) {
                     (yield $promise);
                 }
             }
         });
     };
     return new self($client, $bucket, $fn, $options);
 }