← All changes
|
includes/sdk/s3/Aws/Multipart/AbstractUploadManager.php
+10
-7
1.0.3
→
1.4.2
View file →
| @@ -21,9 +21,9 @@ | ||
| 21 | 21 | abstract class AbstractUploadManager implements Promise\PromisorInterface |
| 22 | 22 | { |
| 23 | 23 | const DEFAULT_CONCURRENCY = 5; |
| 24 | 24 | /** @var array Default values for base multipart configuration */ |
| 25 | - private static $defaultConfig = ['part_size' => null, 'state' => null, 'concurrency' => self::DEFAULT_CONCURRENCY, 'prepare_data_source' => null, 'before_initiate' => null, 'before_upload' => null, 'before_complete' => null, 'exception_class' => 'Dudlewebs\\WPMCS\\s3\\Aws\\Exception\\MultipartUploadException']; | |
| 25 | + private static $defaultConfig = ['part_size' => null, 'state' => null, 'concurrency' => self::DEFAULT_CONCURRENCY, 'prepare_data_source' => null, 'before_initiate' => null, 'before_upload' => null, 'before_complete' => null, 'exception_class' => MultipartUploadException::class]; | |
| 26 | 26 | /** @var Client Client used for the upload. */ |
| 27 | 27 | protected $client; |
| 28 | 28 | /** @var array Configuration used to perform the upload. */ |
| 29 | 29 | protected $config; |
| @@ -32,8 +32,10 @@ | ||
| 32 | 32 | /** @var PromiseInterface Promise that represents the multipart upload. */ |
| 33 | 33 | protected $promise; |
| 34 | 34 | /** @var UploadState State used to manage the upload. */ |
| 35 | 35 | protected $state; |
| 36 | + /** @var bool Configuration used to indicate if upload progress will be displayed. */ | |
| 37 | + protected $displayProgress; | |
| 36 | 38 | /** |
| 37 | 39 | * @param Client $client |
| 38 | 40 | * @param array $config |
| 39 | 41 | */ |
| @@ -42,8 +44,11 @@ | ||
| 42 | 44 | $this->client = $client; |
| 43 | 45 | $this->info = $this->loadUploadWorkflowInfo(); |
| 44 | 46 | $this->config = $config + self::$defaultConfig; |
| 45 | 47 | $this->state = $this->determineState(); |
| 48 | + if (isset($config['display_progress']) && \is_bool($config['display_progress'])) { | |
| 49 | + $this->displayProgress = $config['display_progress']; | |
| 50 | + } | |
| 46 | 51 | } |
| 47 | 52 | /** |
| 48 | 53 | * Returns the current state of the upload |
| 49 | 54 | * |
| @@ -68,9 +73,9 @@ | ||
| 68 | 73 | * Upload the source asynchronously using multipart upload operations. |
| 69 | 74 | * |
| 70 | 75 | * @return PromiseInterface |
| 71 | 76 | */ |
| 72 | - public function promise() | |
| 77 | + public function promise() : PromiseInterface | |
| 73 | 78 | { |
| 74 | 79 | if ($this->promise) { |
| 75 | 80 | return $this->promise; |
| 76 | 81 | } |
| @@ -168,12 +173,10 @@ | ||
| 168 | 173 | protected abstract function getCompleteParams(); |
| 169 | 174 | /** |
| 170 | 175 | * Based on the config and service-specific workflow info, creates a |
| 171 | 176 | * `Promise` for an `UploadState` object. |
| 172 | - * | |
| 173 | - * @return PromiseInterface A `Promise` that resolves to an `UploadState`. | |
| 174 | 177 | */ |
| 175 | - private function determineState() | |
| 178 | + private function determineState() : UploadState | |
| 176 | 179 | { |
| 177 | 180 | // If the state was provided via config, then just use it. |
| 178 | 181 | if ($this->config['state'] instanceof UploadState) { |
| 179 | 182 | return $this->config['state']; |
| @@ -187,9 +190,9 @@ | ||
| 187 | 190 | throw new IAE('You must provide a value for "' . $key . '" in ' . 'your config for the MultipartUploader for ' . $this->client->getApi()->getServiceFullName() . '.'); |
| 188 | 191 | } |
| 189 | 192 | $id[$param] = $this->config[$key]; |
| 190 | 193 | } |
| 191 | - $state = new UploadState($id); | |
| 194 | + $state = new UploadState($id, $this->config); | |
| 192 | 195 | $state->setPartSize($this->determinePartSize()); |
| 193 | 196 | return $state; |
| 194 | 197 | } |
| 195 | 198 | /** |
| @@ -226,9 +229,9 @@ | ||
| 226 | 229 | */ |
| 227 | 230 | protected function getResultHandler(&$errors = []) |
| 228 | 231 | { |
| 229 | 232 | return function (callable $handler) use(&$errors) { |
| 230 | - return function (CommandInterface $command, RequestInterface $request = null) use($handler, &$errors) { | |
| 233 | + return function (CommandInterface $command, ?RequestInterface $request = null) use($handler, &$errors) { | |
| 231 | 234 | return $handler($command, $request)->then(function (ResultInterface $result) use($command) { |
| 232 | 235 | $this->handleResult($command, $result); |
| 233 | 236 | return $result; |
| 234 | 237 | }, function (AwsException $e) use(&$errors) { |