当前位置: 首页>>代码示例>>PHP>>正文


PHP ClassMetadata::mapManyToMany方法代码示例

本文整理汇总了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::mapManyToMany方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::mapManyToMany方法的具体用法?PHP ClassMetadata::mapManyToMany怎么用?PHP ClassMetadata::mapManyToMany使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\Common\Persistence\Mapping\ClassMetadata的用法示例。


在下文中一共展示了ClassMetadata::mapManyToMany方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: mapManyToMany

 private function mapManyToMany(ClassMetadata $metadata)
 {
     foreach ($this->variables as $variable => $class) {
         if ($class['variant']['model'] !== $metadata->getName()) {
             continue;
         }
         $metadata->mapManyToOne(array('fieldName' => 'object', 'targetEntity' => $class['variable'], 'inversedBy' => 'variants', 'joinColumns' => array(array('name' => $variable . '_id', 'referencedColumnName' => 'id', 'nullable' => false, 'onDelete' => 'CASCADE'))));
         $metadata->mapManyToMany(array('fieldName' => 'options', 'type' => ClassMetadataInfo::MANY_TO_MANY, 'targetEntity' => $class['option_value']['model'], 'joinTable' => array('name' => sprintf('sylius_%s_variant_option_value', $variable), 'joinColumns' => array(array('name' => 'variant_id', 'referencedColumnName' => 'id', 'unique' => false, 'nullable' => false, 'onDelete' => 'CASCADE')), 'inverseJoinColumns' => array(array('name' => 'option_value_id', 'referencedColumnName' => 'id', 'unique' => false, 'nullable' => false, 'onDelete' => 'CASCADE')))));
     }
 }
开发者ID:bcremer,项目名称:Sylius,代码行数:10,代码来源:LoadMetadataSubscriber.php

示例2: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string        $className
  * @param ClassMetadata $metadata
  *
  * @return void
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $originClassName = $className;
     $originMetadata = $this->em->getClassMetadata('Opifer\\ContentBundle\\Entity\\ListBlock');
     //
     //        $metadata->name = self::REVISION_ENTITY; //. '' . str_replace('\\', '', $class->name);
     //        $class->rootEntityName = $class->name;
     //        $class->namespace = 'Opifer\\Revisions\\Entity';
     //
     //        $class->discriminatorMap = null;
     //        $class->discriminatorColumn = null;
     $metadata->setPrimaryTable(['name' => $originMetadata->getTableName() . '_revisions']);
     foreach ($originMetadata->fieldMappings as $key => $fieldMapping) {
         $fieldMapping['inherited'] = self::REVISION_ENTITY;
         $fieldMapping['declared'] = self::REVISION_ENTITY;
         if ($this->annotationReader->isPropertyRevised($originClassName, $fieldMapping['fieldName'])) {
             $metadata->mapField($fieldMapping);
         }
     }
     foreach ($originMetadata->associationMappings as $key => $associationMapping) {
         $associationMapping['inherited'] = self::REVISION_ENTITY;
         $associationMapping['declared'] = self::REVISION_ENTITY;
         if ($this->annotationReader->isPropertyRevised($originClassName, $associationMapping['fieldName'])) {
             if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_ONE) {
                 $metadata->mapOneToOne($associationMapping);
             } else {
                 if ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_ONE) {
                     $metadata->mapManyToOne($associationMapping);
                 } else {
                     if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_MANY) {
                         $metadata->mapOneToMany($associationMapping);
                     } else {
                         if ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_MANY) {
                             $metadata->mapManyToMany($associationMapping);
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:opifer,项目名称:revisions,代码行数:49,代码来源:RevisionMetadataDriver.php

示例3: loadMetadataForClass


//.........这里部分代码省略.........
         foreach ($xmlRoot->{'many-to-many'} as $manyToManyElement) {
             $mapping = array('fieldName' => (string) $manyToManyElement['field'], 'targetEntity' => (string) $manyToManyElement['target-entity']);
             if (isset($manyToManyElement['fetch'])) {
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . (string) $manyToManyElement['fetch']);
             }
             if (isset($manyToManyElement['orphan-removal'])) {
                 $mapping['orphanRemoval'] = $this->evaluateBoolean($manyToManyElement['orphan-removal']);
             }
             if (isset($manyToManyElement['mapped-by'])) {
                 $mapping['mappedBy'] = (string) $manyToManyElement['mapped-by'];
             } else {
                 if (isset($manyToManyElement->{'join-table'})) {
                     if (isset($manyToManyElement['inversed-by'])) {
                         $mapping['inversedBy'] = (string) $manyToManyElement['inversed-by'];
                     }
                     $joinTableElement = $manyToManyElement->{'join-table'};
                     $joinTable = array('name' => (string) $joinTableElement['name']);
                     if (isset($joinTableElement['schema'])) {
                         $joinTable['schema'] = (string) $joinTableElement['schema'];
                     }
                     foreach ($joinTableElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
                         $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement);
                     }
                     foreach ($joinTableElement->{'inverse-join-columns'}->{'join-column'} as $joinColumnElement) {
                         $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumnElement);
                     }
                     $mapping['joinTable'] = $joinTable;
                 }
             }
             if (isset($manyToManyElement->cascade)) {
                 $mapping['cascade'] = $this->_getCascadeMappings($manyToManyElement->cascade);
             }
             if (isset($manyToManyElement->{'order-by'})) {
                 $orderBy = array();
                 foreach ($manyToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) {
                     $orderBy[(string) $orderByField['name']] = (string) $orderByField['direction'];
                 }
                 $mapping['orderBy'] = $orderBy;
             }
             if (isset($manyToManyElement['index-by'])) {
                 $mapping['indexBy'] = (string) $manyToManyElement['index-by'];
             } else {
                 if (isset($manyToManyElement->{'index-by'})) {
                     throw new \InvalidArgumentException("<index-by /> is not a valid tag");
                 }
             }
             $metadata->mapManyToMany($mapping);
         }
     }
     // Evaluate association-overrides
     if (isset($xmlRoot->{'attribute-overrides'})) {
         foreach ($xmlRoot->{'attribute-overrides'}->{'attribute-override'} as $overrideElement) {
             $fieldName = (string) $overrideElement['name'];
             foreach ($overrideElement->field as $field) {
                 $mapping = $this->columnToArray($field);
                 $mapping['fieldName'] = $fieldName;
                 $metadata->setAttributeOverride($fieldName, $mapping);
             }
         }
     }
     // Evaluate association-overrides
     if (isset($xmlRoot->{'association-overrides'})) {
         foreach ($xmlRoot->{'association-overrides'}->{'association-override'} as $overrideElement) {
             $fieldName = (string) $overrideElement['name'];
             $override = array();
             // Check for join-columns
             if (isset($overrideElement->{'join-columns'})) {
                 $joinColumns = array();
                 foreach ($overrideElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
                     $joinColumns[] = $this->joinColumnToArray($joinColumnElement);
                 }
                 $override['joinColumns'] = $joinColumns;
             }
             // Check for join-table
             if ($overrideElement->{'join-table'}) {
                 $joinTable = null;
                 $joinTableElement = $overrideElement->{'join-table'};
                 $joinTable = array('name' => (string) $joinTableElement['name'], 'schema' => (string) $joinTableElement['schema']);
                 if (isset($joinTableElement->{'join-columns'})) {
                     foreach ($joinTableElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
                         $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement);
                     }
                 }
                 if (isset($joinTableElement->{'inverse-join-columns'})) {
                     foreach ($joinTableElement->{'inverse-join-columns'}->{'join-column'} as $joinColumnElement) {
                         $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumnElement);
                     }
                 }
                 $override['joinTable'] = $joinTable;
             }
             $metadata->setAssociationOverride($fieldName, $override);
         }
     }
     // Evaluate <lifecycle-callbacks...>
     if (isset($xmlRoot->{'lifecycle-callbacks'})) {
         foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) {
             $metadata->addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\\ORM\\Events::' . (string) $lifecycleCallback['type']));
         }
     }
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:101,代码来源:XmlDriver.php

示例4: loadMetadataForClass


//.........这里部分代码省略.........
                     if ($manyToOneAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToOne')) {
                         if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
                             $mapping['id'] = true;
                         }
                         $mapping['joinColumns'] = $joinColumns;
                         $mapping['cascade'] = $manyToOneAnnot->cascade;
                         $mapping['inversedBy'] = $manyToOneAnnot->inversedBy;
                         $mapping['targetEntity'] = $manyToOneAnnot->targetEntity;
                         $mapping['fetch'] = $this->getFetchMode($className, $manyToOneAnnot->fetch);
                         $metadata->mapManyToOne($mapping);
                     } else {
                         if ($manyToManyAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToMany')) {
                             $joinTable = array();
                             if ($joinTableAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinTable')) {
                                 $joinTable = array('name' => $joinTableAnnot->name, 'schema' => $joinTableAnnot->schema);
                                 foreach ($joinTableAnnot->joinColumns as $joinColumn) {
                                     $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumn);
                                 }
                                 foreach ($joinTableAnnot->inverseJoinColumns as $joinColumn) {
                                     $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumn);
                                 }
                             }
                             $mapping['joinTable'] = $joinTable;
                             $mapping['targetEntity'] = $manyToManyAnnot->targetEntity;
                             $mapping['mappedBy'] = $manyToManyAnnot->mappedBy;
                             $mapping['inversedBy'] = $manyToManyAnnot->inversedBy;
                             $mapping['cascade'] = $manyToManyAnnot->cascade;
                             $mapping['indexBy'] = $manyToManyAnnot->indexBy;
                             $mapping['orphanRemoval'] = $manyToManyAnnot->orphanRemoval;
                             $mapping['fetch'] = $this->getFetchMode($className, $manyToManyAnnot->fetch);
                             if ($orderByAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OrderBy')) {
                                 $mapping['orderBy'] = $orderByAnnot->value;
                             }
                             $metadata->mapManyToMany($mapping);
                         } else {
                             if ($embeddedAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Embedded')) {
                                 $mapping['class'] = $embeddedAnnot->class;
                                 $mapping['columnPrefix'] = $embeddedAnnot->columnPrefix;
                                 $metadata->mapEmbedded($mapping);
                             }
                         }
                     }
                 }
             }
         }
     }
     // Evaluate AssociationOverrides annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\AssociationOverrides'])) {
         $associationOverridesAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\AssociationOverrides'];
         foreach ($associationOverridesAnnot->value as $associationOverride) {
             $override = array();
             $fieldName = $associationOverride->name;
             // Check for JoinColumn/JoinColumns annotations
             if ($associationOverride->joinColumns) {
                 $joinColumns = array();
                 foreach ($associationOverride->joinColumns as $joinColumn) {
                     $joinColumns[] = $this->joinColumnToArray($joinColumn);
                 }
                 $override['joinColumns'] = $joinColumns;
             }
             // Check for JoinTable annotations
             if ($associationOverride->joinTable) {
                 $joinTableAnnot = $associationOverride->joinTable;
                 $joinTable = array('name' => $joinTableAnnot->name, 'schema' => $joinTableAnnot->schema);
                 foreach ($joinTableAnnot->joinColumns as $joinColumn) {
                     $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumn);
开发者ID:aschempp,项目名称:doctrine2,代码行数:67,代码来源:AnnotationDriver.php

示例5: loadMetadataForClass


//.........这里部分代码省略.........
                         foreach ($joinTableElement['joinColumns'] as $joinColumnName => $joinColumnElement) {
                             if (!isset($joinColumnElement['name'])) {
                                 $joinColumnElement['name'] = $joinColumnName;
                             }
                         }
                         $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement);
                     }
                     if (isset($joinTableElement['inverseJoinColumns'])) {
                         foreach ($joinTableElement['inverseJoinColumns'] as $joinColumnName => $joinColumnElement) {
                             if (!isset($joinColumnElement['name'])) {
                                 $joinColumnElement['name'] = $joinColumnName;
                             }
                         }
                         $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumnElement);
                     }
                     $mapping['joinTable'] = $joinTable;
                 }
             }
             if (isset($manyToManyElement['inversedBy'])) {
                 $mapping['inversedBy'] = $manyToManyElement['inversedBy'];
             }
             if (isset($manyToManyElement['cascade'])) {
                 $mapping['cascade'] = $manyToManyElement['cascade'];
             }
             if (isset($manyToManyElement['orderBy'])) {
                 $mapping['orderBy'] = $manyToManyElement['orderBy'];
             }
             if (isset($manyToManyElement['indexBy'])) {
                 $mapping['indexBy'] = $manyToManyElement['indexBy'];
             }
             if (isset($manyToManyElement['orphanRemoval'])) {
                 $mapping['orphanRemoval'] = (bool) $manyToManyElement['orphanRemoval'];
             }
             $metadata->mapManyToMany($mapping);
             // Evaluate second level cache
             if (isset($manyToManyElement['cache'])) {
                 $metadata->enableAssociationCache($mapping['fieldName'], $this->cacheToArray($manyToManyElement['cache']));
             }
         }
     }
     // Evaluate associationOverride
     if (isset($element['associationOverride']) && is_array($element['associationOverride'])) {
         foreach ($element['associationOverride'] as $fieldName => $associationOverrideElement) {
             $override = array();
             // Check for joinColumn
             if (isset($associationOverrideElement['joinColumn'])) {
                 $joinColumns = array();
                 foreach ($associationOverrideElement['joinColumn'] as $name => $joinColumnElement) {
                     if (!isset($joinColumnElement['name'])) {
                         $joinColumnElement['name'] = $name;
                     }
                     $joinColumns[] = $this->joinColumnToArray($joinColumnElement);
                 }
                 $override['joinColumns'] = $joinColumns;
             }
             // Check for joinTable
             if (isset($associationOverrideElement['joinTable'])) {
                 $joinTableElement = $associationOverrideElement['joinTable'];
                 $joinTable = array('name' => $joinTableElement['name']);
                 if (isset($joinTableElement['schema'])) {
                     $joinTable['schema'] = $joinTableElement['schema'];
                 }
                 foreach ($joinTableElement['joinColumns'] as $name => $joinColumnElement) {
                     if (!isset($joinColumnElement['name'])) {
                         $joinColumnElement['name'] = $name;
                     }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:67,代码来源:YamlDriver.php

示例6: mapManyToMany

 /**
  * @param ClassMetadata $metadata
  * @param LoadClassMetadataEventArgs $eventArgs
  */
 private function mapManyToMany(ClassMetadata $metadata, LoadClassMetadataEventArgs $eventArgs)
 {
     $cmf = $eventArgs->getEntityManager()->getMetadataFactory();
     foreach ($this->variables as $variable => $class) {
         if ($class['variant']['model'] !== $metadata->getName()) {
             continue;
         }
         $targetEntity = $class['variable'];
         $targetEntityMetadata = $cmf->getMetadataFor($targetEntity);
         $metadata->mapManyToOne(array('fieldName' => 'object', 'targetEntity' => $class['variable'], 'inversedBy' => 'variants', 'joinColumns' => array(array('name' => $variable . '_id', 'referencedColumnName' => $targetEntityMetadata->fieldMappings['id']['columnName'], 'nullable' => false, 'onDelete' => 'CASCADE'))));
         $targetEntity = $class['option_value']['model'];
         $targetEntityMetadata = $cmf->getMetadataFor($targetEntity);
         $metadata->mapManyToMany(array('fieldName' => 'options', 'type' => ClassMetadataInfo::MANY_TO_MANY, 'targetEntity' => $class['option_value']['model'], 'joinTable' => array('name' => sprintf('sylius_%s_variant_option_value', $variable), 'joinColumns' => array(array('name' => 'variant_id', 'referencedColumnName' => 'id', 'unique' => false, 'nullable' => false, 'onDelete' => 'CASCADE')), 'inverseJoinColumns' => array(array('name' => 'option_value_id', 'referencedColumnName' => $targetEntityMetadata->fieldMappings['id']['columnName'], 'unique' => false, 'nullable' => false, 'onDelete' => 'CASCADE')))));
     }
 }
开发者ID:Onnit,项目名称:Sylius,代码行数:19,代码来源:LoadMetadataSubscriber.php

示例7: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     /** @var $metadata \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */
     $reflClass = $metadata->getReflectionClass();
     $documentAnnots = array();
     foreach ($this->reader->getClassAnnotations($reflClass) as $annot) {
         foreach ($this->entityAnnotationClasses as $annotClass => $i) {
             if ($annot instanceof $annotClass) {
                 $documentAnnots[$i] = $annot;
             }
         }
     }
     if (!$documentAnnots) {
         throw MappingException::classIsNotAValidDocument($className);
     }
     // find the winning document annotation
     ksort($documentAnnots);
     $documentAnnot = reset($documentAnnots);
     if ($documentAnnot instanceof ODM\MappedSuperclass) {
         $metadata->isMappedSuperclass = true;
     }
     if (null !== $documentAnnot->referenceable) {
         $metadata->setReferenceable($documentAnnot->referenceable);
     }
     if (null !== $documentAnnot->versionable) {
         $metadata->setVersioned($documentAnnot->versionable);
     }
     if (null !== $documentAnnot->mixins) {
         $metadata->setMixins($documentAnnot->mixins);
     }
     if (null !== $documentAnnot->inheritMixins) {
         $metadata->setInheritMixins($documentAnnot->inheritMixins);
     }
     if (null !== $documentAnnot->nodeType) {
         $metadata->setNodeType($documentAnnot->nodeType);
     }
     if (null !== $documentAnnot->repositoryClass) {
         $metadata->setCustomRepositoryClassName($documentAnnot->repositoryClass);
     }
     if (null !== $documentAnnot->translator) {
         $metadata->setTranslator($documentAnnot->translator);
     }
     foreach ($reflClass->getProperties() as $property) {
         if ($metadata->isInheritedField($property->name) && $metadata->name !== $property->getDeclaringClass()->getName()) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) {
             if ($fieldAnnot instanceof ODM\Property) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapField($mapping);
             } elseif ($fieldAnnot instanceof ODM\Id) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapId($mapping);
             } elseif ($fieldAnnot instanceof ODM\Node) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapNode($mapping);
             } elseif ($fieldAnnot instanceof ODM\Nodename) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapNodename($mapping);
             } elseif ($fieldAnnot instanceof ODM\ParentDocument) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                 $metadata->mapParentDocument($mapping);
             } elseif ($fieldAnnot instanceof ODM\Child) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                 $metadata->mapChild($mapping);
             } elseif ($fieldAnnot instanceof ODM\Children) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                 $metadata->mapChildren($mapping);
             } elseif ($fieldAnnot instanceof ODM\ReferenceOne) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                 $metadata->mapManyToOne($mapping);
             } elseif ($fieldAnnot instanceof ODM\ReferenceMany) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                 $metadata->mapManyToMany($mapping);
             } elseif ($fieldAnnot instanceof ODM\Referrers) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                 $metadata->mapReferrers($mapping);
             } elseif ($fieldAnnot instanceof ODM\MixedReferrers) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapMixedReferrers($mapping);
             } elseif ($fieldAnnot instanceof ODM\Locale) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapLocale($mapping);
             } elseif ($fieldAnnot instanceof ODM\Depth) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapDepth($mapping);
             } elseif ($fieldAnnot instanceof ODM\VersionName) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapVersionName($mapping);
//.........这里部分代码省略.........
开发者ID:pkdevbox,项目名称:phpcr-odm,代码行数:101,代码来源:AnnotationDriver.php

示例8: addMappingFromReference

 private function addMappingFromReference(ClassMetadata $class, $fieldName, $reference, $type)
 {
     /** @var $class \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */
     $mapping = array_merge(array('fieldName' => $fieldName), $reference);
     $mapping['cascade'] = isset($reference['cascade']) ? $this->getCascadeMode($reference['cascade']) : 0;
     $mapping['name'] = isset($reference['name']) ? $reference['name'] : null;
     if (!isset($mapping['targetDocument'])) {
         $mapping['targetDocument'] = null;
     }
     if ($type === 'many') {
         $class->mapManyToMany($mapping);
     } elseif ($type === 'one') {
         $class->mapManyToOne($mapping);
     }
 }
开发者ID:steffenbrem,项目名称:phpcr-odm,代码行数:15,代码来源:YamlDriver.php

示例9: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $class)
 {
     /** @var $class \Doctrine\ODM\CouchDB\Mapping\ClassMetadata */
     try {
         $element = $this->getElement($className);
     } catch (DoctrineMappingException $e) {
         // Convert Exception type for consistency with other drivers
         throw new MappingException($e->getMessage(), $e->getCode(), $e);
     }
     if (!$element) {
         return;
     }
     if ($element['type'] == 'document') {
         $class->setCustomRepositoryClass(isset($element['repositoryClass']) ? $element['repositoryClass'] : null);
         if (isset($element['indexed']) && $element['indexed'] == true) {
             $class->indexed = true;
         }
         if (isset($element['inheritanceRoot']) && $element['inheritanceRoot']) {
             $class->markInheritanceRoot();
         }
     } else {
         if ($element['type'] == 'embedded') {
             $class->isEmbeddedDocument = true;
             if (isset($element['inheritanceRoot']) && $element['inheritanceRoot']) {
                 $class->markInheritanceRoot();
             }
         } else {
             if (strtolower($element['type']) == "mappedsuperclass") {
                 $class->isMappedSuperclass = true;
             } else {
                 throw MappingException::classIsNotAValidDocument($className);
             }
         }
     }
     if (isset($element['id'])) {
         foreach ($element['id'] as $fieldName => $idElement) {
             $class->mapField(array('fieldName' => $fieldName, 'indexed' => isset($idElement['index']) ? (bool) $idElement['index'] : false, 'type' => isset($idElement['type']) ? $idElement['type'] : null, 'id' => true, 'strategy' => isset($idElement['strategy']) ? $idElement['strategy'] : null));
         }
     }
     if (isset($element['fields'])) {
         foreach ($element['fields'] as $fieldName => $fieldElement) {
             $class->mapField(array('fieldName' => $fieldName, 'jsonName' => isset($fieldElement['jsonName']) ? $fieldElement['jsonName'] : null, 'indexed' => isset($fieldElement['index']) ? (bool) $fieldElement['index'] : false, 'type' => isset($fieldElement['type']) ? $fieldElement['type'] : null, 'isVersionField' => isset($fieldElement['version']) ? true : null));
         }
     }
     if (isset($element['referenceOne'])) {
         foreach ($element['referenceOne'] as $field => $referenceOneElement) {
             $class->mapManyToOne(array('cascade' => isset($referenceOneElement['cascade']) ? $this->getCascadeMode($referenceOneElement['cascade']) : 0, 'targetDocument' => (string) $referenceOneElement['targetDocument'], 'fieldName' => $field, 'jsonName' => isset($referenceOneElement['jsonName']) ? (string) $referenceOneElement['jsonName'] : null, 'indexed' => isset($referenceOneElement['index']) ? (bool) $referenceOneElement['index'] : false));
         }
     }
     if (isset($element['referenceMany'])) {
         foreach ($element['referenceMany'] as $field => $referenceManyElement) {
             $class->mapManyToMany(array('cascade' => isset($referenceManyElement['cascade']) ? $this->getCascadeMode($referenceManyElement['cascade']) : 0, 'targetDocument' => (string) $referenceManyElement['targetDocument'], 'fieldName' => $field, 'jsonName' => isset($referenceManyElement['jsonName']) ? (string) $referenceManyElement['jsonName'] : null, 'mappedBy' => isset($referenceManyElement['mappedBy']) ? (string) $referenceManyElement['mappedBy'] : null));
         }
     }
     if (isset($element['attachments'])) {
         $class->mapAttachments($element['attachments']);
     }
     if (isset($element['embedOne'])) {
         foreach ($element['embedOne'] as $field => $embedOneElement) {
             $class->mapEmbedded(array('targetDocument' => (string) $embedOneElement['targetDocument'], 'fieldName' => $field, 'jsonName' => isset($embedOneElement['jsonName']) ? (string) $embedOneElement['jsonName'] : null, 'embedded' => 'one'));
         }
     }
     if (isset($element['embedMany'])) {
         foreach ($element['embedMany'] as $field => $embedManyElement) {
             $class->mapEmbedded(array('targetDocument' => (string) $embedManyElement['targetDocument'], 'fieldName' => $field, 'jsonName' => isset($embedManyElement['jsonName']) ? (string) $embedManyElement['jsonName'] : null, 'embedded' => 'many'));
         }
     }
 }
开发者ID:doctrine,项目名称:couchdb-odm,代码行数:71,代码来源:YamlDriver.php

示例10: loadMetadataForClass


//.........这里部分代码省略.........

            foreach ($ids as $id) {
                $metadata->mapField($id);
            }
        }

        foreach ($fieldMappings as $fieldMapping) {
            $metadata->mapField($fieldMapping);
        }

        foreach ($this->manyToManyTables as $manyTable) {
            foreach ($manyTable->getForeignKeys() as $foreignKey) {
                // foreign  key maps to the table of the current entity, many to many association probably exists
                if (strtolower($tableName) == strtolower($foreignKey->getForeignTableName())) {
                    $myFk = $foreignKey;
                    $otherFk = null;
                    foreach ($manyTable->getForeignKeys() as $foreignKey) {
                        if ($foreignKey != $myFk) {
                            $otherFk = $foreignKey;
                            break;
                        }
                    }

                    if (!$otherFk) {
                        // the definition of this many to many table does not contain
                        // enough foreign key information to continue reverse engineering.
                        continue;
                    }

                    $localColumn = current($myFk->getColumns());
                    $associationMapping = array();
                    $associationMapping['fieldName'] = $this->getFieldNameForColumn($manyTable->getName(), current($otherFk->getColumns()), true);
                    $associationMapping['targetEntity'] = $this->getClassNameForTable($otherFk->getForeignTableName());
                    if (current($manyTable->getColumns())->getName() == $localColumn) {
                        $associationMapping['inversedBy'] = $this->getFieldNameForColumn($manyTable->getName(), current($myFk->getColumns()), true);
                        $associationMapping['joinTable'] = array(
                            'name' => strtolower($manyTable->getName()),
                            'joinColumns' => array(),
                            'inverseJoinColumns' => array(),
                        );

                        $fkCols = $myFk->getForeignColumns();
                        $cols = $myFk->getColumns();
                        for ($i = 0; $i < count($cols); $i++) {
                            $associationMapping['joinTable']['joinColumns'][] = array(
                                'name' => $cols[$i],
                                'referencedColumnName' => $fkCols[$i],
                            );
                        }

                        $fkCols = $otherFk->getForeignColumns();
                        $cols = $otherFk->getColumns();
                        for ($i = 0; $i < count($cols); $i++) {
                            $associationMapping['joinTable']['inverseJoinColumns'][] = array(
                                'name' => $cols[$i],
                                'referencedColumnName' => $fkCols[$i],
                            );
                        }
                    } else {
                        $associationMapping['mappedBy'] = $this->getFieldNameForColumn($manyTable->getName(), current($myFk->getColumns()), true);
                    }
                    $metadata->mapManyToMany($associationMapping);
                    break;
                }
            }
        }

        foreach ($foreignKeys as $foreignKey) {
            $foreignTable = $foreignKey->getForeignTableName();
            $cols = $foreignKey->getColumns();
            $fkCols = $foreignKey->getForeignColumns();

            $localColumn = current($cols);
            $associationMapping = array();
            $associationMapping['fieldName'] = $this->getFieldNameForColumn($tableName, $localColumn, true);
            $associationMapping['targetEntity'] = $this->getClassNameForTable($foreignTable);

            if (isset($metadata->fieldMappings[$associationMapping['fieldName']])) {
                $associationMapping['fieldName'] = $associationMapping['fieldName'] . "2";
            }

            if ($primaryKeyColumns && in_array($localColumn, $primaryKeyColumns)) {
                $associationMapping['id'] = true;
            }

            for ($i = 0; $i < count($cols); $i++) {
                $associationMapping['joinColumns'][] = array(
                    'name' => $cols[$i],
                    'referencedColumnName' => $fkCols[$i],
                );
            }

            //Here we need to check if $cols are the same as $primaryKeyColumns
            if (!array_diff($cols,$primaryKeyColumns)) {
                $metadata->mapOneToOne($associationMapping);
            } else {
                $metadata->mapManyToOne($associationMapping);
            }
        }
    }
开发者ID:nattaphat,项目名称:hgis,代码行数:101,代码来源:DatabaseDriver.php

示例11: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $reflClass = $metadata->getReflectionClass();
     $documentAnnots = array();
     foreach ($this->reader->getClassAnnotations($reflClass) as $annot) {
         foreach ($this->entityAnnotationClasses as $annotClass => $i) {
             if ($annot instanceof $annotClass) {
                 $documentAnnots[$i] = $annot;
             }
         }
     }
     if (!$documentAnnots) {
         throw MappingException::classIsNotAValidDocument($className);
     }
     // find the winning document annotation
     ksort($documentAnnots);
     $documentAnnot = reset($documentAnnots);
     if (isset($documentAnnot->versionable) && $documentAnnot->versionable) {
         $metadata->setVersioned($documentAnnot->versionable);
     }
     $metadata->setNodeType($documentAnnot->nodeType);
     if (isset($documentAnnot->referenceable) && $documentAnnot->referenceable) {
         $metadata->setReferenceable(true);
     }
     if ($documentAnnot->repositoryClass) {
         $metadata->setCustomRepositoryClassName($documentAnnot->repositoryClass);
     }
     if ($documentAnnot->translator) {
         $metadata->setTranslator($documentAnnot->translator);
     }
     foreach ($reflClass->getProperties() as $property) {
         if ($metadata->isMappedSuperclass && !$property->isPrivate() || $metadata->isInheritedField($property->name) && $metadata->name !== $property->getDeclaringClass()->getName()) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) {
             if ($fieldAnnot instanceof ODM\Property) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapField($mapping);
             } elseif ($fieldAnnot instanceof ODM\Id) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapId($mapping);
             } elseif ($fieldAnnot instanceof ODM\Node) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapNode($mapping);
             } elseif ($fieldAnnot instanceof ODM\Nodename) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapNodename($mapping);
             } elseif ($fieldAnnot instanceof ODM\ParentDocument) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapParentDocument($mapping);
             } elseif ($fieldAnnot instanceof ODM\Child) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapChild($mapping);
             } elseif ($fieldAnnot instanceof ODM\Children) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapChildren($mapping);
             } elseif ($fieldAnnot instanceof ODM\ReferenceOne) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapManyToOne($mapping);
             } elseif ($fieldAnnot instanceof ODM\ReferenceMany) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapManyToMany($mapping);
             } elseif ($fieldAnnot instanceof ODM\Referrers) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapReferrers($mapping);
             } elseif ($fieldAnnot instanceof ODM\Locale) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapLocale($mapping);
             } elseif ($fieldAnnot instanceof ODM\VersionName) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapVersionName($mapping);
             } elseif ($fieldAnnot instanceof ODM\VersionCreated) {
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 $metadata->mapVersionCreated($mapping);
             }
             if (!isset($mapping['name'])) {
                 $mapping['name'] = $property->getName();
             }
         }
     }
     foreach ($reflClass->getMethods() as $method) {
         if ($method->isPublic() && $method->getDeclaringClass()->getName() == $metadata->name) {
             foreach ($this->reader->getMethodAnnotations($method) as $annot) {
                 if ($annot instanceof ODM\PrePersist) {
                     $metadata->addLifecycleCallback($method->getName(), Event::prePersist);
                 } elseif ($annot instanceof ODM\PostPersist) {
                     $metadata->addLifecycleCallback($method->getName(), Event::postPersist);
                 } elseif ($annot instanceof ODM\PreUpdate) {
                     $metadata->addLifecycleCallback($method->getName(), Event::preUpdate);
                 } elseif ($annot instanceof ODM\PostUpdate) {
                     $metadata->addLifecycleCallback($method->getName(), Event::postUpdate);
                 } elseif ($annot instanceof ODM\PreRemove) {
                     $metadata->addLifecycleCallback($method->getName(), Event::preRemove);
                 } elseif ($annot instanceof ODM\PostRemove) {
                     $metadata->addLifecycleCallback($method->getName(), Event::postRemove);
//.........这里部分代码省略.........
开发者ID:nicam,项目名称:phpcr-odm,代码行数:101,代码来源:AnnotationDriver.php

示例12: loadMetadataForClass


//.........这里部分代码省略.........
     } else {
         $metadata->setCustomRepositoryClass('Contao\\Doctrine\\ORM\\Repository');
     }
     // id generator
     if (array_key_exists('idGenerator', $entityConfig)) {
         $metadata->setIdGeneratorType($entityConfig['idGenerator']);
     } else {
         $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
     }
     // indexes
     if (isset($entityConfig['indexes'])) {
         if (is_array($entityConfig['indexes'])) {
             foreach ($entityConfig['indexes'] as $name => $columns) {
                 if (is_array($columns)) {
                     $builder->addIndex($columns, $name);
                 } else {
                     throw new \RuntimeException(sprintf('$GLOBALS[TL_DCA][%s][entity][indexes][%s] must be an array', $tableName, $name));
                 }
             }
         } else {
             throw new \RuntimeException(sprintf('$GLOBALS[TL_DCA][%s][entity][indexes] must be an array', $tableName));
         }
     }
     // uniques
     if (isset($entityConfig['uniques'])) {
         if (is_array($entityConfig['uniques'])) {
             foreach ($entityConfig['uniques'] as $name => $columns) {
                 if (is_array($columns)) {
                     $builder->addUniqueConstraint($columns, $name);
                 } else {
                     throw new \RuntimeException(sprintf('$GLOBALS[TL_DCA][%s][entity][uniques][%s] must be an array', $tableName, $name));
                 }
             }
         } else {
             throw new \RuntimeException(sprintf('$GLOBALS[TL_DCA][%s][entity][uniques] must be an array', $tableName));
         }
     }
     $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
     $metadata->setPrimaryTable(array('name' => $tableName));
     $fields = (array) $GLOBALS['TL_DCA'][$tableName]['fields'];
     foreach ($fields as $fieldName => $fieldConfig) {
         $configured = array_key_exists('field', $fieldConfig) || array_key_exists('oneToOne', $fieldConfig) || array_key_exists('oneToMany', $fieldConfig) || array_key_exists('manyToOne', $fieldConfig) || array_key_exists('manyToMany', $fieldConfig);
         if (!$configured && empty($fieldConfig['inputType']) || $configured && $fieldConfig['field'] === false) {
             continue;
         }
         if (isset($fieldConfig['oneToOne'])) {
             $fieldConfig['oneToOne']['fieldName'] = $fieldName;
             $metadata->mapOneToOne($fieldConfig['oneToOne']);
         } elseif (isset($fieldConfig['oneToMany'])) {
             $fieldConfig['oneToMany']['fieldName'] = $fieldName;
             $metadata->mapOneToMany($fieldConfig['oneToMany']);
         } elseif (isset($fieldConfig['manyToOne'])) {
             $fieldConfig['manyToOne']['fieldName'] = $fieldName;
             $metadata->mapManyToOne($fieldConfig['manyToOne']);
         } elseif (isset($fieldConfig['manyToMany'])) {
             $fieldConfig['manyToMany']['fieldName'] = $fieldName;
             $metadata->mapManyToMany($fieldConfig['manyToMany']);
         } else {
             $fieldMapping = array();
             $inputTypes = array($fieldConfig['inputType']);
             $inputTypeOptions = array();
             if ($fieldConfig['foreignKey']) {
                 $inputTypeOptions[] = 'foreignKey';
             }
             if ($fieldConfig['eval']['multiple']) {
                 $inputTypeOptions[] = 'multiple';
             }
             for ($i = 0; $i < count($inputTypeOptions); $i++) {
                 $inputTypeOption = $fieldConfig['inputType'] . '_' . $inputTypeOptions[$i];
                 array_unshift($inputTypes, $inputTypeOption);
                 for ($j = $i + 1; $j < count($inputTypeOptions); $j++) {
                     $inputTypeOption .= '_' . $inputTypeOptions[$j];
                     array_unshift($inputTypes, $inputTypeOption);
                 }
             }
             foreach ($inputTypes as $inputType) {
                 if (array_key_exists($inputType, $GLOBALS['DOCTRINE_TYPE_MAP'])) {
                     $fieldMapping = $GLOBALS['DOCTRINE_TYPE_MAP'][$inputType];
                     break;
                 }
             }
             if (isset($fieldConfig['eval']['maxlength'])) {
                 $fieldMapping['length'] = (int) $fieldConfig['eval']['maxlength'];
             }
             if (isset($fieldConfig['eval']['unique'])) {
                 $fieldMapping['unique'] = (bool) $fieldConfig['eval']['unique'];
             }
             if (array_key_exists('field', $fieldConfig)) {
                 $fieldMapping = array_merge($fieldMapping, $fieldConfig['field']);
             }
             $fieldMapping['fieldName'] = $fieldName;
             $metadata->mapField($fieldMapping);
         }
     }
     /*
     if (TL_MODE == 'BE' && !$metadata->isMappedSuperclass) {
     	EntityGeneration::generateEntity($metadata);
     }
     */
 }
开发者ID:bit3,项目名称:contao-doctrine-orm,代码行数:101,代码来源:ContaoDcaDriver.php

示例13: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $class)
 {
     $reflClass = $class->getReflectionClass();
     $isValidDocument = false;
     $classAnnotations = $this->reader->getClassAnnotations($reflClass);
     foreach ($classAnnotations as $classAnnotation) {
         if ($classAnnotation instanceof ODM\Document) {
             if ($classAnnotation->indexed) {
                 $class->indexed = true;
             }
             $class->setCustomRepositoryClass($classAnnotation->repositoryClass);
             $isValidDocument = true;
         } elseif ($classAnnotation instanceof ODM\EmbeddedDocument) {
             $class->isEmbeddedDocument = true;
             $isValidDocument = true;
         } else {
             if ($classAnnotation instanceof ODM\MappedSuperclass) {
                 $class->isMappedSuperclass = true;
                 $isValidDocument = true;
             } else {
                 if ($classAnnotation instanceof ODM\Index) {
                     $class->indexed = true;
                 } else {
                     if ($classAnnotation instanceof ODM\InheritanceRoot) {
                         $class->markInheritanceRoot();
                     }
                 }
             }
         }
     }
     if (!$isValidDocument) {
         throw MappingException::classIsNotAValidDocument($className);
     }
     foreach ($reflClass->getProperties() as $property) {
         if ($class->isInheritedAssociation($property->name) || $class->isInheritedField($property->name)) {
             continue;
         }
         $mapping = array();
         $mapping['fieldName'] = $property->name;
         if ($this->reader->getPropertyAnnotation($property, 'Doctrine\\ODM\\CouchDB\\Mapping\\Annotations\\Index')) {
             $mapping['indexed'] = true;
         }
         foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) {
             if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Field) {
                 if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Version) {
                     $mapping['isVersionField'] = true;
                 }
                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                 unset($mapping['value']);
                 $class->mapField($mapping);
             } else {
                 if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\ReferenceOne) {
                     $mapping = array_merge($mapping, (array) $fieldAnnot);
                     $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                     unset($mapping['value']);
                     $class->mapManyToOne($mapping);
                 } else {
                     if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\ReferenceMany) {
                         $mapping = array_merge($mapping, (array) $fieldAnnot);
                         $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade);
                         unset($mapping['value']);
                         $class->mapManyToMany($mapping);
                     } else {
                         if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Attachments) {
                             $class->mapAttachments($mapping['fieldName']);
                         } else {
                             if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\EmbedOne || $fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\EmbedMany) {
                                 $mapping = array_merge($mapping, (array) $fieldAnnot);
                                 unset($mapping['value']);
                                 $class->mapEmbedded($mapping);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:doctrine,项目名称:couchdb-odm,代码行数:81,代码来源:AnnotationDriver.php

示例14: addReferenceMapping

 private function addReferenceMapping(ClassMetadata $class, $reference, $type)
 {
     /** @var $class \Doctrine\ODM\PHPCR\Mapping\ClassMetadata */
     $attributes = (array) $reference->attributes();
     $mapping = $attributes["@attributes"];
     $mapping['strategy'] = isset($mapping['strategy']) ? strtolower($mapping['strategy']) : null;
     $mapping['targetDocument'] = isset($mapping['target-document']) ? $mapping['target-document'] : null;
     unset($mapping['target-document']);
     if ($type === 'many') {
         $class->mapManyToMany($mapping);
     } elseif ($type === 'one') {
         $class->mapManyToOne($mapping);
     }
 }
开发者ID:nikophil,项目名称:cmf-tests,代码行数:14,代码来源:XmlDriver.php

示例15: loadMetadataForClass

 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $class)
 {
     /** @var $class \Doctrine\ODM\CouchDB\Mapping\ClassMetadata */
     try {
         $xmlRoot = $this->getElement($className);
     } catch (DoctrineMappingException $e) {
         // Convert Exception type for consistency with other drivers
         throw new MappingException($e->getMessage(), $e->getCode(), $e);
     }
     if (!$xmlRoot) {
         return;
     }
     if ($xmlRoot->getName() == 'document') {
         $class->setCustomRepositoryClass(isset($xmlRoot['repository-class']) ? (string) $xmlRoot['repository-class'] : null);
         if (isset($xmlRoot['indexed']) && $xmlRoot['indexed'] == true) {
             $class->indexed = true;
         }
         if (isset($xmlRoot['inheritance-root']) && $xmlRoot['inheritance-root']) {
             $class->markInheritanceRoot();
         }
     } else {
         if ($xmlRoot->getName() == "embedded-document") {
             $class->isEmbeddedDocument = true;
             if (isset($xmlRoot['inheritance-root']) && $xmlRoot['inheritance-root']) {
                 $class->markInheritanceRoot();
             }
         } else {
             if ($xmlRoot->getName() == "mapped-superclass") {
                 $class->isMappedSuperclass = true;
             } else {
                 throw MappingException::classIsNotAValidDocument($className);
             }
         }
     }
     // Evaluate <field ...> mappings
     if (isset($xmlRoot->field)) {
         foreach ($xmlRoot->field as $fieldMapping) {
             $class->mapField(array('fieldName' => (string) $fieldMapping['name'], 'jsonName' => isset($fieldMapping['json-name']) ? (string) $fieldMapping['json-name'] : null, 'indexed' => isset($fieldMapping['index']) ? (bool) $fieldMapping['index'] : false, 'type' => isset($fieldMapping['type']) ? (string) $fieldMapping['type'] : null, 'isVersionField' => isset($fieldMapping['version']) ? true : null));
         }
     }
     // Evaluate <id ..> mappings
     foreach ($xmlRoot->id as $idElement) {
         $class->mapField(array('fieldName' => (string) $idElement['name'], 'indexed' => isset($idElement['index']) ? (bool) $idElement['index'] : false, 'type' => isset($idElement['type']) ? (string) $idElement['type'] : null, 'id' => true, 'strategy' => isset($idElement['strategy']) ? (string) $idElement['strategy'] : null));
     }
     // Evaluate <version ..> mappings
     foreach ($xmlRoot->version as $versionElement) {
         $class->mapField(array('fieldName' => (string) $versionElement['name'], 'type' => 'string', 'isVersionField' => true, 'jsonName' => '_rev'));
     }
     // Evaluate <many-to-one ..> mappings
     if (isset($xmlRoot->{"reference-one"})) {
         foreach ($xmlRoot->{"reference-one"} as $referenceOneElement) {
             $class->mapManyToOne(array('cascade' => isset($referenceOneElement->cascade) ? $this->getCascadeMode($referenceOneElement->cascade) : 0, 'targetDocument' => (string) $referenceOneElement['target-document'], 'fieldName' => (string) $referenceOneElement['field'], 'jsonName' => isset($referenceOneElement['json-name']) ? (string) $referenceOneElement['json-name'] : null, 'indexed' => isset($referenceOneElement['index']) ? (bool) $referenceOneElement['index'] : false));
         }
     }
     // Evaluate <many-to-one ..> mappings
     if (isset($xmlRoot->{"reference-many"})) {
         foreach ($xmlRoot->{"reference-many"} as $referenceManyElement) {
             $class->mapManyToMany(array('cascade' => isset($referenceManyElement->cascade) ? $this->getCascadeMode($referenceManyElement->cascade) : 0, 'targetDocument' => (string) $referenceManyElement['target-document'], 'fieldName' => (string) $referenceManyElement['field'], 'jsonName' => isset($referenceManyElement['json-name']) ? (string) $referenceManyElement['json-name'] : null, 'mappedBy' => isset($referenceManyElement['mapped-by']) ? (string) $referenceManyElement['mapped-by'] : null));
         }
     }
     // Evaluate <attachments ..> mapping
     if (isset($xmlRoot->{"attachments"})) {
         $class->mapAttachments((string) $xmlRoot->{"attachments"}[0]['field']);
     }
     // Evaluate <embed-one />
     if (isset($xmlRoot->{'embed-one'})) {
         foreach ($xmlRoot->{'embed-one'} as $embedOneElement) {
             $class->mapEmbedded(array('targetDocument' => (string) $embedOneElement['target-document'], 'fieldName' => (string) $embedOneElement['field'], 'jsonName' => isset($embedOneElement['json-name']) ? (string) $embedOneElement['json-name'] : null, 'embedded' => 'one'));
         }
     }
     // Evaluate <embed-many />
     if (isset($xmlRoot->{'embed-many'})) {
         foreach ($xmlRoot->{'embed-many'} as $embedManyElement) {
             $class->mapEmbedded(array('targetDocument' => (string) $embedManyElement['target-document'], 'fieldName' => (string) $embedManyElement['field'], 'jsonName' => isset($embedManyElement['json-name']) ? (string) $embedManyElement['json-name'] : null, 'embedded' => 'many'));
         }
     }
 }
开发者ID:doctrine,项目名称:couchdb-odm,代码行数:80,代码来源:XmlDriver.php


注:本文中的Doctrine\Common\Persistence\Mapping\ClassMetadata::mapManyToMany方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。