client = $client; $this->bucket = $bucket; $this->mfa = $mfa; } /** * Set a new MFA token value * * @param string $token MFA token * * @return self */ public function setMfa($token) { $this->mfa = $token; return $this; } /** * {@inheritdoc} * @throws OverflowException if a batch has more than 1000 items * @throws InvalidArgumentException when an invalid batch item is encountered */ public function transfer(array $batch) { if (empty($batch)) { return; } if (count($batch) > 1000) { throw new OverflowException('Batches should be divided into chunks of no larger than 1000 keys'); } $del = array(); $command = $this->client->getCommand('DeleteObjects', array( 'Bucket' => $this->bucket, Ua::OPTION => Ua::BATCH )); if ($this->mfa) { $command->getRequestHeaders()->set('x-amz-mfa', $this->mfa); } foreach ($batch as $object) { // Ensure that the batch item is valid if (!is_array($object) || !isset($object['Key'])) { throw new InvalidArgumentException('Invalid batch item encountered: ' . var_export($batch, true)); } $del[] = array( 'Key' => $object['Key'], 'VersionId' => isset($object['VersionId']) ? $object['VersionId'] : null ); } $command['Objects'] = $del; $command->execute(); $this->processResponse($command); } /** * Process the response of the DeleteMultipleObjects request * * @paramCommandInterface $command Command executed */ protected function processResponse(CommandInterface $command) { $result = $command->getResult(); // Ensure that the objects were deleted successfully if (!empty($result['Errors'])) { $errors = $result['Errors']; throw new DeleteMultipleObjectsException($errors); } } }