コード例 #1
0
 private function addDependencies(ClassMetadataProxy $class, CommitOrderCalculator $calc)
 {
     foreach ($class->origFieldMappings as $mapping) {
         $isOwningReference = isset($mapping['reference']) && $mapping['isOwningSide'];
         $isAssociation = isset($mapping['embedded']) || $isOwningReference;
         if (!$isAssociation || !isset($mapping['targetDocument'])) {
             continue;
         }
         $targetClass = $this->objectManager->getClassMetadata($mapping['targetDocument']);
         if (!$calc->hasClass($targetClass->name)) {
             $calc->addClass($targetClass);
         }
         $calc->addDependency($targetClass, $class);
         // If the target class has mapped subclasses, these share the same dependency.
         if (!$targetClass->subClasses) {
             continue;
         }
         $newNodes = array();
         foreach ($targetClass->subClasses as $subClassName) {
             $targetSubClass = $this->objectManager->getClassMetadata($subClassName);
             if (!$calc->hasClass($subClassName)) {
                 $calc->addClass($targetSubClass);
                 $newNodes[] = $targetSubClass;
             }
             $calc->addDependency($targetSubClass, $class);
         }
         // avoid infinite recursion
         if ($class !== $targetClass) {
             $this->addDependencies($targetClass, $calc);
         }
     }
 }
コード例 #2
0
ファイル: UnitOfWork.php プロジェクト: nextmotion/mongodb-odm
 /**
  * Add dependencies recursively through embedded documents. Embedded documents
  * may have references to other documents so those need to be saved first.
  *
  * @param ClassMetadata $class
  * @param CommitOrderCalculator $calc
  */
 private function addDependencies(ClassMetadata $class, $calc)
 {
     foreach ($class->fieldMappings as $mapping) {
         if ($mapping['isOwningSide'] && isset($mapping['reference']) && isset($mapping['targetDocument'])) {
             $targetClass = $this->dm->getClassMetadata($mapping['targetDocument']);
             if (!$calc->hasClass($targetClass->name)) {
                 $calc->addClass($targetClass);
             }
             if (!$calc->hasDependency($targetClass, $class)) {
                 $calc->addDependency($targetClass, $class);
             }
         }
         if (isset($mapping['embedded']) && isset($mapping['targetDocument'])) {
             $targetClass = $this->dm->getClassMetadata($mapping['targetDocument']);
             if (!$calc->hasClass($targetClass->name)) {
                 $calc->addClass($targetClass);
             }
             if (!$calc->hasDependency($targetClass, $class)) {
                 $calc->addDependency($targetClass, $class);
             }
             // avoid infinite recursion
             if ($class != $targetClass) {
                 $this->addDependencies($targetClass, $calc);
             }
         }
     }
 }
コード例 #3
0
 /**
  * Add dependencies recursively through embedded documents. Embedded documents
  * may have references to other documents so those need to be saved first.
  *
  * @param ClassMetadata $class
  * @param CommitOrderCalculator $calc
  */
 private function _addDependencies($class, $calc)
 {
     foreach ($class->fieldMappings as $mapping) {
         if (isset($mapping['reference'])) {
             $targetClass = $this->_dm->getClassMetadata($mapping['targetDocument']);
             if (!$calc->hasClass($targetClass->name)) {
                 $calc->addClass($targetClass);
             }
             if (!$calc->hasDependency($targetClass, $class)) {
                 $calc->addDependency($targetClass, $class);
             }
         }
         if (isset($mapping['embedded'])) {
             $targetClass = $this->_dm->getClassMetadata($mapping['targetDocument']);
             if (!$calc->hasClass($targetClass->name)) {
                 $calc->addClass($targetClass);
             }
             if (!$calc->hasDependency($targetClass, $class)) {
                 $calc->addDependency($targetClass, $class);
             }
             $this->_addDependencies($targetClass, $calc);
         }
     }
 }