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

보호된 프로퍼티들

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