| 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 |
|
| 22 |
private StreamInterface|string $source; |
| 23 |
|
| 24 |
|
| 25 |
private array $uploadRequestArgs; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 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 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public function getSource(): StreamInterface|string |
| 72 |
{ |
| 73 |
return $this->source; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public function getUploadRequestArgs(): array |
| 82 |
{ |
| 83 |
return $this->uploadRequestArgs; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 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 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 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 |
|
| 122 |
throw new InvalidArgumentException( |
| 123 |
"The `$key` parameter must be provided as part of the request arguments." |
| 124 |
); |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
} |