S3MultipartUploadException.php 2.6 KB

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