Storage/src/Bucket.php
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,
            'userProject' => $this->identity['userProject'],
            '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 + array_filter([
                'requesterProjectId' => $this->identity['userProject']
            ])
        );
    }
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,
            'userProject' => $this->identity['userProject'],
            '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 + array_filter([
                'requesterProjectId' => $this->identity['userProject']
            ])
        );
    }
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 , 'userProject' => $ this -> identity [ 'userProject' ] , '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 + array_filter ( [ 'requesterProjectId' => $ this -> identity [ 'userProject' ] ] ) ) ; }
Composes a set of objects into a single object.

Please note that all objects to be composed must come from the same
bucket.

Example:
```
$sourceObjects = ['log1.txt', 'log2.txt'];
$singleObject = $bucket->compose($sourceObjects, 'combined-logs.txt');
```

```
// Use an instance of StorageObject.
$sourceObjects = [
$bucket->object('log1.txt'),
$bucket->object('log2.txt')
];

$singleObject = $bucket->compose($sourceObjects, 'combined-logs.txt');
```

@see https://cloud.google.com/storage/docs/json_api/v1/objects/compose Objects compose API documentation

@param string[]|StorageObject[] $sourceObjects The objects to compose.
@param string $name The name of the composed object.
@param array $options [optional] {
Configuration options.

@type string $predefinedAcl Predefined ACL to apply to the composed
object. Acceptable values include, `"authenticatedRead"`,
`"bucketOwnerFullControl"`, `"bucketOwnerRead"`, `"private"`,
`"projectPrivate"`, and `"publicRead"`.
@type array $metadata Metadata to apply to the composed object. The
available options for metadata are outlined at the
[JSON API docs](https://cloud.google.com/storage/docs/json_api/v1/objects/insert#request-body).
@type string $ifGenerationMatch Makes the operation conditional on whether the object's current generation
matches the given value.
@type string $ifMetagenerationMatch Makes the operation conditional on whether the object's current
metageneration matches the given value.
}
@return StorageObject
@throws \InvalidArgumentException
Composes a set of objects into a single object .