For example, I'm trying to create a method similar to doesObjectExist()
, but for multiple files called doObjectsExist()
. The problem is that I need it to return true if all files exist and false if even just one doesn't. Here's my current method.
public function doObjectsExist(...$objects) {
$client = $this->client;
$bucket = $this->bucket;
$commands = [];
foreach ($objects as $key) {
$commands[] = $client->getCommand('HeadObject', [
'Bucket' => $bucket,
'Key' => $key
]);
}
$pool = new CommandPool($client, $commands, [null,
'rejected' => function (AwsException $reason, $iterKey, PromiseInterface $aggregatePromise) {
return false;
}
]);
$promise = $pool->promise();
try {
$promise->wait();
return true;
}
catch (AwsException $e) {
return false;
}
}