Datastore/src/Operation.php
private function mapEntityResult(array $result, $class)
    {
        $entity = $result['entity'];

        $namespaceId = (isset($entity['key']['partitionId']['namespaceId']))
            ? $entity['key']['partitionId']['namespaceId']
            : null;

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

        if (is_array($class)) {
            $lastPathElement = $key->pathEnd();
            if (!array_key_exists($lastPathElement['kind'], $class)) {
                throw new \InvalidArgumentException(sprintf(
                    'No class found for kind %s',
                    $lastPathElement['kind']
                ));
            }

            $className = $class[$lastPathElement['kind']];
        } else {
            $className = $class;
        }

        $properties = [];
        $excludes = [];
        $meanings = [];

        if (isset($entity['properties'])) {
            $res = $this->entityMapper->responseToEntityProperties($entity['properties'], $className);

            $properties = $res['properties'];
            $excludes = $res['excludes'];
            $meanings = $res['meanings'];
        }

        return $this->entity($key, $properties, [
            'cursor' => (isset($result['cursor']))
                ? $result['cursor']
                : null,
            'baseVersion' => (isset($result['version']))
                ? $result['version']
                : null,
            'className' => $className,
            'populatedByService' => true,
            'excludeFromIndexes' => $excludes,
            'meanings' => $meanings
        ]);
    }
private function mapEntityResult(array $result, $class)
    {
        $entity = $result['entity'];

        $namespaceId = (isset($entity['key']['partitionId']['namespaceId']))
            ? $entity['key']['partitionId']['namespaceId']
            : null;

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

        if (is_array($class)) {
            $lastPathElement = $key->pathEnd();
            if (!array_key_exists($lastPathElement['kind'], $class)) {
                throw new \InvalidArgumentException(sprintf(
                    'No class found for kind %s',
                    $lastPathElement['kind']
                ));
            }

            $className = $class[$lastPathElement['kind']];
        } else {
            $className = $class;
        }

        $properties = [];
        $excludes = [];
        $meanings = [];

        if (isset($entity['properties'])) {
            $res = $this->entityMapper->responseToEntityProperties($entity['properties'], $className);

            $properties = $res['properties'];
            $excludes = $res['excludes'];
            $meanings = $res['meanings'];
        }

        return $this->entity($key, $properties, [
            'cursor' => (isset($result['cursor']))
                ? $result['cursor']
                : null,
            'baseVersion' => (isset($result['version']))
                ? $result['version']
                : null,
            'className' => $className,
            'populatedByService' => true,
            'excludeFromIndexes' => $excludes,
            'meanings' => $meanings
        ]);
    }
private function mapEntityResult ( array $ result , $ class ) { $ entity = $ result [ 'entity' ] ; $ namespaceId = ( isset ( $ entity [ 'key' ] [ 'partitionId' ] [ 'namespaceId' ] ) ) ? $ entity [ 'key' ] [ 'partitionId' ] [ 'namespaceId' ] : null ; $ key = new Key ( $ this -> projectId , [ 'path' => $ entity [ 'key' ] [ 'path' ] , 'namespaceId' => $ namespaceId ] ) ; if ( is_array ( $ class ) ) { $ lastPathElement = $ key -> pathEnd ( ) ; if ( ! array_key_exists ( $ lastPathElement [ 'kind' ] , $ class ) ) { throw new \ InvalidArgumentException ( sprintf ( 'No class found for kind %s' , $ lastPathElement [ 'kind' ] ) ) ; } $ className = $ class [ $ lastPathElement [ 'kind' ] ] ; } else { $ className = $ class ; } $ properties = [ ] ; $ excludes = [ ] ; $ meanings = [ ] ; if ( isset ( $ entity [ 'properties' ] ) ) { $ res = $ this -> entityMapper -> responseToEntityProperties ( $ entity [ 'properties' ] , $ className ) ; $ properties = $ res [ 'properties' ] ; $ excludes = $ res [ 'excludes' ] ; $ meanings = $ res [ 'meanings' ] ; } return $ this -> entity ( $ key , $ properties , [ 'cursor' => ( isset ( $ result [ 'cursor' ] ) ) ? $ result [ 'cursor' ] : null , 'baseVersion' => ( isset ( $ result [ 'version' ] ) ) ? $ result [ 'version' ] : null , 'className' => $ className , 'populatedByService' => true , 'excludeFromIndexes' => $ excludes , 'meanings' => $ meanings ] ) ; }
Convert an EntityResult into an array of entities

@see https://cloud.google.com/datastore/reference/rest/v1/EntityResult EntityResult

@param array $result The EntityResult from a Lookup.
@param string|array $class If a string, the name of the class to return results as.
Must implement {@see Google\Cloud\Datastore\EntityInterface}.
If not set, {@see Google\Cloud\Datastore\Entity} will be used.
If an array is given, it must be an associative array, where
the key is a Kind and the value is an object implementing
{@see Google\Cloud\Datastore\EntityInterface}.
@return EntityInterface[]
Convert an EntityResult into an array of entities