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