PHP Class Sokil\Mongo\Document

Author: Dmytro Sokil ([email protected])
Inheritance: extends Structure
Afficher le fichier Open project: sokil/php-mongo Class Usage Examples

Méthodes publiques

Méthode Description
__call ( $name, $arguments )
__construct ( Collection $collection, array $data = null, array $options = [] )
__get ( $name )
__toString ( )
__unset ( $fieldName )
addRelation ( $relationName, Document $document )
addToSet ( $fieldName, $value )
addToSetEach ( $fieldName, array $values )
append ( type $selector, type $value ) : Structure If field not exist - set value.
attachBehavior ( string $name, string | array | Sokil\Mongo\Behavior $behavior ) : Document
attachBehaviors ( array $behaviors )
attachEvent ( string $event, callable | array | string $handler, $priority ) : Document Attach event handler
beforeConstruct ( ) Event handler, called before running constructor.
behaviors ( )
bitwiceAnd ( $field, $value )
bitwiceOr ( $field, $value )
bitwiceXor ( $field, $value )
clearBehaviors ( )
clearRevisions ( )
createReference ( ) : array Get reference to document
decrement ( $fieldName, $value = 1 )
defineId ( MongoId | string $id ) : Document Used to define id of stored document. This id must be already present in db
delete ( )
getCollection ( ) : Collection Get instance of collection
getId ( )
getOperator ( )
getOption ( $name, $default = null )
getOptions ( )
getReferencedDocument ( string $name ) : null | Document Get document by reference
getReferencedDocumentList ( string $name ) : null | Document Get document by reference
getRelated ( string $relationName ) : array | Document Get related documents
getRelationDefinition ( ) : array Relation definition through mapping is more prior to defined in class
getRevision ( $id )
getRevisionManager ( ) : Sokil\Mongo\RevisionManager
getRevisions ( $limit = null, $offset = null )
getRevisionsCount ( )
hasEvent ( string $event ) : boolean Check if event attached
hasOption ( $name )
increment ( $fieldName, $value = 1 )
isModificationOperatorDefined ( )
isSaveRequired ( )
isStored ( )
merge ( array $data ) : Document
pull ( integer | string | array | Expression | callable $expression, mixed | Expression | callable $value = null ) : Document Removes from an existing array all instances of a value or values that match a specified query
push ( string $fieldName, mixed $value ) : Document Push argument as single element to field value
pushEach ( string $fieldName, array $values ) : Document Push each element of argument's array as single element to field value
pushReference ( string $name, Document $document ) : Document Push reference to list
refresh ( ) Reload data from db and reset all unsaved data
removeRelation ( $relationName, Document $document = null )
reset ( ) : Document Reset all data passed to object in run-time, like events, behaviors, data modifications, etc. to the state just after open or save document
save ( $validate = true )
set ( string $fieldName, mixed $value ) : Document Update value in local cache and in DB
setGeometry ( string $field, GeoJson\Geometry\Geometry $geometry ) : Document Set geo data as GeoJson object
setGeometryCollection ( string $field, array $geometryCollection ) : Document Set collection of different geometries
setId ( MongoId | string $id ) : Document Used to define id of not stored document.
setLegacyPoint ( string $field, float $longitude, float $latitude ) : Document Set point as longitude and latitude in legacy format
setLineString ( string $field, array $pointArray ) : Document Set line string as array of points
setMultiLineString ( string $field, array $lineStringArray ) : Document Set multi line string as array of line strings
setMultiPoint ( string $field, array $pointArray ) : Document Set multi point as array of points
setMultyPolygon ( string $field, array $polygonsArray ) : Document Set multy polygon as array of polygons.
setPoint ( string $field, float $longitude, float $latitude ) : Document Set point as longitude and latitude
setPolygon ( string $field, array $lineRingsArray ) : Document Set polygon as array of line rings.
setReference ( $name, Document $document ) : Document Store DBRef to specified field
triggerEvent ( string $eventName, Event $event = null ) : Event Manually trigger defined events
unsetField ( string $fieldName ) : Document Remove field
validate ( ) : Document

Méthodes protégées

Méthode Description
relations ( ) : array Override in child class to define relations

Private Methods

Méthode Description
getRelationManager ( ) : Sokil\Mongo\Document\RelationManager
initDelegates ( ) Initialise relative classes

Method Details

__call() public méthode

public __call ( $name, $arguments )

__construct() public méthode

public __construct ( Collection $collection, array $data = null, array $options = [] )
$collection Collection instance of Mongo collection
$data array mongo document
$options array options of object initialization

__get() public méthode

public __get ( $name )

__toString() public méthode

public __toString ( )

__unset() public méthode

public __unset ( $fieldName )

addRelation() public méthode

public addRelation ( $relationName, Document $document )
$document Document

addToSet() public méthode

public addToSet ( $fieldName, $value )

addToSetEach() public méthode

public addToSetEach ( $fieldName, array $values )
$values array

append() public méthode

If field exists and is not array - convert to array and append If field -s array - append
public append ( type $selector, type $value ) : Structure
$selector type
$value type
Résultat Structure

attachBehavior() public méthode

public attachBehavior ( string $name, string | array | Sokil\Mongo\Behavior $behavior ) : Document
$name string unique name of attached behavior
$behavior string | array | Sokil\Mongo\Behavior Behavior instance or behavior definition
Résultat Document

attachBehaviors() public méthode

public attachBehaviors ( array $behaviors )
$behaviors array

attachEvent() public méthode

Attach event handler
public attachEvent ( string $event, callable | array | string $handler, $priority ) : Document
$event string event name
$handler callable | array | string event handler
Résultat Document

beforeConstruct() public méthode

May be overridden in child classes
public beforeConstruct ( )

behaviors() public méthode

public behaviors ( )

bitwiceAnd() public méthode

public bitwiceAnd ( $field, $value )

bitwiceOr() public méthode

public bitwiceOr ( $field, $value )

bitwiceXor() public méthode

public bitwiceXor ( $field, $value )

clearBehaviors() public méthode

public clearBehaviors ( )

clearRevisions() public méthode

Deprecation: since 1.13.0 use self::getRevisionManager()->clearRevisions()
public clearRevisions ( )

createReference() public méthode

Get reference to document
public createReference ( ) : array
Résultat array

decrement() public méthode

public decrement ( $fieldName, $value = 1 )

defineId() public méthode

Used to define id of stored document. This id must be already present in db
public defineId ( MongoId | string $id ) : Document
$id MongoId | string id of document
Résultat Document

delete() public méthode

public delete ( )

getCollection() public méthode

Get instance of collection
public getCollection ( ) : Collection
Résultat Collection

getId() public méthode

public getId ( )

getOperator() public méthode

public getOperator ( )

getOption() public méthode

public getOption ( $name, $default = null )

getOptions() public méthode

public getOptions ( )

getReferencedDocument() public méthode

Get document by reference
public getReferencedDocument ( string $name ) : null | Document
$name string name of field where reference stored
Résultat null | Document

getReferencedDocumentList() public méthode

Get document by reference
public getReferencedDocumentList ( string $name ) : null | Document
$name string name of field where reference stored
Résultat null | Document

getRelated() public méthode

Get related documents
public getRelated ( string $relationName ) : array | Document
$relationName string
Résultat array | Document related document or array of documents

getRelationDefinition() public méthode

Relation definition through mapping is more prior to defined in class
public getRelationDefinition ( ) : array
Résultat array definition of relations

getRevision() public méthode

Deprecation: since 1.13.0 use self::getRevisionManager()->getRevision()
public getRevision ( $id )

getRevisionManager() public méthode

public getRevisionManager ( ) : Sokil\Mongo\RevisionManager
Résultat Sokil\Mongo\RevisionManager

getRevisions() public méthode

Deprecation: since 1.13.0 use self::getRevisionManager()->getRevisions()
public getRevisions ( $limit = null, $offset = null )

getRevisionsCount() public méthode

Deprecation: since 1.13.0 use self::getRevisionManager()->getRevisionsCount()
public getRevisionsCount ( )

hasEvent() public méthode

Check if event attached
public hasEvent ( string $event ) : boolean
$event string event name
Résultat boolean

hasOption() public méthode

public hasOption ( $name )

increment() public méthode

public increment ( $fieldName, $value = 1 )

isModificationOperatorDefined() public méthode

isSaveRequired() public méthode

public isSaveRequired ( )

isStored() public méthode

public isStored ( )

merge() public méthode

public merge ( array $data ) : Document
$data array
Résultat Document

pull() public méthode

Removes from an existing array all instances of a value or values that match a specified query
public pull ( integer | string | array | Expression | callable $expression, mixed | Expression | callable $value = null ) : Document
$expression integer | string | array | Expression | callable
$value mixed | Expression | callable
Résultat Document

push() public méthode

Push argument as single element to field value
public push ( string $fieldName, mixed $value ) : Document
$fieldName string
$value mixed
Résultat Document

pushEach() public méthode

Push each element of argument's array as single element to field value
public pushEach ( string $fieldName, array $values ) : Document
$fieldName string
$values array
Résultat Document

pushReference() public méthode

Push reference to list
public pushReference ( string $name, Document $document ) : Document
$name string
$document Document
Résultat Document

refresh() public méthode

Reload data from db and reset all unsaved data
public refresh ( )

relations() protected méthode

Override in child class to define relations
protected relations ( ) : array
Résultat array relation description

removeRelation() public méthode

public removeRelation ( $relationName, Document $document = null )
$document Document

reset() public méthode

Reset all data passed to object in run-time, like events, behaviors, data modifications, etc. to the state just after open or save document
public reset ( ) : Document
Résultat Document

save() public méthode

public save ( $validate = true )

set() public méthode

Update value in local cache and in DB
public set ( string $fieldName, mixed $value ) : Document
$fieldName string point-delimited field name
$value mixed value to store
Résultat Document

setGeometry() public méthode

Requires MongoDB version 2.4 or above with 2dsparse index version 1 to use Point, LineString and Polygon. Requires MongoDB version 2.6 or above with 2dsparse index version 2 to use MultiPoint, MultiLineString, MultiPolygon and GeometryCollection.
public setGeometry ( string $field, GeoJson\Geometry\Geometry $geometry ) : Document
$field string
$geometry GeoJson\Geometry\Geometry
Résultat Document

setGeometryCollection() public méthode

Requires MongoDB version 2.6 or above with 2dsparse index version 2 to use MultiPoint, MultiLineString, MultiPolygon and GeometryCollection.
public setGeometryCollection ( string $field, array $geometryCollection ) : Document
$field string
$geometryCollection array
Résultat Document

setId() public méthode

Used to define id of not stored document.
public setId ( MongoId | string $id ) : Document
$id MongoId | string id of document
Résultat Document

setLegacyPoint() public méthode

May be used 2d index
public setLegacyPoint ( string $field, float $longitude, float $latitude ) : Document
$field string
$longitude float
$latitude float
Résultat Document

setLineString() public méthode

Requires MongoDB version 2.4 or above with 2dsparse index version 1 to use Point, LineString and Polygon.
public setLineString ( string $field, array $pointArray ) : Document
$field string
$pointArray array array of points
Résultat Document

setMultiLineString() public méthode

Requires MongoDB version 2.6 or above with 2dsparse index version 2 to use MultiPoint, MultiLineString, MultiPolygon and GeometryCollection. http://docs.mongodb.org/manual/core/2dsphere/#multilinestring
public setMultiLineString ( string $field, array $lineStringArray ) : Document
$field string
$lineStringArray array array of line strings
Résultat Document

setMultiPoint() public méthode

Requires MongoDB version 2.6 or above with 2dsparse index version 2 to use MultiPoint, MultiLineString, MultiPolygon and GeometryCollection.
public setMultiPoint ( string $field, array $pointArray ) : Document
$field string
$pointArray array array of point arrays
Résultat Document

setMultyPolygon() public méthode

Polygon is array of line rings. Line ring is closed line string (first and last point same). Line string is array of points. Requires MongoDB version 2.6 or above with 2dsparse index version 2 to use MultiPoint, MultiLineString, MultiPolygon and GeometryCollection.
public setMultyPolygon ( string $field, array $polygonsArray ) : Document
$field string
$polygonsArray array array of polygons
Résultat Document

setPoint() public méthode

Requires MongoDB version 2.4 or above with 2dsparse index version 1 to use Point, LineString and Polygon.
public setPoint ( string $field, float $longitude, float $latitude ) : Document
$field string
$longitude float
$latitude float
Résultat Document

setPolygon() public méthode

Line ring is closed line string (first and last point same). Line string is array of points. Requires MongoDB version 2.4 or above with 2dsparse index version 1 to use Point, LineString and Polygon.
public setPolygon ( string $field, array $lineRingsArray ) : Document
$field string
$lineRingsArray array array of line rings
Résultat Document

setReference() public méthode

Store DBRef to specified field
public setReference ( $name, Document $document ) : Document
$name
$document Document
Résultat Document

triggerEvent() public méthode

Manually trigger defined events
public triggerEvent ( string $eventName, Event $event = null ) : Event
$eventName string event name
$event Event
Résultat Event

unsetField() public méthode

Remove field
public unsetField ( string $fieldName ) : Document
$fieldName string field name
Résultat Document

validate() public méthode

public validate ( ) : Document
Résultat Document