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'}}}
파일 보기
프로젝트 열기: 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. |
|
보호된 메소드들
메소드 상세
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. |
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. |
$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 |
|
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();
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. |
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. |
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`. |
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. |
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 |
|
Allows document fields to be unset as array keys, i.e. unset($document['_id']).
Rewinds to the first item.
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 |
|
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 |
|
Adds conversions checks to ensure certain class types and embedded values are properly cast.
Used by the Iterator interface to determine the current state of the iteration, and when
to stop iterating.
프로퍼티 상세
If this Document instance has a parent document (see $_parent), this value indicates
the key name of the parent document that contains it.
protected string $_pathKey |
리턴 |
string |
|
Removed keys list. Contains names of the fields will be removed from the backend data store
protected array $_removed |
리턴 |
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.
protected array $_stats |
리턴 |
array |
|
Holds the current iteration state. Used by Document::valid() to terminate foreach loops
when there are no more fields to iterate over.