Пример #1
0
 /**
  * When providing the $source argument, you may provide a string referencing
  * the path to a directory on disk to upload, an s3 scheme URI that contains
  * the bucket and key (e.g., "s3://bucket/key"), or an \Iterator object
  * that yields strings containing filenames that are the path to a file on
  * disk or an s3 scheme URI. The "/key" portion of an s3 URI is optional.
  *
  * When providing an iterator for the $source argument, you must also
  * provide a 'base_dir' key value pair in the $options argument.
  *
  * The $dest argument can be the path to a directory on disk or an s3
  * scheme URI (e.g., "s3://bucket/key").
  *
  * The options array can contain the following key value pairs:
  *
  * - base_dir: The directory to remove from the filename when saving.
  * - before: A callable that accepts the following positional arguments:
  *   source, dest, command; where command is an instance of a Command
  *   object. The provided command will be either a GetObject, PutObject,
  *   InitiateMultipartUpload, or UploadPart command.
  * - mup_threshold: Size in bytes in which a multipart upload should be
  *   used instead of PutObject. Defaults to 20971520 (20 MB).
  * - concurrency: Number of files to upload concurrently. Defaults to 5.
  * - debug: Set to true to print out debug information for transfers. Set
  *   to an fopen() resource to write to a specific stream.
  *
  * @param S3Client         $client  Client used for transfers.
  * @param string|\Iterator $source  Where the files are transferred from.
  * @param string           $dest    Where the files are transferred to.
  * @param array            $options Hash of options.
  */
 public function __construct(S3Client $client, $source, $dest, array $options = [])
 {
     $client->registerStreamWrapper();
     if (is_string($source)) {
         $this->base_dir = $source;
         $source = Utils::recursiveDirIterator($source);
     } elseif (!$source instanceof \Iterator) {
         throw new \InvalidArgumentException('source must be the path to a ' . 'directory or an iterator that yields file names.');
     } elseif (!$this->base_dir) {
         throw new \InvalidArgumentException('You must provide the source ' . 'argument as a string or provide the "base_dir" option.');
     }
     $valid = ['mup_threshold', 'base_dir', 'before', 'concurrency', 'debug'];
     foreach ($valid as $opt) {
         if (isset($options[$opt])) {
             $this->{$opt} = $options[$opt];
         }
     }
     if ($this->mup_threshold < 5248000) {
         throw new \InvalidArgumentException('mup_threshold must be >= 5248000');
     }
     // Normalize the destination and source directory.
     $this->dest = rtrim(str_replace('\\', '/', $dest), '/');
     $this->base_dir = rtrim(str_replace('\\', '/', $this->base_dir), '/');
     $this->destScheme = $this->getScheme($this->dest);
     $this->sourceScheme = $this->getScheme($this->base_dir);
     $this->client = $client;
     if ($this->destScheme == 's3') {
         $this->s3Args = $this->getS3Args($this->dest);
     }
     if ($this->debug) {
         $this->wrapDebug();
     }
     $this->source = $this->wrapIterator($source);
 }
Пример #2
0
 /**
  * Create a default credential provider that first checks for environment
  * variables, then checks for the "default" profile in ~/.aws/credentials,
  * and finally checks for credentials using EC2 instance profile
  * credentials.
  *
  * @param array $config Optional array of instance profile credentials
  *                      provider options.
  * @return callable
  */
 public static function defaultProvider(array $config = [])
 {
     return Utils::orFn(self::env(), self::ini(), self::instanceProfile($config));
 }