PHP Class Doctrine\ODM\MongoDB\Persisters\DocumentPersister

Since: 1.0
Author: Jonathan H. Wage ([email protected])
Author: Bulat Shakirzyanov ([email protected])
Show file Open project: pmjones/php-framework-benchmarks Class Usage Examples

Public Methods

Method Description
__construct ( PersistenceBuilder $pb, DocumentManager $dm, ClassMetadata $class ) Initializes a new DocumentPersister instance.
addInsert ( object $document ) Adds a document to the queued insertions.
delete ( mixed $document, array $options = [] ) Removes document from mongo
executeInserts ( array $options = [] ) : array Executes all queued document insertions and returns any generated post-insert identifiers that were created as a result of the insertions.
exists ( object $document ) : boolean Checks whether the given managed document exists in the database.
getClassMetadata ( ) : ClassMetadata Gets the ClassMetadata instance of the document class this persister is used for.
load ( array $criteria, object $document = null, array $hints = [], integer $lockMode ) : object Loads an document by a list of field criteria.
loadAll ( array $criteria = [] ) : array Loads a list of documents by a list of field criteria.
loadCollection ( PersistentCollection $collection )
lock ( object $document, integer $lockMode ) Locks document by storing the lock mode on the mapped lock field.
prepareQuery ( string | array $query ) : array Prepares a query and converts values to the types mongodb expects.
refresh ( array $id, object $document ) Refreshes a managed document.
unlock ( object $document ) Releases any lock that exists on this document.
update ( object $document, array $options = [] ) Updates the already persisted document if it has any new changesets.

Private Methods

Method Description
createDocument ( $result, object $document = null, array $hints = [] ) : object Creates or fills a single document object from an query result.
getClassDiscriminatorValues ( ClassMetadata $metadata ) : array Gets the array of discriminator values for the given ClassMetadata
prepareWhereValue ( string &$fieldName, string $value ) : string Prepare where values converting document object field names to the document collection field name.

Method Details

__construct() public method

Initializes a new DocumentPersister instance.
public __construct ( PersistenceBuilder $pb, DocumentManager $dm, ClassMetadata $class )
$pb PersistenceBuilder
$dm Doctrine\ODM\MongoDB\DocumentManager
$class Doctrine\ODM\MongoDB\Mapping\ClassMetadata

addInsert() public method

The document remains queued until {@link executeInserts} is invoked.
public addInsert ( object $document )
$document object The document to queue for insertion.

delete() public method

Removes document from mongo
public delete ( mixed $document, array $options = [] )
$document mixed
$options array Array of options to be used with remove()

executeInserts() public method

If no inserts are queued, invoking this method is a NOOP.
public executeInserts ( array $options = [] ) : array
$options array Array of options to be used with batchInsert()
return array An array of any generated post-insert IDs. This will be an empty array if the document class does not use the IDENTITY generation strategy.

exists() public method

Checks whether the given managed document exists in the database.
public exists ( object $document ) : boolean
$document object
return boolean TRUE if the document exists in the database, FALSE otherwise.

getClassMetadata() public method

Gets the ClassMetadata instance of the document class this persister is used for.
public getClassMetadata ( ) : ClassMetadata
return Doctrine\ODM\MongoDB\Mapping\ClassMetadata

load() public method

Loads an document by a list of field criteria.
public load ( array $criteria, object $document = null, array $hints = [], integer $lockMode ) : object
$criteria array The criteria by which to load the document.
$document object The document to load the data into. If not specified, a new document is created.
$hints array Hints for document creation.
$lockMode integer
return object The loaded and managed document instance or NULL if the document can not be found.

loadAll() public method

Loads a list of documents by a list of field criteria.
public loadAll ( array $criteria = [] ) : array
$criteria array
return array

loadCollection() public method

public loadCollection ( PersistentCollection $collection )
$collection Doctrine\ODM\MongoDB\PersistentCollection

lock() public method

Locks document by storing the lock mode on the mapped lock field.
public lock ( object $document, integer $lockMode )
$document object
$lockMode integer

prepareQuery() public method

Prepares a query and converts values to the types mongodb expects.
public prepareQuery ( string | array $query ) : array
$query string | array
return array $query

refresh() public method

Refreshes a managed document.
public refresh ( array $id, object $document )
$id array The identifier of the document.
$document object The document to refresh.

unlock() public method

Releases any lock that exists on this document.
public unlock ( object $document )
$document object

update() public method

Updates the already persisted document if it has any new changesets.
public update ( object $document, array $options = [] )
$document object
$options array Array of options to be used with update()