Datastore/src/Operation.php
public function keys($kind, array $options = [])
    {
        $options += [
            'number' => 1,
            'ancestors' => [],
            'id' => null,
            'name' => null
        ];

        if ($options['number'] < 1) {
            throw new \InvalidArgumentException('Number of keys cannot be less than 1.');
        }

        $path = [];
        if (count($options['ancestors']) > 0) {
            $path = $options['ancestors'];
        }

        $path[] = array_filter([
            'kind' => $kind,
            'id' => $options['id'],
            'name' => $options['name']
        ]);

        $key = new Key($this->projectId, [
            'path' => $path,
            'namespaceId' => $this->namespaceId
        ]);

        $keys = [$key];

        for ($i = 1; $i < $options['number']; $i++) {
            $keys[] = clone $key;
        }

        return $keys;
    }
public function keys($kind, array $options = [])
    {
        $options += [
            'number' => 1,
            'ancestors' => [],
            'id' => null,
            'name' => null
        ];

        if ($options['number'] < 1) {
            throw new \InvalidArgumentException('Number of keys cannot be less than 1.');
        }

        $path = [];
        if (count($options['ancestors']) > 0) {
            $path = $options['ancestors'];
        }

        $path[] = array_filter([
            'kind' => $kind,
            'id' => $options['id'],
            'name' => $options['name']
        ]);

        $key = new Key($this->projectId, [
            'path' => $path,
            'namespaceId' => $this->namespaceId
        ]);

        $keys = [$key];

        for ($i = 1; $i < $options['number']; $i++) {
            $keys[] = clone $key;
        }

        return $keys;
    }
public function keys ( $ kind , array $ options = [ ] ) { $ options += [ 'number' => 1 , 'ancestors' => [ ] , 'id' => null , 'name' => null ] ; if ( $ options [ 'number' ] < 1 ) { throw new \ InvalidArgumentException ( 'Number of keys cannot be less than 1.' ) ; } $ path = [ ] ; if ( count ( $ options [ 'ancestors' ] ) > 0 ) { $ path = $ options [ 'ancestors' ] ; } $ path [ ] = array_filter ( [ 'kind' => $ kind , 'id' => $ options [ 'id' ] , 'name' => $ options [ 'name' ] ] ) ; $ key = new Key ( $ this -> projectId , [ 'path' => $ path , 'namespaceId' => $ this -> namespaceId ] ) ; $ keys = [ $ key ] ; for ( $ i = 1 ; $ i < $ options [ 'number' ] ; $ i ++ ) { $ keys [ ] = clone $ key ; } return $ keys ; }
Create multiple keys with the same configuration.

When inserting multiple entities, creating a set of keys at once can be
useful. By defining the Key's kind and any ancestors up front, and
allowing Cloud Datastore to allocate IDs, you can be sure that your
entity identity and ancestry are correct and that there will be no
collisions during the insert operation.

@see https://cloud.google.com/datastore/reference/rest/v1/Key Key
@see https://cloud.google.com/datastore/reference/rest/v1/Key#PathElement PathElement

@param string $kind The kind to use in the final path element.
@param array $options [optional] {
Configuration Options

@type array[] $ancestors An array of
[PathElement](https://cloud.google.com/datastore/reference/rest/v1/Key#PathElement) arrays. Use to
create [ancestor paths](https://cloud.google.com/datastore/docs/concepts/entities#ancestor_paths).
@type int $number The number of keys to generate.
@type string|int $id The ID for the last pathElement.
@type string $name The Name for the last pathElement.
}
@return Key[]
@throws \InvalidArgumentException If the number of keys is less than 1.
Create multiple keys with the same configuration .