PHP Class Doctrine\ODM\MongoDB\DocumentManager

Since: 1.0
Author: Jonathan H. Wage ([email protected])
Author: Roman Borschel ([email protected])
显示文件 Open project: doctrine/mongodb-odm Class Usage Examples

Public Methods

Method Description
clear ( string | null $documentName = null ) Clears the DocumentManager.
close ( ) Closes the DocumentManager. All documents that are currently managed by this DocumentManager become detached. The DocumentManager may no longer be used after it is closed.
contains ( object $document ) : boolean Determines whether a document instance is managed in this DocumentManager.
create ( Connection $conn = null, Configuration $config = null, Doctrine\Common\EventManager $eventManager = null ) : DocumentManager Creates a new Document that operates on the given Mongo connection and uses the given Configuration.
createAggregationBuilder ( string $documentName ) : Builder Creates a new aggregation builder instance for a class.
createDBRef ( mixed $document, array $referenceMapping = null ) : array Returns a DBRef array for the supplied document.
createQueryBuilder ( string $documentName = null ) : Query\Builder Create a new Query instance for a class.
detach ( object $document ) Detaches a document from the DocumentManager, causing a managed document to become detached. Unflushed changes made to the document if any (including removal of the document), will not be synchronized to the database.
find ( string $documentName, mixed $identifier, integer $lockMode = LockMode::NONE, integer $lockVersion = null ) : object Finds a Document by its identifier.
flush ( object $document = null, array $options = [] ) Flushes all changes to objects that have been queued up to now to the database.
getClassMetadata ( string $className ) : ClassMetadata Returns the metadata for a class.
getConfiguration ( ) : Configuration Gets the Configuration used by the DocumentManager.
getConnection ( ) : Connection Gets the PHP Mongo instance that this DocumentManager wraps.
getDocumentCollection ( string $className ) : Doctrine\MongoDB\Collection Returns the MongoCollection instance for a class.
getDocumentCollections ( ) : array Gets the array of instantiated document collection instances.
getDocumentDatabase ( string $className ) : Doctrine\MongoDB\Database Returns the MongoDB instance for a class.
getDocumentDatabases ( ) : array Gets the array of instantiated document database instances.
getEventManager ( ) : Doctrine\Common\EventManager Gets the EventManager used by the DocumentManager.
getFilterCollection ( ) : Doctrine\ODM\MongoDB\Query\FilterCollection Gets the filter collection.
getHydratorFactory ( ) : Doctrine\ODM\MongoDB\Hydrator\HydratorInterface Gets the Hydrator factory used by the DocumentManager to generate and get hydrators for each type of document.
getMetadataFactory ( ) : ClassMetadataFactory Gets the metadata factory used to gather the metadata of classes.
getPartialReference ( string $documentName, mixed $identifier ) : object Gets a partial reference to the document identified by the given type and identifier without actually loading it, if the document is not yet loaded.
getProxyFactory ( ) : ProxyFactory Gets the proxy factory used by the DocumentManager to create document proxies.
getReference ( string $documentName, string | object $identifier ) : mixed | object Gets a reference to the document identified by the given type and identifier without actually loading it.
getRepository ( string $documentName ) : DocumentRepository Gets the repository for a document class.
getSchemaManager ( ) : SchemaManager Returns SchemaManager, used to create/drop indexes/collections/databases.
getUnitOfWork ( ) : UnitOfWork Gets the UnitOfWork used by the DocumentManager to coordinate operations.
initializeObject ( object $obj ) Helper method to initialize a lazy loading proxy or persistent collection.
isOpen ( ) : boolean Check if the Document manager is open or closed.
lock ( object $document, integer $lockMode, integer $lockVersion = null ) Acquire a lock on the given document.
merge ( object $document ) : object Merges the state of a detached document into the persistence context of this DocumentManager and returns the managed copy of the document.
persist ( object $document ) Tells the DocumentManager to make an instance managed and persistent.
refresh ( object $document ) Refreshes the persistent state of a document from the database, overriding any local changes that have not yet been persisted.
remove ( object $document ) Removes a document instance.
unlock ( object $document ) Releases a lock on the given document.

Protected Methods

Method Description
__construct ( Connection $conn = null, Configuration $config = null, Doctrine\Common\EventManager $eventManager = null ) Creates a new Document that operates on the given Mongo connection and uses the given Configuration.

Private Methods

Method Description
errorIfClosed ( ) Throws an exception if the DocumentManager is closed or currently not active.

Method Details

__construct() protected method

Creates a new Document that operates on the given Mongo connection and uses the given Configuration.
protected __construct ( Connection $conn = null, Configuration $config = null, Doctrine\Common\EventManager $eventManager = null )
$conn Doctrine\MongoDB\Connection
$config Configuration
$eventManager Doctrine\Common\EventManager

clear() public method

All documents that are currently managed by this DocumentManager become detached.
public clear ( string | null $documentName = null )
$documentName string | null if given, only documents of this type will get detached

close() public method

Closes the DocumentManager. All documents that are currently managed by this DocumentManager become detached. The DocumentManager may no longer be used after it is closed.
public close ( )

contains() public method

Determines whether a document instance is managed in this DocumentManager.
public contains ( object $document ) : boolean
$document object
return boolean TRUE if this DocumentManager currently manages the given document, FALSE otherwise.

create() public static method

Creates a new Document that operates on the given Mongo connection and uses the given Configuration.
public static create ( Connection $conn = null, Configuration $config = null, Doctrine\Common\EventManager $eventManager = null ) : DocumentManager
$conn Doctrine\MongoDB\Connection
$config Configuration
$eventManager Doctrine\Common\EventManager
return DocumentManager

createAggregationBuilder() public method

Creates a new aggregation builder instance for a class.
public createAggregationBuilder ( string $documentName ) : Builder
$documentName string The document class name.
return Doctrine\ODM\MongoDB\Aggregation\Builder

createDBRef() public method

Returns a DBRef array for the supplied document.
public createDBRef ( mixed $document, array $referenceMapping = null ) : array
$document mixed A document object
$referenceMapping array Mapping for the field that references the document
return array A DBRef array

createQueryBuilder() public method

Create a new Query instance for a class.
public createQueryBuilder ( string $documentName = null ) : Query\Builder
$documentName string The document class name.
return Query\Builder

detach() public method

Documents which previously referenced the detached document will continue to reference it.
public detach ( object $document )
$document object The document to detach.

find() public method

This is just a convenient shortcut for getRepository($documentName)->find($id).
public find ( string $documentName, mixed $identifier, integer $lockMode = LockMode::NONE, integer $lockVersion = null ) : object
$documentName string
$identifier mixed
$lockMode integer
$lockVersion integer
return object $document

flush() public method

This effectively synchronizes the in-memory state of managed objects with the database.
public flush ( object $document = null, array $options = [] )
$document object
$options array Array of options to be used with batchInsert(), update() and remove()

getClassMetadata() public method

Returns the metadata for a class.
public getClassMetadata ( string $className ) : ClassMetadata
$className string The class name.
return Doctrine\ODM\MongoDB\Mapping\ClassMetadata

getConfiguration() public method

Gets the Configuration used by the DocumentManager.
public getConfiguration ( ) : Configuration
return Configuration

getConnection() public method

Gets the PHP Mongo instance that this DocumentManager wraps.
public getConnection ( ) : Connection
return Doctrine\MongoDB\Connection

getDocumentCollection() public method

Returns the MongoCollection instance for a class.
public getDocumentCollection ( string $className ) : Doctrine\MongoDB\Collection
$className string The class name.
return Doctrine\MongoDB\Collection

getDocumentCollections() public method

Gets the array of instantiated document collection instances.
public getDocumentCollections ( ) : array
return array

getDocumentDatabase() public method

Returns the MongoDB instance for a class.
public getDocumentDatabase ( string $className ) : Doctrine\MongoDB\Database
$className string The class name.
return Doctrine\MongoDB\Database

getDocumentDatabases() public method

Gets the array of instantiated document database instances.
public getDocumentDatabases ( ) : array
return array

getEventManager() public method

Gets the EventManager used by the DocumentManager.
public getEventManager ( ) : Doctrine\Common\EventManager
return Doctrine\Common\EventManager

getFilterCollection() public method

Gets the filter collection.
public getFilterCollection ( ) : Doctrine\ODM\MongoDB\Query\FilterCollection
return Doctrine\ODM\MongoDB\Query\FilterCollection The active filter collection.

getHydratorFactory() public method

Gets the Hydrator factory used by the DocumentManager to generate and get hydrators for each type of document.
public getHydratorFactory ( ) : Doctrine\ODM\MongoDB\Hydrator\HydratorInterface
return Doctrine\ODM\MongoDB\Hydrator\HydratorInterface

getMetadataFactory() public method

Gets the metadata factory used to gather the metadata of classes.
public getMetadataFactory ( ) : ClassMetadataFactory
return Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory

getPartialReference() public method

The returned reference may be a partial object if the document is not yet loaded/managed. If it is a partial object it will not initialize the rest of the document state on access. Thus you can only ever safely access the identifier of a document obtained through this method. The use-cases for partial references involve maintaining bidirectional associations without loading one side of the association or to update a document without loading it. Note, however, that in the latter case the original (persistent) document data will never be visible to the application (especially not event listeners) as it will never be loaded in the first place.
public getPartialReference ( string $documentName, mixed $identifier ) : object
$documentName string The name of the document type.
$identifier mixed The document identifier.
return object The (partial) document reference.

getProxyFactory() public method

Gets the proxy factory used by the DocumentManager to create document proxies.
public getProxyFactory ( ) : ProxyFactory
return Doctrine\ODM\MongoDB\Proxy\ProxyFactory

getReference() public method

If partial objects are allowed, this method will return a partial object that only has its identifier populated. Otherwise a proxy is returned that automatically loads itself on first access.
public getReference ( string $documentName, string | object $identifier ) : mixed | object
$documentName string
$identifier string | object
return mixed | object The document reference.

getRepository() public method

Gets the repository for a document class.
public getRepository ( string $documentName ) : DocumentRepository
$documentName string The name of the Document.
return DocumentRepository The repository.

getSchemaManager() public method

Returns SchemaManager, used to create/drop indexes/collections/databases.
public getSchemaManager ( ) : SchemaManager
return SchemaManager

getUnitOfWork() public method

Gets the UnitOfWork used by the DocumentManager to coordinate operations.
public getUnitOfWork ( ) : UnitOfWork
return UnitOfWork

initializeObject() public method

This method is a no-op for other objects.
public initializeObject ( object $obj )
$obj object

isOpen() public method

Check if the Document manager is open or closed.
public isOpen ( ) : boolean
return boolean

lock() public method

Acquire a lock on the given document.
public lock ( object $document, integer $lockMode, integer $lockVersion = null )
$document object
$lockMode integer
$lockVersion integer

merge() public method

The document passed to merge will not become associated/managed with this DocumentManager.
public merge ( object $document ) : object
$document object The detached document to merge into the persistence context.
return object The managed copy of the document.

persist() public method

The document will be entered into the database at or before transaction commit or as a result of the flush operation. NOTE: The persist operation always considers documents that are not yet known to this DocumentManager as NEW. Do not pass detached documents to the persist operation.
public persist ( object $document )
$document object The instance to make managed and persistent.

refresh() public method

Refreshes the persistent state of a document from the database, overriding any local changes that have not yet been persisted.
public refresh ( object $document )
$document object The document to refresh.

remove() public method

A removed document will be removed from the database at or before transaction commit or as a result of the flush operation.
public remove ( object $document )
$document object The document instance to remove.

unlock() public method

Releases a lock on the given document.
public unlock ( object $document )
$document object