PHP Класс lithium\data\entity\Document

A Document object's fields can represent a collection of both simple and complex data types, as well as other Document objects. Given the following data (document) structure: {{{ { _id: 12345. name: 'Acme, Inc.', employees: { 'Larry': { email: '[email protected]' }, 'Curly': { email: '[email protected]' }, 'Moe': { email: '[email protected]' } } } }}} You can query the object as follows: {{{$acme = Company::find(12345);}}} This returns a Document object, populated with the raw representation of the data. {{{print_r($acme->to('array')); Yields: array( '_id' => 12345, 'name' => 'Acme, Inc.', 'employees' => array( 'Larry' => array('email' => '[email protected]'), 'Curly' => array('email' => '[email protected]'), 'Moe' => array('email' => '[email protected]') ) )}}} As with other database objects, a Document exposes its fields as object properties, like so: {{{echo $acme->name; // echoes 'Acme, Inc.'}}} However, accessing a field containing a data set will return that data set wrapped in a sub-Document object., i.e.: {{{$employees = $acme->employees; returns a Document object with the data in 'employees'}}}
Наследование: extends lithium\data\Entity, implements Iterator, implements ArrayAccess
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$_pathKey string If this Document instance has a parent document (see $_parent), this value indicates the key name of the parent document that contains it.
$_removed array Removed keys list. Contains names of the fields will be removed from the backend data store
$_stats array Contains an array of backend-specific statistics generated by the query that produced this Document object. These stats are accessible via the stats() method.
$_valid boolean Holds the current iteration state. Used by Document::valid() to terminate foreach loops when there are no more fields to iterate over.

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

Метод Описание
__get ( $name ) : mixed PHP magic method used when accessing fields as document properties, i.e. $document->_id.
__isset ( $name ) : boolean PHP magic method used to check the presence of a field as document properties, i.e.
__set ( $name, $value = null ) : void PHP magic method used when setting properties on the Document instance, i.e.
__unset ( string $name ) : void PHP magic method used when unset() is called on a Document instance.
current ( )
export ( array $options = [] )
key ( )
next ( ) : mixed Returns the next Document in the set, and advances the object's internal pointer. If the end of the set is reached, a new document will be fetched from the data source connection handle ($_handle). If no more records can be fetched, returns null.
offsetExists ( mixed $offset ) : boolean Allows document fields to be tested as array keys, i.e. isset($document['_id']).
offsetGet ( mixed $offset ) : mixed Allows document fields to be accessed as array keys, i.e. $document['_id'].
offsetSet ( mixed $offset, mixed $value ) : void Allows document fields to be assigned as array keys, i.e. $document['_id'] = $id.
offsetUnset ( string $key ) : void Allows document fields to be unset as array keys, i.e. unset($document['_id']).
rewind ( ) : mixed Rewinds to the first item.
set ( array $data, array $options = [] ) : void Allows several properties to be assigned at once.
sync ( mixed $id = null, array $data = [], array $options = [] ) : void Extends the parent implementation to ensure that child documents are properly synced as well.
to ( string $format, array $options = [] ) : mixed Adds conversions checks to ensure certain class types and embedded values are properly cast.
valid ( ) : boolean Used by the Iterator interface to determine the current state of the iteration, and when to stop iterating.

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

Метод Описание
_getNested ( $name )
_init ( )
_relation ( string $classType, string $key, array $data, array $options = [] ) : object Instantiates a new Document object as a descendant of the current object, and sets all default values and internal state.
_setNested ( $name, $value )

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

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

PHP magic method used when accessing fields as document properties, i.e. $document->_id.
public __get ( $name ) : mixed
$name The field name, as specified with an object property.
Результат mixed Returns the value of the field specified in `$name`, and wraps complex data types in sub-`Document` objects.

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

$document->_id.
public __isset ( $name ) : boolean
$name The field name, as specified with an object property.
Результат boolean True if the field specified in `$name` exists, false otherwise.

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

$document->title = 'Lorem Ipsum'. If $value is a complex data type (i.e. associative array), it is wrapped in a sub-Document object before being appended.
public __set ( $name, $value = null ) : void
$name The name of the field/property to write to, i.e. `title` in the above example.
$value The value to write, i.e. `'Lorem Ipsum'`.
Результат void

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

Use case for this would be when you wish to edit a document and remove a field, ie.: $doc = Post::find($id); unset($doc->fieldName); $doc->save();
public __unset ( string $name ) : void
$name string The name of the field to remove.
Результат void

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

protected _getNested ( $name )

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

protected _init ( )

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

Instantiates a new Document object as a descendant of the current object, and sets all default values and internal state.
protected _relation ( string $classType, string $key, array $data, array $options = [] ) : object
$classType string The type of class to create, either `'entity'` or `'set'`.
$key string The key name to which the related object is assigned.
$data array The internal data of the related object.
$options array Any other options to pass when instantiating the related object.
Результат object Returns a new `Document` object instance.

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

protected _setNested ( $name, $value )

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

public current ( )

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

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

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

public key ( )

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

Returns the next Document in the set, and advances the object's internal pointer. If the end of the set is reached, a new document will be fetched from the data source connection handle ($_handle). If no more records can be fetched, returns null.
public next ( ) : mixed
Результат mixed Returns the next record in the set, or `null`, if no more records are available.

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

Allows document fields to be tested as array keys, i.e. isset($document['_id']).
public offsetExists ( mixed $offset ) : boolean
$offset mixed String or integer indicating the offset or the name of a field in an individual document.
Результат boolean Returns `true` if `$offset` is a field in the document, otherwise `false`.

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

Allows document fields to be accessed as array keys, i.e. $document['_id'].
public offsetGet ( mixed $offset ) : mixed
$offset mixed String or integer indicating the offset or index of a document in a set, or the name of a field in an individual document.
Результат mixed Returns either a sub-object in the document, or a scalar field value.

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

Allows document fields to be assigned as array keys, i.e. $document['_id'] = $id.
public offsetSet ( mixed $offset, mixed $value ) : void
$offset mixed String or integer indicating the offset or the name of a field in an individual document.
$value mixed The value to assign to the field.
Результат void

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

Allows document fields to be unset as array keys, i.e. unset($document['_id']).
public offsetUnset ( string $key ) : void
$key string The name of a field in an individual document.
Результат void

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

Rewinds to the first item.
public rewind ( ) : mixed
Результат mixed The current item after rewinding.

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

For example: $doc->set(array('title' => 'Lorem Ipsum', 'value' => 42));
public set ( array $data, array $options = [] ) : void
$data array An associative array of fields and values to assign to the `Document`.
$options array
Результат void

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

Extends the parent implementation to ensure that child documents are properly synced as well.
public sync ( mixed $id = null, array $data = [], array $options = [] ) : void
$id mixed
$data array
$options array Options when calling this method: - `'recursive'` _boolean_: If `true` attempts to sync nested objects as well. Otherwise, only syncs the current object. Defaults to `true`.
Результат void

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

Adds conversions checks to ensure certain class types and embedded values are properly cast.
public to ( string $format, array $options = [] ) : mixed
$format string Currently only `array` is supported.
$options array
Результат mixed

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

Used by the Iterator interface to determine the current state of the iteration, and when to stop iterating.
public valid ( ) : boolean
Результат boolean

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

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

If this Document instance has a parent document (see $_parent), this value indicates the key name of the parent document that contains it.
См. также: lithium\data\entity\Document::$_parent
protected string $_pathKey
Результат string

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

Removed keys list. Contains names of the fields will be removed from the backend data store
protected array $_removed
Результат array

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

Contains an array of backend-specific statistics generated by the query that produced this Document object. These stats are accessible via the stats() method.
См. также: lithium\data\collection\DocumentSet::stats()
protected array $_stats
Результат array

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

Holds the current iteration state. Used by Document::valid() to terminate foreach loops when there are no more fields to iterate over.
protected bool $_valid
Результат boolean