PHP Класс lithium\data\Entity

The Entity class can also be used as a base class for your own custom data objects, and is the basis for generating forms with the Form helper.
См. также: lithium\template\helper\Form
Наследование: extends lithium\core\Object
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_autoConfig array Auto configuration.
$_data array Associative array of the entity's fields and values.
$_errors array The list of validation errors associated with this object, where keys are field names, and values are arrays containing one or more validation error messages.
$_exists boolean A flag indicating whether or not this entity exists. Set to false if this is a newly-created entity, or if this entity has been loaded and subsequently deleted. Set to true if the entity has been loaded from the database, or has been created and subsequently saved.
$_handlers array Hold the "data export" handlers where the keys are fully-namespaced class names, and the values are closures that take an instance of the class as a parameter, and return an array or scalar value that the instance represents.
$_increment array An array of key/value pairs corresponding to fields that should be updated using atomic incrementing / decrementing operations. Keys match field names, and values indicate the value each field should be incremented or decremented by.
$_model string Fully-namespaced class name of model that this record is bound to. Instance methods declared in the model may be called on the entity. See the Model class documentation for more information.
$_parent object If this record is chained off of another, contains the origin object.
$_relationships array An array containing all related records and recordsets, keyed by relationship name, as defined in the bound model class.
$_schema array to create a form.
$_updated array Contains the values of updated fields. These values will be persisted to the backend data store when the document is saved.

Открытые методы

Метод Описание
__call ( string $method, array $params ) : mixed Magic method that allows calling of model methods on this record instance, i.e.: $record->validates();
__construct ( array $config = [] ) : void Constructor.
__get ( string $name ) : mixed Overloading for reading inaccessible properties.
__isset ( string $name ) : mixed Overloading for calling isset() or empty() on inaccessible properties.
__set ( string $name, mixed $value ) : void PHP magic method used when setting properties on the Entity instance, i.e.
__toString ( ) : string Returns a string representation of the Entity instance, based on the result of the 'title' meta value of the bound model class.
assignTo ( object $parent, array $config = [] ) Configures protected properties of an Entity so that it is parented to $parent.
data ( string $name = null ) : mixed Access the data fields of the record. Can also access a $named field.
decrement ( string $field, string $value = 1 ) : integer Decrements a field by the specified value. Works identically to increment(), but in reverse.
errors ( array | string $field = null, string $value = null ) : mixed Access the errors of the record.
exists ( ) : boolean A flag indicating whether or not this record exists.
export ( array $options = [] )
increment ( string $field, integer | string $value = 1 ) : integer Safely (atomically) increments the value of the specified field by an arbitrary value.
model ( ) : string Returns the model which this entity is bound to.
modified ( $field = null ) : mixed Gets the current state for a given field or, if no field is given, gets the array of fields modified on this entity.
parent ( ) : object Returns the parent object of this object, if any.
respondsTo ( string $method, boolean $internal = false ) : boolean Determines if a given method can be called.
schema ( $field = null )
serialize ( ) : string Prepares, enables and executes serialization of the object.
set ( array $data ) : void Allows several properties to be assigned at once, i.e.: $record->set(array('title' => 'Lorem Ipsum', 'value' => 42));
sync ( mixed $id = null, array $data = [], array $options = [] ) Called after an Entity is saved. Updates the object's internal state to reflect the corresponding database entity, and sets the Entity object's key, if this is a newly-created object. **Do not** call this method if you intend to update the database's copy of the entity. Instead, see Model::save().
to ( string $format, array $options = [] ) : mixed Converts the data in the record set to a different format, i.e. an array.
unserialize ( string $data ) : void Prepares, enables and executes unserialization of the object.

Защищенные методы

Метод Описание
_init ( )

Описание методов

__call() публичный Метод

Magic method that allows calling of model methods on this record instance, i.e.: $record->validates();
public __call ( string $method, array $params ) : mixed
$method string Method name caught by `__call()`.
$params array Arguments given to the above `$method` call.
Результат mixed

__construct() публичный Метод

Constructor.
public __construct ( array $config = [] ) : void
$config array Available configuration options are: - `'data'` _array_: Data to enter into the record. Defaults to an empty array. - `'model'` _string_: Class name that provides the data-source for this record. Defaults to `null`.
Результат void

__get() публичный Метод

Overloading for reading inaccessible properties.
public __get ( string $name ) : mixed
$name string Property name.
Результат mixed Result.

__isset() публичный Метод

Overloading for calling isset() or empty() on inaccessible properties.
public __isset ( string $name ) : mixed
$name string Property name.
Результат mixed Result.

__set() публичный Метод

$entity->title = 'Lorem Ipsum'.
public __set ( string $name, mixed $value ) : void
$name string The name of the field/property to write to, i.e. `title` in the above example.
$value mixed The value to write, i.e. `'Lorem Ipsum'`.
Результат void

__toString() публичный Метод

Returns a string representation of the Entity instance, based on the result of the 'title' meta value of the bound model class.
public __toString ( ) : string
Результат string Returns the generated title of the object.

_init() защищенный Метод

protected _init ( )

assignTo() публичный Метод

Configures protected properties of an Entity so that it is parented to $parent.
public assignTo ( object $parent, array $config = [] )
$parent object
$config array

data() публичный Метод

Access the data fields of the record. Can also access a $named field.
public data ( string $name = null ) : mixed
$name string Optionally included field name.
Результат mixed Entire data array if $name is empty, otherwise the value from the named field.

decrement() публичный Метод

Decrements a field by the specified value. Works identically to increment(), but in reverse.
См. также: lithium\data\Entity::increment()
public decrement ( string $field, string $value = 1 ) : integer
$field string The name of the field to decrement.
$value string The value by which to decrement the field. Defaults to `1`.
Результат integer Returns the new value of `$field`, after modification.

errors() публичный Метод

Access the errors of the record.
См. также: lithium\data\Entity::$_errors
public errors ( array | string $field = null, string $value = null ) : mixed
$field array | string If an array, overwrites `$this->_errors` if it is empty, if not, merges the errors with the current values. If a string, and `$value` is not `null`, sets the corresponding key in `$this->_errors` to `$value`. Setting `$field` to `false` will reset the current state.
$value string Value to set.
Результат mixed Either the `$this->_errors` array, or single value from it.

exists() публичный Метод

A flag indicating whether or not this record exists.
public exists ( ) : boolean
Результат boolean `True` if the record was `read` from the data-source, or has been `create`d and `save`d. Otherwise `false`.

export() публичный Метод

public export ( array $options = [] )
$options array

increment() публичный Метод

Defaults to 1 if no value is specified. Throws an exception if the specified field is non-numeric.
public increment ( string $field, integer | string $value = 1 ) : integer
$field string The name of the field to be incremented.
$value integer | string The value to increment the field by. Defaults to `1` if this parameter is not specified.
Результат integer Returns the current value of `$field`, based on the value retrieved from the data source when the entity was loaded, plus any increments applied. Note that it may not reflect the most current value in the persistent backend data source.

model() публичный Метод

Returns the model which this entity is bound to.
public model ( ) : string
Результат string The fully qualified model class name.

modified() публичный Метод

Gets the current state for a given field or, if no field is given, gets the array of fields modified on this entity.
public modified ( $field = null ) : mixed
Результат mixed Returns `true` if a field is given and was updated, `false` otherwise and `null` if the field was not set at all. If no field is given returns an arra where the keys are entity field names, and the values are `true` for changed fields.

parent() публичный Метод

Returns the parent object of this object, if any.
public parent ( ) : object
Результат object Returns the object that contains this object, or `null`.

respondsTo() публичный Метод

Determines if a given method can be called.
public respondsTo ( string $method, boolean $internal = false ) : boolean
$method string Name of the method.
$internal boolean Provide `true` to perform check from inside the class/object. When `false` checks also for public visibility; defaults to `false`.
Результат boolean Returns `true` if the method can be called, `false` otherwise.

schema() публичный Метод

public schema ( $field = null )

serialize() публичный Метод

Note: because of the limitations outlined below custom handlers and schema are ignored with serialized objects. Properties that hold anonymous functions are also skipped. Some of these can almost be reconstructed (_handlers) others cannot (_methodFilters and schema).
public serialize ( ) : string
Результат string Serialized properties of the object.

set() публичный Метод

Allows several properties to be assigned at once, i.e.: $record->set(array('title' => 'Lorem Ipsum', 'value' => 42));
public set ( array $data ) : void
$data array An associative array of fields and values to assign to this `Entity` instance.
Результат void

sync() публичный Метод

Called after an Entity is saved. Updates the object's internal state to reflect the corresponding database entity, and sets the Entity object's key, if this is a newly-created object. **Do not** call this method if you intend to update the database's copy of the entity. Instead, see Model::save().
См. также: lithium\data\Model::save()
public sync ( mixed $id = null, array $data = [], array $options = [] )
$id mixed The ID to assign, where applicable.
$data array Any additional generated data assigned to the object by the database.
$options array Method options: - `'materialize'` _boolean_: Determines whether or not the flag should be set that indicates that this entity exists in the data store. Defaults to `true`. - `'dematerialize'` _boolean_: If set to `true`, indicates that this entity has been deleted from the data store and no longer exists. Defaults to `false`.

to() публичный Метод

Converts the data in the record set to a different format, i.e. an array.
public to ( string $format, array $options = [] ) : mixed
$format string Currently only `array`.
$options array Options for converting: - `'indexed'` _boolean_: Allows to control how converted data of nested collections is keyed. When set to `true` will force indexed conversion of nested collection data. By default `false` which will only index the root level.
Результат mixed

unserialize() публичный Метод

Restores state of the object including pulled results. Tries to restore _handlers by calling into _init().
public unserialize ( string $data ) : void
$data string Serialized properties of the object.
Результат void

Описание свойств

$_autoConfig защищенное свойство

Auto configuration.
protected array $_autoConfig
Результат array

$_data защищенное свойство

Associative array of the entity's fields and values.
protected array $_data
Результат array

$_errors защищенное свойство

The list of validation errors associated with this object, where keys are field names, and values are arrays containing one or more validation error messages.
См. также: lithium\data\Entity::errors()
protected array $_errors
Результат array

$_exists защищенное свойство

A flag indicating whether or not this entity exists. Set to false if this is a newly-created entity, or if this entity has been loaded and subsequently deleted. Set to true if the entity has been loaded from the database, or has been created and subsequently saved.
protected bool $_exists
Результат boolean

$_handlers защищенное свойство

Hold the "data export" handlers where the keys are fully-namespaced class names, and the values are closures that take an instance of the class as a parameter, and return an array or scalar value that the instance represents.
См. также: lithium\data\Entity::to()
protected array $_handlers
Результат array

$_increment защищенное свойство

An array of key/value pairs corresponding to fields that should be updated using atomic incrementing / decrementing operations. Keys match field names, and values indicate the value each field should be incremented or decremented by.
См. также: lithium\data\Entity::increment()
См. также: lithium\data\Entity::decrement()
protected array $_increment
Результат array

$_model защищенное свойство

Fully-namespaced class name of model that this record is bound to. Instance methods declared in the model may be called on the entity. See the Model class documentation for more information.
См. также: lithium\data\Model
См. также: lithium\data\Entity::__call()
protected string $_model
Результат string

$_parent защищенное свойство

If this record is chained off of another, contains the origin object.
protected object $_parent
Результат object

$_relationships защищенное свойство

An array containing all related records and recordsets, keyed by relationship name, as defined in the bound model class.
protected array $_relationships
Результат array

$_schema защищенное свойство

to create a form.
protected array $_schema
Результат array

$_updated защищенное свойство

Contains the values of updated fields. These values will be persisted to the backend data store when the document is saved.
protected array $_updated
Результат array