Datastore/src/Operation.php
public function entity($key = null, array $entity = [], array $options = [])
    {
        $options += [
            'className' => null
        ];

        if ($key && !is_string($key) && !($key instanceof Key)) {
            throw new \InvalidArgumentException(
                '$key must be an instance of Key or a string'
            );
        }

        if (is_string($key)) {
            $key = $this->key($key);
        }

        $className = $options['className'];
        if (!is_null($className) && !is_subclass_of($className, EntityInterface::class)) {
            throw new \InvalidArgumentException(sprintf(
                'Given classname %s must implement EntityInterface',
                $className
            ));
        }

        if (is_null($className)) {
            $className = Entity::class;
        }

        return $className::build($key, $entity, $options);
    }
public function entity($key = null, array $entity = [], array $options = [])
    {
        $options += [
            'className' => null
        ];

        if ($key && !is_string($key) && !($key instanceof Key)) {
            throw new \InvalidArgumentException(
                '$key must be an instance of Key or a string'
            );
        }

        if (is_string($key)) {
            $key = $this->key($key);
        }

        $className = $options['className'];
        if (!is_null($className) && !is_subclass_of($className, EntityInterface::class)) {
            throw new \InvalidArgumentException(sprintf(
                'Given classname %s must implement EntityInterface',
                $className
            ));
        }

        if (is_null($className)) {
            $className = Entity::class;
        }

        return $className::build($key, $entity, $options);
    }
public function entity ( $ key = null , array $ entity = [ ] , array $ options = [ ] ) { $ options += [ 'className' => null ] ; if ( $ key && ! is_string ( $ key ) && ! ( $ key instanceof Key ) ) { throw new \ InvalidArgumentException ( '$key must be an instance of Key or a string' ) ; } if ( is_string ( $ key ) ) { $ key = $ this -> key ( $ key ) ; } $ className = $ options [ 'className' ] ; if ( ! is_null ( $ className ) && ! is_subclass_of ( $ className , EntityInterface :: class ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Given classname %s must implement EntityInterface' , $ className ) ) ; } if ( is_null ( $ className ) ) { $ className = Entity :: class ; } return $ className :: build ( $ key , $ entity , $ options ) ; }
Create an entity

This method does not execute any service requests.

Entities are created with a Datastore Key, or by specifying a Kind. Kinds
are only allowed for insert operations. For any other case, you must
specify a named key. If a kind is given, an ID will be automatically
allocated for the entity upon insert. Additionally, if your entity
requires a complex key elementPath, you must create the key separately.

In certain cases, you may want to create your own entity types.
Google Cloud PHP supports custom types implementing
{@see Google\Cloud\Datastore\EntityInterface}. If the name of an
`EntityInterface` implementation is given in the options array, an
instance of that class will be returned instead of
{@see Google\Cloud\Datastore\Entity}.

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

@param Key|string|null $key [optional] The key used to identify the record, or
a string $kind. The key may be null only if the entity will be
used as an embedded entity within another entity. Attempting to
use keyless entities as root entities will result in error.
@param array $entity [optional] The data to fill the entity with.
@param array $options [optional] {
Configuration Options

@type string $className If set, the given class will be returned.
Value must be the name of a class implementing
{@see Google\Cloud\Datastore\EntityInterface}. **Defaults to**
{@see Google\Cloud\Datastore\Entity}.
@type array $excludeFromIndexes A list of entity keys to exclude from
datastore indexes.
}
@return EntityInterface
@throws InvalidArgumentException
Create an entity