Datastore/src/Operation.php
public function lookup(array $keys, array $options = [])
    {
        $options += [
            'className' => Entity::class,
            'sort' => false
        ];

        $serviceKeys = [];
        $this->validateBatch($keys, Key::class, function ($key) use (&$serviceKeys) {
            if ($key->state() !== Key::STATE_NAMED) {
                throw new \InvalidArgumentException(sprintf(
                    'Given $key is in an invalid state. Can only lookup records when given a complete key. ' .
                    'Given path was %s',
                    (string) $key
                ));
            }

            $serviceKeys[] = $key->keyObject();
        });

        $res = $this->connection->lookup($options + $this->readOptions($options) + [
            'projectId' => $this->projectId,
            'keys' => $serviceKeys
        ]);

        $result = [];
        if (isset($res['found'])) {
            foreach ($res['found'] as $found) {
                $result['found'][] = $this->mapEntityResult($found, $options['className']);
            }

            if ($options['sort']) {
                $result['found'] = $this->sortEntities($result['found'], $keys);
            }
        }

        if (isset($res['missing'])) {
            $result['missing'] = [];
            foreach ($res['missing'] as $missing) {
                $key = $this->key(
                    $missing['entity']['key']['path'],
                    $missing['entity']['key']['partitionId']
                );

                $result['missing'][] = $key;
            }
        }

        if (isset($res['deferred'])) {
            $result['deferred'] = [];
            foreach ($res['deferred'] as $deferred) {
                $key = $this->key(
                    $deferred['path'],
                    $deferred['partitionId']
                );

                $result['deferred'][] = $key;
            }
        }

        return $result;
    }
public function lookup(array $keys, array $options = [])
    {
        $options += [
            'className' => Entity::class,
            'sort' => false
        ];

        $serviceKeys = [];
        $this->validateBatch($keys, Key::class, function ($key) use (&$serviceKeys) {
            if ($key->state() !== Key::STATE_NAMED) {
                throw new \InvalidArgumentException(sprintf(
                    'Given $key is in an invalid state. Can only lookup records when given a complete key. ' .
                    'Given path was %s',
                    (string) $key
                ));
            }

            $serviceKeys[] = $key->keyObject();
        });

        $res = $this->connection->lookup($options + $this->readOptions($options) + [
            'projectId' => $this->projectId,
            'keys' => $serviceKeys
        ]);

        $result = [];
        if (isset($res['found'])) {
            foreach ($res['found'] as $found) {
                $result['found'][] = $this->mapEntityResult($found, $options['className']);
            }

            if ($options['sort']) {
                $result['found'] = $this->sortEntities($result['found'], $keys);
            }
        }

        if (isset($res['missing'])) {
            $result['missing'] = [];
            foreach ($res['missing'] as $missing) {
                $key = $this->key(
                    $missing['entity']['key']['path'],
                    $missing['entity']['key']['partitionId']
                );

                $result['missing'][] = $key;
            }
        }

        if (isset($res['deferred'])) {
            $result['deferred'] = [];
            foreach ($res['deferred'] as $deferred) {
                $key = $this->key(
                    $deferred['path'],
                    $deferred['partitionId']
                );

                $result['deferred'][] = $key;
            }
        }

        return $result;
    }
public function lookup ( array $ keys , array $ options = [ ] ) { $ options += [ 'className' => Entity :: class , 'sort' => false ] ; $ serviceKeys = [ ] ; $ this -> validateBatch ( $ keys , Key :: class , function ( $ key ) use ( & $ serviceKeys ) { if ( $ key -> state ( ) !== Key :: STATE_NAMED ) { throw new \ InvalidArgumentException ( sprintf ( 'Given $key is in an invalid state. Can only lookup records when given a complete key. ' . 'Given path was %s' , ( string ) $ key ) ) ; } $ serviceKeys [ ] = $ key -> keyObject ( ) ; } ) ; $ res = $ this -> connection -> lookup ( $ options + $ this -> readOptions ( $ options ) + [ 'projectId' => $ this -> projectId , 'keys' => $ serviceKeys ] ) ; $ result = [ ] ; if ( isset ( $ res [ 'found' ] ) ) { foreach ( $ res [ 'found' ] as $ found ) { $ result [ 'found' ] [ ] = $ this -> mapEntityResult ( $ found , $ options [ 'className' ] ) ; } if ( $ options [ 'sort' ] ) { $ result [ 'found' ] = $ this -> sortEntities ( $ result [ 'found' ] , $ keys ) ; } } if ( isset ( $ res [ 'missing' ] ) ) { $ result [ 'missing' ] = [ ] ; foreach ( $ res [ 'missing' ] as $ missing ) { $ key = $ this -> key ( $ missing [ 'entity' ] [ 'key' ] [ 'path' ] , $ missing [ 'entity' ] [ 'key' ] [ 'partitionId' ] ) ; $ result [ 'missing' ] [ ] = $ key ; } } if ( isset ( $ res [ 'deferred' ] ) ) { $ result [ 'deferred' ] = [ ] ; foreach ( $ res [ 'deferred' ] as $ deferred ) { $ key = $ this -> key ( $ deferred [ 'path' ] , $ deferred [ 'partitionId' ] ) ; $ result [ 'deferred' ] [ ] = $ key ; } } return $ result ; }
Lookup records by key

@param Key[] $keys The identifiers to look up.
@param array $options [optional] {
Configuration Options

@type string $readConsistency See
[ReadConsistency](https://cloud.google.com/datastore/reference/rest/v1/ReadOptions#ReadConsistency).
@type string $transaction The transaction ID, if the query should be
run in a transaction.
@type string|array $className If a string, the given class will be
returned. Value must be the name of a class implementing
{@see Google\Cloud\Datastore\EntityInterface}.
If an array is given, it must be an associative array, where
the key is a Kind and the value must implement
{@see Google\Cloud\Datastore\EntityInterface}. **Defaults to**
{@see Google\Cloud\Datastore\Entity}.
@type bool $sort If set to true, results in each set will be sorted
to match the order given in $keys. **Defaults to** `false`.
}
@return array Returns an array with keys [`found`, `missing`, and `deferred`].
Members of `found` will be instance of
{@see Google\Cloud\Datastore\Entity}. Members of `missing` and
`deferred` will be instance of {@see Google\Cloud\Datastore\Key}.
@throws InvalidArgumentException
Lookup records by key