lib/3rdParty/composer/aws/aws-sdk-php/src/S3/S3Transfer/Models/DownloadDirectoryRequest.php
raw symbols SCIP| 1 | <?php |
| 2 | |
| 3 | namespace Aws\S3\S3Transfer\Models; |
| 4 | |
| 5 | use Aws\Arn\ArnParser; |
| 6 | use Aws\S3\S3Transfer\Progress\AbstractTransferListener; |
| 7 | use InvalidArgumentException; |
| 8 | |
| 9 | final class DownloadDirectoryRequest extends AbstractTransferRequest |
| 10 | { |
| 11 | public static array $configKeys = [ |
| 12 | 's3_prefix' => 'string', |
| 13 | 'filter' => 'callable', |
| 14 | 'download_object_request_modifier' => 'callable', |
| 15 | 'failure_policy' => 'callable', |
| 16 | 'max_concurrency' => 'int', |
| 17 | 'track_progress' => 'bool', |
| 18 | 'target_part_size_bytes' => 'int', |
| 19 | 'list_objects_v2_args' => 'array', |
| 20 | 'fails_when_destination_exists' => 'bool', |
| 21 | ]; |
| 22 | public const DEFAULT_MAX_CONCURRENCY = 100; |
| 23 | |
| 24 | /** @var string */ |
| 25 | private string $sourceBucket; |
| 26 | |
| 27 | /** @var string */ |
| 28 | private string $destinationDirectory; |
| 29 | |
| 30 | /** @var array */ |
| 31 | private readonly array $downloadRequestArgs; |
| 32 | |
| 33 | /** |
| 34 | * @param string $sourceBucket The bucket from where the files are going to be |
| 35 | * downloaded from. |
| 36 | * @param string $destinationDirectory The destination path where the downloaded |
| 37 | * files will be placed in. |
| 38 | * @param array $downloadRequestArgs |
| 39 | * @param array $config The config options for this download directory operation. |
| 40 | * - s3_prefix: (string, optional) This parameter will be considered just if |
| 41 | * not provided as part of the list_objects_v2_args config option. |
| 42 | * - filter: (Closure, optional) A callable which will receive an object key as |
| 43 | * parameter and should return true or false in order to determine |
| 44 | * whether the object should be downloaded. |
| 45 | * - download_object_request_modifier: (Closure, optional) A function that will |
| 46 | * be invoked right before the download request is performed and that will |
| 47 | * receive as parameter the request arguments for each request. |
| 48 | * - failure_policy: (Closure, optional) A function that will be invoked |
| 49 | * on a download failure and that will receive as parameters: |
| 50 | * - $requestArgs: (array) The arguments for the request that originated |
| 51 | * the failure. |
| 52 | * - $downloadDirectoryRequestArgs: (array) The arguments for the download |
| 53 | * directory request. |
| 54 | * - $reason: (Throwable) The exception that originated the request failure. |
| 55 | * - $downloadDirectoryResponse: (DownloadDirectoryResult) The download response |
| 56 | * to that point in the upload process. |
| 57 | * - track_progress: (bool, optional) Overrides the config option set |
| 58 | * in the transfer manager instantiation to decide whether transfer |
| 59 | * progress should be tracked. |
| 60 | * - target_part_size_bytes: (int, optional) The part size in bytes |
| 61 | * to be used in a range multipart download. |
| 62 | * - fails_when_destination_exists: (bool) Whether to fail when a destination |
| 63 | * file exists. |
| 64 | * - max_concurrency: (int, optional) The max number of concurrent downloads. |
| 65 | * - list_objects_v2_args: (array, optional) The arguments to be included |
| 66 | * as part of the listObjectV2 request in order to fetch the objects to |
| 67 | * be downloaded. The most common arguments would be: |
| 68 | * - MaxKeys: (int) Sets the maximum number of keys returned in the response. |
| 69 | * - Prefix: (string) To limit the response to keys that begin with the |
| 70 | * specified prefix. |
| 71 | * @param AbstractTransferListener[] $listeners Directory-level listeners that receive directory snapshots. |
| 72 | * @param AbstractTransferListener|null $progressTracker Directory-level progress tracker. |
| 73 | * @param array $singleObjectListeners Per-object listeners that receive single-object snapshots. |
| 74 | */ |
| 75 | public function __construct( |
| 76 | string $sourceBucket, |
| 77 | string $destinationDirectory, |
| 78 | array $downloadRequestArgs = [], |
| 79 | array $config = [], |
| 80 | array $listeners = [], |
| 81 | ?AbstractTransferListener $progressTracker = null, |
| 82 | array $singleObjectListeners = [] |
| 83 | ) { |
| 84 | parent::__construct( |
| 85 | $listeners, |
| 86 | $progressTracker, |
| 87 | $config, |
| 88 | $singleObjectListeners |
| 89 | ); |
| 90 | if (ArnParser::isArn($sourceBucket)) { |
| 91 | $sourceBucket = ArnParser::parse($sourceBucket)->getResource(); |
| 92 | } |
| 93 | |
| 94 | $this->sourceBucket = $sourceBucket; |
| 95 | $this->destinationDirectory = $destinationDirectory; |
| 96 | $this->downloadRequestArgs = $downloadRequestArgs; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @return string |
| 101 | */ |
| 102 | public function getSourceBucket(): string |
| 103 | { |
| 104 | return $this->sourceBucket; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * @return string |
| 109 | */ |
| 110 | public function getDestinationDirectory(): string |
| 111 | { |
| 112 | return $this->destinationDirectory; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * @return array |
| 117 | */ |
| 118 | public function getDownloadRequestArgs(): array |
| 119 | { |
| 120 | return $this->downloadRequestArgs; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Helper method to validate the destination directory exists. |
| 125 | * |
| 126 | * @return void |
| 127 | */ |
| 128 | public function validateDestinationDirectory(): void |
| 129 | { |
| 130 | if (!file_exists($this->destinationDirectory)) { |
| 131 | mkdir($this->destinationDirectory, 0755, true); |
| 132 | } |
| 133 | |
| 134 | if (!is_dir($this->destinationDirectory)) { |
| 135 | throw new InvalidArgumentException( |
| 136 | "Destination directory `$this->destinationDirectory` is not a directory." |
| 137 | ); |
| 138 | } |
| 139 | } |
| 140 | } |