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


PHP ClassMetadata::mapOneToOne方法代码示例

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


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

示例1: 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

示例2: loadMetadataForClass


//.........这里部分代码省略.........
     if (isset($xmlRoot->{'one-to-one'})) {
         foreach ($xmlRoot->{'one-to-one'} as $oneToOneElement) {
             $mapping = array('fieldName' => (string) $oneToOneElement['field'], 'targetEntity' => (string) $oneToOneElement['target-entity']);
             if (isset($associationIds[$mapping['fieldName']])) {
                 $mapping['id'] = true;
             }
             if (isset($oneToOneElement['fetch'])) {
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . (string) $oneToOneElement['fetch']);
             }
             if (isset($oneToOneElement['mapped-by'])) {
                 $mapping['mappedBy'] = (string) $oneToOneElement['mapped-by'];
             } else {
                 if (isset($oneToOneElement['inversed-by'])) {
                     $mapping['inversedBy'] = (string) $oneToOneElement['inversed-by'];
                 }
                 $joinColumns = array();
                 if (isset($oneToOneElement->{'join-column'})) {
                     $joinColumns[] = $this->joinColumnToArray($oneToOneElement->{'join-column'});
                 } else {
                     if (isset($oneToOneElement->{'join-columns'})) {
                         foreach ($oneToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
                             $joinColumns[] = $this->joinColumnToArray($joinColumnElement);
                         }
                     }
                 }
                 $mapping['joinColumns'] = $joinColumns;
             }
             if (isset($oneToOneElement->cascade)) {
                 $mapping['cascade'] = $this->_getCascadeMappings($oneToOneElement->cascade);
             }
             if (isset($oneToOneElement['orphan-removal'])) {
                 $mapping['orphanRemoval'] = $this->evaluateBoolean($oneToOneElement['orphan-removal']);
             }
             $metadata->mapOneToOne($mapping);
         }
     }
     // Evaluate <one-to-many ...> mappings
     if (isset($xmlRoot->{'one-to-many'})) {
         foreach ($xmlRoot->{'one-to-many'} as $oneToManyElement) {
             $mapping = array('fieldName' => (string) $oneToManyElement['field'], 'targetEntity' => (string) $oneToManyElement['target-entity'], 'mappedBy' => (string) $oneToManyElement['mapped-by']);
             if (isset($oneToManyElement['fetch'])) {
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . (string) $oneToManyElement['fetch']);
             }
             if (isset($oneToManyElement->cascade)) {
                 $mapping['cascade'] = $this->_getCascadeMappings($oneToManyElement->cascade);
             }
             if (isset($oneToManyElement['orphan-removal'])) {
                 $mapping['orphanRemoval'] = $this->evaluateBoolean($oneToManyElement['orphan-removal']);
             }
             if (isset($oneToManyElement->{'order-by'})) {
                 $orderBy = array();
                 foreach ($oneToManyElement->{'order-by'}->{'order-by-field'} as $orderByField) {
                     $orderBy[(string) $orderByField['name']] = (string) $orderByField['direction'];
                 }
                 $mapping['orderBy'] = $orderBy;
             }
             if (isset($oneToManyElement['index-by'])) {
                 $mapping['indexBy'] = (string) $oneToManyElement['index-by'];
             } else {
                 if (isset($oneToManyElement->{'index-by'})) {
                     throw new \InvalidArgumentException("<index-by /> is not a valid tag");
                 }
             }
             $metadata->mapOneToMany($mapping);
         }
     }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:67,代码来源:XmlDriver.php

示例3: loadMetadataForClass


//.........这里部分代码省略.........
                 $mapping['id'] = true;
             }
             if ($generatedValueAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\GeneratedValue')) {
                 $metadata->setIdGeneratorType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy));
             }
             if ($this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Version')) {
                 $metadata->setVersionMapping($mapping);
             }
             $metadata->mapField($mapping);
             // Check for SequenceGenerator/TableGenerator definition
             if ($seqGeneratorAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\SequenceGenerator')) {
                 $metadata->setSequenceGeneratorDefinition(array('sequenceName' => $seqGeneratorAnnot->sequenceName, 'allocationSize' => $seqGeneratorAnnot->allocationSize, 'initialValue' => $seqGeneratorAnnot->initialValue));
             } else {
                 if ($this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\TableGenerator')) {
                     throw MappingException::tableIdGeneratorNotImplemented($className);
                 } else {
                     if ($customGeneratorAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\CustomIdGenerator')) {
                         $metadata->setCustomGeneratorDefinition(array('class' => $customGeneratorAnnot->class));
                     }
                 }
             }
         } else {
             if ($oneToOneAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToOne')) {
                 if ($idAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
                     $mapping['id'] = true;
                 }
                 $mapping['targetEntity'] = $oneToOneAnnot->targetEntity;
                 $mapping['joinColumns'] = $joinColumns;
                 $mapping['mappedBy'] = $oneToOneAnnot->mappedBy;
                 $mapping['inversedBy'] = $oneToOneAnnot->inversedBy;
                 $mapping['cascade'] = $oneToOneAnnot->cascade;
                 $mapping['orphanRemoval'] = $oneToOneAnnot->orphanRemoval;
                 $mapping['fetch'] = $this->getFetchMode($className, $oneToOneAnnot->fetch);
                 $metadata->mapOneToOne($mapping);
             } else {
                 if ($oneToManyAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToMany')) {
                     $mapping['mappedBy'] = $oneToManyAnnot->mappedBy;
                     $mapping['targetEntity'] = $oneToManyAnnot->targetEntity;
                     $mapping['cascade'] = $oneToManyAnnot->cascade;
                     $mapping['indexBy'] = $oneToManyAnnot->indexBy;
                     $mapping['orphanRemoval'] = $oneToManyAnnot->orphanRemoval;
                     $mapping['fetch'] = $this->getFetchMode($className, $oneToManyAnnot->fetch);
                     if ($orderByAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OrderBy')) {
                         $mapping['orderBy'] = $orderByAnnot->value;
                     }
                     $metadata->mapOneToMany($mapping);
                 } else {
                     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) {
开发者ID:aschempp,项目名称:doctrine2,代码行数:67,代码来源:AnnotationDriver.php

示例4: loadMetadataForClass


//.........这里部分代码省略.........
             if (isset($associationIds[$mapping['fieldName']])) {
                 $mapping['id'] = true;
             }
             if (isset($oneToOneElement['fetch'])) {
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $oneToOneElement['fetch']);
             }
             if (isset($oneToOneElement['mappedBy'])) {
                 $mapping['mappedBy'] = $oneToOneElement['mappedBy'];
             } else {
                 if (isset($oneToOneElement['inversedBy'])) {
                     $mapping['inversedBy'] = $oneToOneElement['inversedBy'];
                 }
                 $joinColumns = array();
                 if (isset($oneToOneElement['joinColumn'])) {
                     $joinColumns[] = $this->joinColumnToArray($oneToOneElement['joinColumn']);
                 } else {
                     if (isset($oneToOneElement['joinColumns'])) {
                         foreach ($oneToOneElement['joinColumns'] as $joinColumnName => $joinColumnElement) {
                             if (!isset($joinColumnElement['name'])) {
                                 $joinColumnElement['name'] = $joinColumnName;
                             }
                             $joinColumns[] = $this->joinColumnToArray($joinColumnElement);
                         }
                     }
                 }
                 $mapping['joinColumns'] = $joinColumns;
             }
             if (isset($oneToOneElement['cascade'])) {
                 $mapping['cascade'] = $oneToOneElement['cascade'];
             }
             if (isset($oneToOneElement['orphanRemoval'])) {
                 $mapping['orphanRemoval'] = (bool) $oneToOneElement['orphanRemoval'];
             }
             $metadata->mapOneToOne($mapping);
             // Evaluate second level cache
             if (isset($oneToOneElement['cache'])) {
                 $metadata->enableAssociationCache($mapping['fieldName'], $this->cacheToArray($oneToOneElement['cache']));
             }
         }
     }
     // Evaluate oneToMany relationships
     if (isset($element['oneToMany'])) {
         foreach ($element['oneToMany'] as $name => $oneToManyElement) {
             $mapping = array('fieldName' => $name, 'targetEntity' => $oneToManyElement['targetEntity'], 'mappedBy' => $oneToManyElement['mappedBy']);
             if (isset($oneToManyElement['fetch'])) {
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $oneToManyElement['fetch']);
             }
             if (isset($oneToManyElement['cascade'])) {
                 $mapping['cascade'] = $oneToManyElement['cascade'];
             }
             if (isset($oneToManyElement['orphanRemoval'])) {
                 $mapping['orphanRemoval'] = (bool) $oneToManyElement['orphanRemoval'];
             }
             if (isset($oneToManyElement['orderBy'])) {
                 $mapping['orderBy'] = $oneToManyElement['orderBy'];
             }
             if (isset($oneToManyElement['indexBy'])) {
                 $mapping['indexBy'] = $oneToManyElement['indexBy'];
             }
             $metadata->mapOneToMany($mapping);
             // Evaluate second level cache
             if (isset($oneToManyElement['cache'])) {
                 $metadata->enableAssociationCache($mapping['fieldName'], $this->cacheToArray($oneToManyElement['cache']));
             }
         }
     }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:67,代码来源:YamlDriver.php

示例5: 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

示例6: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string                              $className
  * @param \Doctrine\ORM\Mapping\ClassMetadata $metadata
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     global $container;
     $builder = new ClassMetadataBuilder($metadata);
     $tableName = static::classToTableName($className);
     $this->loadDataContainer($tableName);
     try {
         /** @var ClassLoader $entitiesClassLoader */
         $entitiesClassLoader = $container['doctrine.orm.entitiesClassLoader'];
         if (!class_exists($className, false)) {
             $entitiesClassLoader->loadClass($className);
         }
         if (class_exists($className, false)) {
             $class = new \ReflectionClass($className);
         } else {
             $class = false;
         }
     } catch (\Exception $e) {
         $class = false;
     }
     if (!array_key_exists('TL_DCA', $GLOBALS)) {
         $GLOBALS['TL_DCA'] = array();
     }
     if (!array_key_exists($tableName, $GLOBALS['TL_DCA']) || !is_array($GLOBALS['TL_DCA'][$tableName])) {
         $GLOBALS['TL_DCA'][$tableName] = array('fields' => array());
     }
     $entityConfig = array();
     if (array_key_exists('entity', $GLOBALS['TL_DCA'][$tableName])) {
         $entityConfig = $GLOBALS['TL_DCA'][$tableName]['entity'];
     }
     if ($class && !$class->isInstantiable()) {
         $metadata->isMappedSuperclass = true;
     } elseif (array_key_exists('isMappedSuperclass', $entityConfig)) {
         $metadata->isMappedSuperclass = $entityConfig['isMappedSuperclass'];
     }
     // custom repository class
     if (array_key_exists('repositoryClass', $entityConfig)) {
         $metadata->setCustomRepositoryClass($entityConfig['repositoryClass']);
     } 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;
//.........这里部分代码省略.........
开发者ID:bit3,项目名称:contao-doctrine-orm,代码行数:101,代码来源:ContaoDcaDriver.php


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