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';
Datei anzeigen
Open project: GoogleCloudPlatform/gcloud-php
Class Usage Examples
Public Methods
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.
} |
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();
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();
excludedProperties()
public method
Example:
$excludedFromIndexes = $entity->excludedProperties();
Example:
$data = $entity->get();
Example:
$key = $entity->key();
public key ( ) : Key |
return |
Key |
|
Example:
$meanings = $entity->meanings();
offsetExists()
public method
offsetGet()
public method
offsetSet()
public method
offsetUnset()
public method
populatedByService()
public method
Example:
$populatedByService = $entity->populatedByService();
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'
]);
setExcludeFromIndexes()
public method
Example:
$entity['birthDate'] = new DateTime('December 31, 1969');
$entity->setExcludeFromIndexes([
'birthDate'
]);