| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\Aws\S3\Exception; |
| 4 |
|
| 5 |
use Dudlewebs\WPMCS\s3\Aws\CommandInterface; |
| 6 |
use Dudlewebs\WPMCS\s3\Aws\Exception\AwsException; |
| 7 |
use Dudlewebs\WPMCS\s3\Aws\Multipart\UploadState; |
| 8 |
class S3MultipartUploadException extends \Dudlewebs\WPMCS\s3\Aws\Exception\MultipartUploadException |
| 9 |
{ |
| 10 |
/** @var string Bucket of the transfer object */ |
| 11 |
private $bucket; |
| 12 |
/** @var string Key of the transfer object */ |
| 13 |
private $key; |
| 14 |
/** @var string Source file name of the transfer object */ |
| 15 |
private $filename; |
| 16 |
/** |
| 17 |
* @param UploadState $state Upload state at time of the exception. |
| 18 |
* @param \Exception|array $prev Exception being thrown. Could be an array of |
| 19 |
* AwsExceptions being thrown when uploading parts |
| 20 |
* for one object, or an instance of AwsException |
| 21 |
* for a specific Multipart error being thrown in |
| 22 |
* the MultipartUpload process. |
| 23 |
*/ |
| 24 |
public function __construct(UploadState $state, $prev = null) |
| 25 |
{ |
| 26 |
if (\is_array($prev) && ($error = $prev[\key($prev)])) { |
| 27 |
$this->collectPathInfo($error->getCommand()); |
| 28 |
} elseif ($prev instanceof AwsException) { |
| 29 |
$this->collectPathInfo($prev->getCommand()); |
| 30 |
} |
| 31 |
parent::__construct($state, $prev); |
| 32 |
} |
| 33 |
/** |
| 34 |
* Get the Bucket information of the transfer object |
| 35 |
* |
| 36 |
* @return string|null Returns null when 'Bucket' information |
| 37 |
* is unavailable. |
| 38 |
*/ |
| 39 |
public function getBucket() |
| 40 |
{ |
| 41 |
return $this->bucket; |
| 42 |
} |
| 43 |
/** |
| 44 |
* Get the Key information of the transfer object |
| 45 |
* |
| 46 |
* @return string|null Returns null when 'Key' information |
| 47 |
* is unavailable. |
| 48 |
*/ |
| 49 |
public function getKey() |
| 50 |
{ |
| 51 |
return $this->key; |
| 52 |
} |
| 53 |
/** |
| 54 |
* Get the source file name of the transfer object |
| 55 |
* |
| 56 |
* @return string|null Returns null when metadata of the stream |
| 57 |
* wrapped in 'Body' parameter is unavailable. |
| 58 |
*/ |
| 59 |
public function getSourceFileName() |
| 60 |
{ |
| 61 |
return $this->filename; |
| 62 |
} |
| 63 |
/** |
| 64 |
* Collect file path information when accessible. (Bucket, Key) |
| 65 |
* |
| 66 |
* @param CommandInterface $cmd |
| 67 |
*/ |
| 68 |
private function collectPathInfo(CommandInterface $cmd) |
| 69 |
{ |
| 70 |
if (empty($this->bucket) && isset($cmd['Bucket'])) { |
| 71 |
$this->bucket = $cmd['Bucket']; |
| 72 |
} |
| 73 |
if (empty($this->key) && isset($cmd['Key'])) { |
| 74 |
$this->key = $cmd['Key']; |
| 75 |
} |
| 76 |
if (empty($this->filename) && isset($cmd['Body'])) { |
| 77 |
$this->filename = $cmd['Body']->getMetadata('uri'); |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|