PHP Class Google\Cloud\Datastore\Entity

Entity implements PHP's ArrayAccess, allowing access via the array syntax (example below). Properties are mapped automatically to their corresponding Datastore value types. Refer to the table below for a guide to how types are stored. | **PHP Type** | **Datastore Value Type** | |--------------------------------------------|--------------------------------------| | \DateTimeInterface | timestampValue | | {@see \Google\Cloud\Datastore\Key} | keyValue | | {@see \Google\Cloud\Datastore\GeoPoint} | geoPointValue | | {@see \Google\Cloud\Datastore\Entity} | entityValue | | {@see \Google\Cloud\Datastore\Blob} | blobValue | | {@see \Google\Cloud\Int64} | integerValue | | Associative Array | entityValue (No Key) | | Non-Associative Array | arrayValue | | float | doubleValue | | int | integerValue | | string | stringValue | | resource | blobValue | | NULL | nullValue | | bool | booleanValue | | object (Outside types specified above) | **ERROR** InvalidArgumentException | Example: use Google\Cloud\ServiceBuilder; $cloud = new ServiceBuilder(); $datastore = $cloud->datastore(); $key = $datastore->key('Person', 'Bob'); $entity = $datastore->entity($key, [ 'firstName' => 'Bob', 'lastName' => 'Testguy' ]); echo $entity['firstName']; // 'Bob' $entity['location'] = 'Detroit, MI';
Inheritance: implements ArrayAcces\ArrayAccess, use trait DatastoreTrait
Datei anzeigen Open project: GoogleCloudPlatform/gcloud-php Class Usage Examples

Public Methods

Method Description
__construct ( Key $key, array $entity = [], array $options = [] )
__get ( string $property ) : mixed
__isset ( string $property ) : boolean
__set ( string $property, mixed $value ) : void
__unset ( string $property ) : void
baseVersion ( ) : string | null Fetch the baseVersion
cursor ( ) : string | null Fetch the cursor
excludedProperties ( ) : array Return a list of properties excluded from datastore indexes
get ( ) : array Get the entity data
key ( ) : Key Get the Entity Key
meanings ( ) : array return a list of meaning values
offsetExists ( string $key ) : boolean
offsetGet ( string $key ) : mixed
offsetSet ( string $key, $val ) : void
offsetUnset ( string $key ) : void
populatedByService ( ) : boolean Indicate whether the entity was created as the result of an API call.
set ( array $entity ) : void Set the entity data
setExcludeFromIndexes ( array $properties ) : void A list of entity properties to exclude from datastore indexes.

Method Details

__construct() public method

public __construct ( Key $key, array $entity = [], array $options = [] )
$key Key The Entity's Key, defining its unique identifier.
$entity array [optional] The entity body.
$options array [optional] { Configuration Options @type string $cursor Set only when the entity is obtained by a query result. If set, the entity cursor can be retrieved from {@see \Google\Cloud\Datastore\Entity::cursor()}. @type string $baseVersion Set only when the entity is obtained by a query result. If set, the entity cursor can be retrieved from {@see \Google\Cloud\Datastore\Entity::baseVersion()}. @type array $excludeFromIndexes A list of entity keys to exclude from datastore indexes. @type array $meanings A list of meaning values for entity properties. @type bool $populatedByService Indicates whether the entity was created as the result of a service request. }

__get() public method

public __get ( string $property ) : mixed
$property string
return mixed

__isset() public method

public __isset ( string $property ) : boolean
$property string
return boolean

__set() public method

public __set ( string $property, mixed $value ) : void
$property string
$value mixed
return void

__unset() public method

public __unset ( string $property ) : void
$property string
return void

baseVersion() public method

This is only set when the entity was obtained from a query result. It is used for concurrency control internally. Example: $baseVersion = $entity->baseVersion();
public baseVersion ( ) : string | null
return string | null

cursor() public method

This is only set when the entity was obtained from a query result. It can be used to manually paginate results. Example: $cursor = $entity->cursor();
public cursor ( ) : string | null
return string | null

excludedProperties() public method

Example: $excludedFromIndexes = $entity->excludedProperties();
public excludedProperties ( ) : array
return array

get() public method

Example: $data = $entity->get();
public get ( ) : array
return array

key() public method

Example: $key = $entity->key();
public key ( ) : Key
return Key

meanings() public method

Example: $meanings = $entity->meanings();
public meanings ( ) : array
return array

offsetExists() public method

public offsetExists ( string $key ) : boolean
$key string the value to check.
return boolean

offsetGet() public method

public offsetGet ( string $key ) : mixed
$key string the value to retrieve.
return mixed

offsetSet() public method

public offsetSet ( string $key, $val ) : void
$key string The value name.
return void

offsetUnset() public method

public offsetUnset ( string $key ) : void
$key string the value to remove.
return void

populatedByService() public method

Example: $populatedByService = $entity->populatedByService();
public populatedByService ( ) : boolean
return boolean

set() public method

Calling this method replaces the entire entity body. To add or modify a single value on the entity, use the array syntax for assignment. Example: $entity->set([ 'firstName' => 'Dave' ]);
public set ( array $entity ) : void
$entity array The new entity body.
return void

setExcludeFromIndexes() public method

Example: $entity['birthDate'] = new DateTime('December 31, 1969'); $entity->setExcludeFromIndexes([ 'birthDate' ]);
public setExcludeFromIndexes ( array $properties ) : void
$properties array A list of properties to exclude from indexes.
return void