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