/**
  * Create a new repository instance for a document class.
  *
  * @param DocumentManager $documentManager The DocumentManager instance.
  * @param string          $documentName    The name of the document.
  *
  * @return \Doctrine\Common\Persistence\ObjectRepository
  */
 protected function createRepository(DocumentManager $documentManager, $documentName)
 {
     $metadata = $documentManager->getClassMetadata($documentName);
     $repositoryClassName = $metadata->customRepositoryClassName;
     if ($repositoryClassName === null) {
         $configuration = $documentManager->getConfiguration();
         $repositoryClassName = $configuration->getDefaultRepositoryClassName();
     }
     return new $repositoryClassName($documentManager, $documentManager->getUnitOfWork(), $metadata);
 }
示例#2
0
 /**
  * Commits the UnitOfWork, executing all operations that have been postponed
  * up to this point. The state of all managed documents will be synchronized with
  * the database.
  *
  * The operations are executed in the following order:
  *
  * 1) All document insertions
  * 2) All document updates
  * 3) All document deletions
  *
  * @param object $document
  * @param array $options Array of options to be used with batchInsert(), update() and remove()
  */
 public function commit($document = null, array $options = array())
 {
     // Raise preFlush
     if ($this->evm->hasListeners(Events::preFlush)) {
         $this->evm->dispatchEvent(Events::preFlush, new Event\PreFlushEventArgs($this->dm));
     }
     $defaultOptions = $this->dm->getConfiguration()->getDefaultCommitOptions();
     if ($options) {
         $options = array_merge($defaultOptions, $options);
     } else {
         $options = $defaultOptions;
     }
     // Compute changes done since last commit.
     if ($document === null) {
         $this->computeChangeSets();
     } elseif (is_object($document)) {
         $this->computeSingleDocumentChangeSet($document);
     } elseif (is_array($document)) {
         foreach ($document as $object) {
             $this->computeSingleDocumentChangeSet($object);
         }
     }
     if (!($this->documentInsertions || $this->documentUpserts || $this->documentDeletions || $this->documentUpdates || $this->collectionUpdates || $this->collectionDeletions || $this->orphanRemovals)) {
         return;
         // Nothing to do.
     }
     if ($this->orphanRemovals) {
         foreach ($this->orphanRemovals as $removal) {
             $this->remove($removal);
         }
     }
     // Raise onFlush
     if ($this->evm->hasListeners(Events::onFlush)) {
         $this->evm->dispatchEvent(Events::onFlush, new Event\OnFlushEventArgs($this->dm));
     }
     foreach ($this->getClassesForCommitAction($this->documentUpserts) as $classAndDocuments) {
         list($class, $documents) = $classAndDocuments;
         $this->executeUpserts($class, $documents, $options);
     }
     foreach ($this->getClassesForCommitAction($this->documentInsertions) as $classAndDocuments) {
         list($class, $documents) = $classAndDocuments;
         $this->executeInserts($class, $documents, $options);
     }
     foreach ($this->getClassesForCommitAction($this->documentUpdates) as $classAndDocuments) {
         list($class, $documents) = $classAndDocuments;
         $this->executeUpdates($class, $documents, $options);
     }
     foreach ($this->getClassesForCommitAction($this->documentDeletions, true) as $classAndDocuments) {
         list($class, $documents) = $classAndDocuments;
         $this->executeDeletions($class, $documents, $options);
     }
     // Raise postFlush
     if ($this->evm->hasListeners(Events::postFlush)) {
         $this->evm->dispatchEvent(Events::postFlush, new Event\PostFlushEventArgs($this->dm));
     }
     // Clear up
     $this->documentInsertions = $this->documentUpserts = $this->documentUpdates = $this->documentDeletions = $this->documentChangeSets = $this->collectionUpdates = $this->collectionDeletions = $this->visitedCollections = $this->scheduledForDirtyCheck = $this->orphanRemovals = $this->hasScheduledCollections = array();
 }
示例#3
0
 /**
  * Constructor.
  *
  * @param DocumentManager $dm
  * @param CriteriaMerger  $cm
  */
 public function __construct(DocumentManager $dm, CriteriaMerger $cm = null)
 {
     $this->dm = $dm;
     $this->cm = $cm ?: new CriteriaMerger();
     $this->config = $dm->getConfiguration();
 }