Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/S3/S3Transfer/Models/UploadRequest.php

raw symbols SCIP
1 <?php
2
3 namespace Aws\S3\S3Transfer\Models;
4
5 use Aws\S3\S3Transfer\Progress\AbstractTransferListener;
6 use InvalidArgumentException;
7 use Psr\Http\Message\StreamInterface;
8
9 final class UploadRequest extends AbstractTransferRequest
10 {
11 public static array $configKeys = [
12 'multipart_upload_threshold_bytes' => 'int',
13 'target_part_size_bytes' => 'int',
14 'track_progress' => 'bool',
15 'concurrency' => 'int',
16 'request_checksum_calculation' => 'string',
17 'resume_enabled' => 'bool',
18 'resume_file_path' => 'string',
19 ];
20
21 /** @var StreamInterface|string */
22 private StreamInterface|string $source;
23
24 /** @var array */
25 private array $uploadRequestArgs;
26
27 /**
28 * @param string|StreamInterface $source
29 * @param array $uploadRequestArgs The putObject request arguments.
30 * Required parameters would be:
31 * - Bucket: (string, required)
32 * - Key: (string, required)
33 * @param array $config The config options for this upload operation.
34 * - multipart_upload_threshold_bytes: (int, optional)
35 * To override the default threshold for when to use multipart upload.
36 * - target_part_size_bytes: (int, optional) To override the default
37 * target part size in bytes.
38 * - track_progress: (bool, optional) To override the default option for
39 * enabling progress tracking. If this option is resolved as true and
40 * a progressTracker parameter is not provided then, a default implementation
41 * will be resolved. This option is intended to make the operation to use
42 * a default progress tracker implementation when $progressTracker is null.
43 * - concurrency: (int, optional) To override default value for concurrency.
44 * - request_checksum_calculation: (string, optional, defaulted to `when_supported`)
45 * - resume_enabled: (bool): To enable resuming a multipart download when a
46 * failure occurs.
47 * - resume_file_path (string, optional): To override the default resume file
48 * location to be generated. If specified the file name must end in `.resume`
49 * otherwise it will be added automatically.
50 * @param AbstractTransferListener[]|null $listeners
51 * @param AbstractTransferListener|null $progressTracker
52 *
53 */
54 public function __construct(
55 StreamInterface|string $source,
56 array $uploadRequestArgs,
57 array $config = [],
58 array $listeners = [],
59 ?AbstractTransferListener $progressTracker = null
60 ) {
61 parent::__construct($listeners, $progressTracker, $config);
62 $this->source = $source;
63 $this->uploadRequestArgs = $uploadRequestArgs;
64 }
65
66 /**
67 * Get the source.
68 *
69 * @return StreamInterface|string
70 */
71 public function getSource(): StreamInterface|string
72 {
73 return $this->source;
74 }
75
76 /**
77 * Get the put object request.
78 *
79 * @return array
80 */
81 public function getUploadRequestArgs(): array
82 {
83 return $this->uploadRequestArgs;
84 }
85
86 /**
87 * Helper method for validating the given source.
88 *
89 * @return void
90 */
91 public function validateSource(): void
92 {
93 if (is_string($this->getSource()) && !is_readable($this->getSource())) {
94 throw new InvalidArgumentException(
95 "Invalid source `". $this->getSource() . "` provided. \n".
96 "Please provide a valid readable file path or a valid stream as source."
97 );
98 }
99 }
100
101 /**
102 * Helper method for validating required parameters.
103 *
104 * @param string|null $customMessage
105 * @return void
106 */
107 public function validateRequiredParameters(
108 ?string $customMessage = null
109 ): void
110 {
111 $requiredParametersWithArgs = [
112 'Bucket' => $this->uploadRequestArgs['Bucket'] ?? null,
113 'Key' => $this->uploadRequestArgs['Key'] ?? null,
114 ];
115 foreach ($requiredParametersWithArgs as $key => $value) {
116 if (empty($value)) {
117 if ($customMessage !== null) {
118 throw new InvalidArgumentException($customMessage);
119 }
120
121 // Fallback to default error message
122 throw new InvalidArgumentException(
123 "The `$key` parameter must be provided as part of the request arguments."
124 );
125 }
126 }
127 }
128 }