Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/S3/S3Transfer/Models/UploadDirectoryRequest.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 UploadDirectoryRequest extends AbstractTransferRequest
10 {
11 public static array $configKeys = [
12 'follow_symbolic_links' => 'bool',
13 'recursive' => 'bool',
14 's3_prefix' => 'string',
15 'filter' => 'callable',
16 's3_delimiter' => 'string',
17 'upload_object_request_modifier' => 'callable',
18 'failure_policy' => 'callable',
19 'max_concurrency' => 'int',
20 'max_depth' => 'int',
21 'track_progress' => 'bool',
22 ];
23 public const DEFAULT_MAX_CONCURRENCY = 100;
24
25 /** @var string */
26 private string $sourceDirectory;
27
28 /** @var string */
29 private string $targetBucket;
30
31 /** @var array */
32 private readonly array $uploadRequestArgs;
33
34 /**
35 * @param string $sourceDirectory The source directory to upload.
36 * @param string $targetBucket The name of the bucket to upload objects to.
37 * @param array $uploadRequestArgs The extract arguments to be passed in
38 * each upload request.
39 * @param array $config
40 * - follow_symbolic_links: (boolean, optional) Whether to follow symbolic links when
41 * traversing the file tree.
42 * - recursive: (boolean, optional) Whether to upload directories recursively.
43 * - s3_prefix: (string, optional) The S3 key prefix to use for each object.
44 * If not provided, files will be uploaded to the root of the bucket.
45 * - filter: (callable, optional) A callback to allow users to filter out unwanted files.
46 * It is invoked for each file. An example implementation is a predicate
47 * that takes a file and returns a boolean indicating whether this file
48 * should be uploaded.
49 * - s3_delimiter: The S3 delimiter. A delimiter causes a list operation
50 * to roll up all the keys that share a common prefix into a single summary list result.
51 * - upload_object_request_modifier: (callable, optional) A callback mechanism
52 * to allow customers to update individual putObjectRequest that the S3 Transfer Manager generates.
53 * - failure_policy: (callable, optional) The failure policy to handle failed requests.
54 * - max_concurrency: (int, optional) The max number of concurrent uploads.
55 * - max_depth: (int, optional) To indicate the maximum depth of the recursive
56 * file tree walk. By default, it will use the built-in default value which is -1.
57 * @param array $listeners Directory-level listeners that receive directory snapshots.
58 * @param AbstractTransferListener|null $progressTracker Directory-level progress tracker.
59 * @param array $singleObjectListeners Per-object listeners that receive single-object snapshots.
60 */
61 public function __construct(
62 string $sourceDirectory,
63 string $targetBucket,
64 array $uploadRequestArgs = [],
65 array $config = [],
66 array $listeners = [],
67 ?AbstractTransferListener $progressTracker = null,
68 array $singleObjectListeners = []
69 ) {
70 parent::__construct(
71 $listeners,
72 $progressTracker,
73 $config,
74 $singleObjectListeners
75 );
76 $this->sourceDirectory = $sourceDirectory;
77 if (ArnParser::isArn($targetBucket)) {
78 $targetBucket = ArnParser::parse($targetBucket)->getResource();
79 }
80 $this->targetBucket = $targetBucket;
81 $this->uploadRequestArgs = $uploadRequestArgs;
82 $this->config = $config;
83 }
84
85 /**
86 * @return string
87 */
88 public function getSourceDirectory(): string
89 {
90 return $this->sourceDirectory;
91 }
92
93 /**
94 * @return string
95 */
96 public function getTargetBucket(): string
97 {
98 return $this->targetBucket;
99 }
100
101 /**
102 * @return array
103 */
104 public function getUploadRequestArgs(): array
105 {
106 return $this->uploadRequestArgs;
107 }
108
109 /**
110 * Helper method to validate source directory
111 * @return void
112 */
113 public function validateSourceDirectory(): void
114 {
115 if (!is_dir($this->sourceDirectory)) {
116 throw new InvalidArgumentException(
117 "Please provide a valid directory path. "
118 . "Provided = " . $this->sourceDirectory
119 );
120 }
121 }
122 }