PHP Class Sokil\Mongo\Document

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

Public Methods

Method 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

Protected Methods

Method Description
relations ( ) : array Override in child class to define relations

Private Methods

Method Description
getRelationManager ( ) : Sokil\Mongo\Document\RelationManager
initDelegates ( ) Initialise relative classes

Method Details

__call() public method

public __call ( $name, $arguments )

__construct() public method

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 method

public __get ( $name )

__toString() public method

public __toString ( )

__unset() public method

public __unset ( $fieldName )

addRelation() public method

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

addToSet() public method

public addToSet ( $fieldName, $value )

addToSetEach() public method

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

append() public method

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
return Structure

attachBehavior() public method

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
return Document

attachBehaviors() public method

public attachBehaviors ( array $behaviors )
$behaviors array

attachEvent() public method

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

beforeConstruct() public method

May be overridden in child classes
public beforeConstruct ( )

behaviors() public method

public behaviors ( )

bitwiceAnd() public method

public bitwiceAnd ( $field, $value )

bitwiceOr() public method

public bitwiceOr ( $field, $value )

bitwiceXor() public method

public bitwiceXor ( $field, $value )

clearBehaviors() public method

public clearBehaviors ( )

clearRevisions() public method

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

createReference() public method

Get reference to document
public createReference ( ) : array
return array

decrement() public method

public decrement ( $fieldName, $value = 1 )

defineId() public method

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
return Document

delete() public method

public delete ( )

getCollection() public method

Get instance of collection
public getCollection ( ) : Collection
return Collection

getId() public method

public getId ( )

getOperator() public method

public getOperator ( )

getOption() public method

public getOption ( $name, $default = null )

getOptions() public method

public getOptions ( )

getReferencedDocument() public method

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

getReferencedDocumentList() public method

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

getRelated() public method

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

getRelationDefinition() public method

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

getRevision() public method

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

getRevisionManager() public method

public getRevisionManager ( ) : Sokil\Mongo\RevisionManager
return Sokil\Mongo\RevisionManager

getRevisions() public method

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

getRevisionsCount() public method

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

hasEvent() public method

Check if event attached
public hasEvent ( string $event ) : boolean
$event string event name
return boolean

hasOption() public method

public hasOption ( $name )

increment() public method

public increment ( $fieldName, $value = 1 )

isModificationOperatorDefined() public method

isSaveRequired() public method

public isSaveRequired ( )

isStored() public method

public isStored ( )

merge() public method

public merge ( array $data ) : Document
$data array
return Document

pull() public method

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
return Document

push() public method

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

pushEach() public method

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

pushReference() public method

Push reference to list
public pushReference ( string $name, Document $document ) : Document
$name string
$document Document
return Document

refresh() public method

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

relations() protected method

Override in child class to define relations
protected relations ( ) : array
return array relation description

removeRelation() public method

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

reset() public method

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
return Document

save() public method

public save ( $validate = true )

set() public method

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
return Document

setGeometry() public method

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
return Document

setGeometryCollection() public method

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
return Document

setId() public method

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

setLegacyPoint() public method

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

setLineString() public method

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
return Document

setMultiLineString() public method

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
return Document

setMultiPoint() public method

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
return Document

setMultyPolygon() public method

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
return Document

setPoint() public method

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
return Document

setPolygon() public method

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
return Document

setReference() public method

Store DBRef to specified field
public setReference ( $name, Document $document ) : Document
$name
$document Document
return Document

triggerEvent() public method

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

unsetField() public method

Remove field
public unsetField ( string $fieldName ) : Document
$fieldName string field name
return Document

validate() public method

public validate ( ) : Document
return Document