PHP Class Shanty_Mongo_Document

Author: Coen Hyde
Inheritance: extends Shanty_Mongo_Collection, implements ArrayAccess, implements Countable, implements IteratorAggregate
Mostra file Open project: coen-hyde/shanty-mongo Class Usage Examples

Protected Properties

Property Type Description
$_cleanData
$_config
$_data
$_docRequirements
$_filters
$_operations
$_references
$_requirements
$_validators

Public Methods

Method Description
__construct ( $data = [], $config = [] )
__get ( $property ) : mixed Get a property
__isset ( string $property ) Test to see if a property is set
__set ( string $property, mixed $value ) Set a property
__unset ( string $property ) Unset a property
_getMongoCollection ( boolean $writable = true ) : MongoCollection Fetch an instance of MongoCollection
_getMongoDb ( boolean $writable = true ) : MongoDb Fetch an instance of MongoDb
addOperation ( string $operation, $property = null, $value = null ) Add an operation
addRequirement ( string $property, string $requirement, $options = null ) Add a requirement to a property
addToSet ( $property, $value ) * Adds value to the array only if its not in the array already.
applyRequirements ( array $requirements, $dirty = true ) Apply a set of requirements
count ( ) : integer Count all properties in this document
createReference ( ) : array Create a reference to this document
delete ( $safe = true ) Delete this document
export ( $skipRequired = false ) : array Export all data
getConfigAttribute ( string $attribute ) Get a config attribute
getCriteria ( string $property = null ) : mixed Get criteria
getFilters ( String $property ) : Zend_Filter Get all filters attached to a property
getId ( ) : MongoId Get this document's id
getInheritance ( ) : array Get the inheritance of this document
getIterator ( ) : Shanty_Mongo_DocumentIterator Get the document iterator
getOperations ( boolean $includingChildren = false ) Get all operations
getPathToDocument ( ) : string Get the path to this document from the root document
getPathToProperty ( $property ) : string Get the full path from the root document to a property
getPropertiesWithRequirement ( array $requirement ) Get all the properties with a particular requirement
getProperty ( mixed $property ) Get a property
getPropertyKeys ( ) Get a list of all property keys in this document
getRequirements ( string $prefix = null ) Get all requirements. If prefix is provided then only the requirements for the properties that start with prefix will be returned.
getValidators ( String $property ) : Zend_Validate Get all validators attached to a property
hasConfigAttribute ( string $attribute ) Determine if a config attribute is set
hasCriteria ( $property ) : boolean Determine if the document has certain criteria
hasId ( ) : boolean Does this document have an id
hasKey ( ) : boolean Determine if this document has a key
hasProperty ( $property ) : boolean Determine if this document has a property
hasReference ( $referenceName ) : boolean Determine if the document has a given reference or not
hasRequirement ( string $property, string $requirement ) Test if this document has a particular requirement
inc ( string $property, integer $value = 1 ) Increment a property by a specified amount
isConnected ( ) Is this document connected to a db and collection
isEmpty ( ) : boolean Test to see if this document is empty
isLocked ( ) : boolean Is this document locked
isNewDocument ( ) : boolean Is this document a new document
isParentDocumentSet ( ) : boolean Is this document a child element of a document set
isReference ( Shanty_Mongo_Document $document ) : boolean Test to see if a document is a reference in this document
isRootDocument ( ) : boolean Is this document a root document
isValid ( String $property, boolean $value ) Test if a value is valid against a property
loadRequirements ( String $property ) : boolean Load the requirements as validators or filters for a given property, and cache them as validators or filters, respectively.
offsetExists ( string $offset ) Test to see if an offset exists
offsetGet ( string $offset ) : mixed Get an offset
offsetSet ( string $offset, mixed $value ) set an offset
offsetUnset ( string $offset ) Unset a property
pop ( $property, $value ) * Removes an element from an array
processChanges ( array $data = [] ) Convert data changes into operations
pull ( string $property, mixed $value ) Pull all occurrences a value from an array
purgeOperations ( boolean $includingChildren = false ) Remove all operations
push ( string $property = null, mixed $value = null ) Push a value to a property
removeIgnoredProperties ( &$exportData ) : void Removes any properties that have been flagged as ignore in properties.
removeRequirement ( string $property, string $requirement ) Remove a requirement from a property
save ( boolean $entierDocument = false, boolean $safe = true ) : boolean Save this document
saveUnsafe ( boolean $entierDocument = false ) : boolean Save this document without waiting for a response from the server
setConfigAttribute ( string $attribute, unknown_type $value ) Set a config attribute
setCriteria ( string $property = null, $value = null ) Add criteria
setId ( MongoId $id ) : MongoId Set this document's id
setPathToDocument ( unknown_type $path ) Set the path to this document from the root document
setProperty ( mixed $property, mixed $value ) Set a property

Protected Methods

Method Description
init ( )
postDelete ( )
postInsert ( )
postSave ( )
postUpdate ( )
preDelete ( )
preInsert ( )
preSave ( )
preUpdate ( )

Method Details

__construct() public method

public __construct ( $data = [], $config = [] )

__get() public method

Get a property
public __get ( $property ) : mixed
$property
return mixed

__isset() public method

Test to see if a property is set
public __isset ( string $property )
$property string

__set() public method

Set a property
public __set ( string $property, mixed $value )
$property string
$value mixed

__unset() public method

Unset a property
public __unset ( string $property )
$property string

_getMongoCollection() public method

Fetch an instance of MongoCollection
public _getMongoCollection ( boolean $writable = true ) : MongoCollection
$writable boolean
return MongoCollection

_getMongoDb() public method

Fetch an instance of MongoDb
public _getMongoDb ( boolean $writable = true ) : MongoDb
$writable boolean
return MongoDb

addOperation() public method

Add an operation
public addOperation ( string $operation, $property = null, $value = null )
$operation string

addRequirement() public method

Add a requirement to a property
public addRequirement ( string $property, string $requirement, $options = null )
$property string
$requirement string

addToSet() public method

* Adds value to the array only if its not in the array already.
public addToSet ( $property, $value )
$property
$value

applyRequirements() public method

Apply a set of requirements
public applyRequirements ( array $requirements, $dirty = true )
$requirements array

count() public method

Count all properties in this document
public count ( ) : integer
return integer

createReference() public method

Create a reference to this document
public createReference ( ) : array
return array

delete() public method

$return boolean Result of delete
public delete ( $safe = true )

export() public method

Export all data
public export ( $skipRequired = false ) : array
return array

getConfigAttribute() public method

Get a config attribute
public getConfigAttribute ( string $attribute )
$attribute string

getCriteria() public method

Get criteria
public getCriteria ( string $property = null ) : mixed
$property string
return mixed

getFilters() public method

Get all filters attached to a property
public getFilters ( String $property ) : Zend_Filter
$property String
return Zend_Filter

getId() public method

Get this document's id
public getId ( ) : MongoId
return MongoId

getInheritance() public method

Get the inheritance of this document
public getInheritance ( ) : array
return array

getIterator() public method

Get the document iterator
public getIterator ( ) : Shanty_Mongo_DocumentIterator
return Shanty_Mongo_DocumentIterator

getOperations() public method

Get all operations
public getOperations ( boolean $includingChildren = false )
$includingChildren boolean Get operations from children as well

getPathToDocument() public method

Get the path to this document from the root document
public getPathToDocument ( ) : string
return string

getPathToProperty() public method

Get the full path from the root document to a property
public getPathToProperty ( $property ) : string
$property
return string

getPropertiesWithRequirement() public method

Get all the properties with a particular requirement
public getPropertiesWithRequirement ( array $requirement )
$requirement array

getProperty() public method

Get a property
public getProperty ( mixed $property )
$property mixed

getPropertyKeys() public method

Get a list of all property keys in this document
public getPropertyKeys ( )

getRequirements() public method

Get all requirements. If prefix is provided then only the requirements for the properties that start with prefix will be returned.
public getRequirements ( string $prefix = null )
$prefix string

getValidators() public method

Get all validators attached to a property
public getValidators ( String $property ) : Zend_Validate
$property String Name of property
return Zend_Validate

hasConfigAttribute() public method

Determine if a config attribute is set
public hasConfigAttribute ( string $attribute )
$attribute string

hasCriteria() public method

Determine if the document has certain criteria
public hasCriteria ( $property ) : boolean
return boolean

hasId() public method

Does this document have an id
public hasId ( ) : boolean
return boolean

hasKey() public method

Determine if this document has a key
public hasKey ( ) : boolean
return boolean

hasProperty() public method

Determine if this document has a property
public hasProperty ( $property ) : boolean
$property
return boolean

hasReference() public method

Determine if the document has a given reference or not
public hasReference ( $referenceName ) : boolean
return boolean

hasRequirement() public method

Test if this document has a particular requirement
public hasRequirement ( string $property, string $requirement )
$property string
$requirement string

inc() public method

Increment a property by a specified amount
public inc ( string $property, integer $value = 1 )
$property string
$value integer

init() protected method

protected init ( )

isConnected() public method

Is this document connected to a db and collection
public isConnected ( )

isEmpty() public method

Test to see if this document is empty
public isEmpty ( ) : boolean
return boolean

isLocked() public method

Is this document locked
public isLocked ( ) : boolean
return boolean

isNewDocument() public method

Is this document a new document
public isNewDocument ( ) : boolean
return boolean

isParentDocumentSet() public method

Is this document a child element of a document set
public isParentDocumentSet ( ) : boolean
return boolean

isReference() public method

Test to see if a document is a reference in this document
public isReference ( Shanty_Mongo_Document $document ) : boolean
$document Shanty_Mongo_Document
return boolean

isRootDocument() public method

Is this document a root document
public isRootDocument ( ) : boolean
return boolean

isValid() public method

Test if a value is valid against a property
public isValid ( String $property, boolean $value )
$property String
$value boolean

loadRequirements() public method

Load the requirements as validators or filters for a given property, and cache them as validators or filters, respectively.
public loadRequirements ( String $property ) : boolean
$property String Name of property
return boolean whether or not cache was used.

offsetExists() public method

Test to see if an offset exists
public offsetExists ( string $offset )
$offset string

offsetGet() public method

Get an offset
public offsetGet ( string $offset ) : mixed
$offset string
return mixed

offsetSet() public method

set an offset
public offsetSet ( string $offset, mixed $value )
$offset string
$value mixed

offsetUnset() public method

Unset a property
public offsetUnset ( string $offset )
$offset string

pop() public method

* Removes an element from an array
public pop ( $property, $value )
$property
$value

postDelete() protected method

protected postDelete ( )

postInsert() protected method

protected postInsert ( )

postSave() protected method

protected postSave ( )

postUpdate() protected method

protected postUpdate ( )

preDelete() protected method

protected preDelete ( )

preInsert() protected method

protected preInsert ( )

preSave() protected method

protected preSave ( )

preUpdate() protected method

protected preUpdate ( )

processChanges() public method

Convert data changes into operations
public processChanges ( array $data = [] )
$data array

pull() public method

Pull all occurrences a value from an array
public pull ( string $property, mixed $value )
$property string
$value mixed

purgeOperations() public method

Remove all operations
public purgeOperations ( boolean $includingChildren = false )
$includingChildren boolean Remove operations from children as wells

push() public method

Push a value to a property
public push ( string $property = null, mixed $value = null )
$property string
$value mixed

removeIgnoredProperties() public method

Removes any properties that have been flagged as ignore in properties.
Author: Tom Holder
public removeIgnoredProperties ( &$exportData ) : void
return void

removeRequirement() public method

Remove a requirement from a property
public removeRequirement ( string $property, string $requirement )
$property string
$requirement string

save() public method

Save this document
public save ( boolean $entierDocument = false, boolean $safe = true ) : boolean
$entierDocument boolean Force the saving of the entier document, instead of just the changes
$safe boolean If FALSE, the program continues executing without waiting for a database response. If TRUE, the program will wait for the database response and throw a MongoCursorException if the update did not succeed
return boolean Result of save

saveUnsafe() public method

Save this document without waiting for a response from the server
public saveUnsafe ( boolean $entierDocument = false ) : boolean
$entierDocument boolean Force the saving of the entier document, instead of just the changes
return boolean Result of save

setConfigAttribute() public method

Set a config attribute
public setConfigAttribute ( string $attribute, unknown_type $value )
$attribute string
$value unknown_type

setCriteria() public method

Add criteria
public setCriteria ( string $property = null, $value = null )
$property string

setId() public method

Set this document's id
public setId ( MongoId $id ) : MongoId
$id MongoId
return MongoId

setPathToDocument() public method

Set the path to this document from the root document
public setPathToDocument ( unknown_type $path )
$path unknown_type

setProperty() public method

Set a property
public setProperty ( mixed $property, mixed $value )
$property mixed
$value mixed

Property Details

$_cleanData protected_oe property

protected $_cleanData

$_config protected_oe property

protected $_config

$_data protected_oe property

protected $_data

$_docRequirements protected_oe property

protected $_docRequirements

$_filters protected_oe property

protected $_filters

$_operations protected_oe property

protected $_operations

$_references protected_oe property

protected $_references

$_requirements protected_oe static_oe property

protected static $_requirements

$_validators protected_oe property

protected $_validators