public function compose(array $sourceObjects, $name, array $options = [])
{
if (count($sourceObjects) < 2) {
throw new \InvalidArgumentException('Must provide at least two objects to compose.');
}
$options += ['destinationBucket' => $this->name(), 'destinationObject' => $name, 'destinationPredefinedAcl' => isset($options['predefinedAcl']) ? $options['predefinedAcl'] : null, 'destination' => isset($options['metadata']) ? $options['metadata'] : null, 'sourceObjects' => array_map(function ($sourceObject) {
$name = null;
$generation = null;
if ($sourceObject instanceof StorageObject) {
$name = $sourceObject->name();
$generation = isset($sourceObject->identity()['generation']) ? $sourceObject->identity()['generation'] : null;
}
return array_filter(['name' => $name ?: $sourceObject, 'generation' => $generation]);
}, $sourceObjects)];
if (!isset($options['destination']['contentType'])) {
$options['destination']['contentType'] = Psr7\mimetype_from_filename($name);
}
if ($options['destination']['contentType'] === null) {
throw new \InvalidArgumentException('A content type could not be detected and must be provided manually.');
}
unset($options['metadata']);
unset($options['predefinedAcl']);
$response = $this->connection->composeObject(array_filter($options));
return new StorageObject($this->connection, $response['name'], $this->identity['bucket'], $response['generation'], $response);
}