DeleteMultipleObjectsException.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Aws\S3\Exception;
  3. use Aws\HasMonitoringEventsTrait;
  4. use Aws\MonitoringEventsInterface;
  5. /**
  6. * Exception thrown when errors occur while deleting objects using a
  7. * {@see S3\BatchDelete} object.
  8. */
  9. class DeleteMultipleObjectsException extends \Exception implements
  10. MonitoringEventsInterface
  11. {
  12. use HasMonitoringEventsTrait;
  13. private $deleted = [];
  14. private $errors = [];
  15. /**
  16. * @param array $deleted Array of successfully deleted keys
  17. * @param array $errors Array of errors that were encountered
  18. */
  19. public function __construct(array $deleted, array $errors)
  20. {
  21. $this->deleted = array_values($deleted);
  22. $this->errors = array_values($errors);
  23. parent::__construct('Unable to delete certain keys when executing a'
  24. . ' DeleteMultipleObjects request: '
  25. . self::createMessageFromErrors($errors));
  26. }
  27. /**
  28. * Create a single error message from multiple errors.
  29. *
  30. * @param array $errors Errors encountered
  31. *
  32. * @return string
  33. */
  34. public static function createMessageFromErrors(array $errors)
  35. {
  36. return "\n- " . implode("\n- ", array_map(function ($key) {
  37. return json_encode($key);
  38. }, $errors));
  39. }
  40. /**
  41. * Get the errored objects
  42. *
  43. * @return array Returns an array of associative arrays, each containing
  44. * a 'Code', 'Message', and 'Key' key.
  45. */
  46. public function getErrors()
  47. {
  48. return $this->errors;
  49. }
  50. /**
  51. * Get the successfully deleted objects
  52. *
  53. * @return array Returns an array of associative arrays, each containing
  54. * a 'Key' and optionally 'DeleteMarker' and
  55. * 'DeleterMarkerVersionId'
  56. */
  57. public function getDeleted()
  58. {
  59. return $this->deleted;
  60. }
  61. }