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
파일 보기 프로젝트 열기: unionofrad/lithium 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_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