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


PHP ClassMetadataInfo::mapOneToMany方法代码示例

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


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

示例1: ClassMetadataInfo

 function it_configures_the_mappings_of_an_original_model_that_is_override($configuration)
 {
     $metadataInfo = new ClassMetadataInfo('Foo\\Bar\\OriginalQux');
     $metadataInfo->mapManyToMany(['fieldName' => 'relation1', 'targetEntity' => 'Foo']);
     $metadataInfo->mapManyToOne(['fieldName' => 'relation2', 'targetEntity' => 'Foo']);
     $metadataInfo->mapOneToMany(['fieldName' => 'relation3', 'targetEntity' => 'Foo', 'mappedBy' => 'baz']);
     $metadataInfo->mapOneToOne(['fieldName' => 'relation4', 'targetEntity' => 'Foo']);
     $overrides = [['original' => 'Foo\\Bar\\OriginalQux', 'override' => 'Acme\\Bar\\OverrideQux'], ['original' => 'Foo\\Baz\\OriginalQux', 'override' => 'Acme\\Baz\\OverrideQux']];
     $this->configure($metadataInfo, $overrides, $configuration)->shouldBeAnOverrideModel();
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:10,代码来源:MappingsOverrideConfiguratorSpec.php

示例2: loadMetadataForClass


//.........这里部分代码省略.........
             if (isset($oneToOneElement['orphan-removal'])) {
                 $mapping['orphanRemoval'] = (bool) $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'] = (bool) $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);
         }
     }
     // Evaluate <many-to-one ...> mappings
     if (isset($xmlRoot->{'many-to-one'})) {
         foreach ($xmlRoot->{'many-to-one'} as $manyToOneElement) {
             $mapping = array('fieldName' => (string) $manyToOneElement['field'], 'targetEntity' => (string) $manyToOneElement['target-entity']);
             if (isset($associationIds[$mapping['fieldName']])) {
                 $mapping['id'] = true;
             }
             if (isset($manyToOneElement['fetch'])) {
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . (string) $manyToOneElement['fetch']);
             }
             if (isset($manyToOneElement['inversed-by'])) {
                 $mapping['inversedBy'] = (string) $manyToOneElement['inversed-by'];
             }
             $joinColumns = array();
             if (isset($manyToOneElement->{'join-column'})) {
                 $joinColumns[] = $this->_getJoinColumnMapping($manyToOneElement->{'join-column'});
             } else {
                 if (isset($manyToOneElement->{'join-columns'})) {
                     foreach ($manyToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
                         $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement);
                     }
                 }
             }
             $mapping['joinColumns'] = $joinColumns;
             if (isset($manyToOneElement->cascade)) {
                 $mapping['cascade'] = $this->_getCascadeMappings($manyToOneElement->cascade);
             }
             $metadata->mapManyToOne($mapping);
         }
     }
开发者ID:SerdarSanri,项目名称:doctrine-bundle,代码行数:67,代码来源:XmlDriver.php

示例3: loadMetadata

 public static function loadMetadata(ClassMetadataInfo $metadata)
 {
     $metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
     $metadata->setPrimaryTable(array('name' => 'cms_users'));
     $metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT);
     $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist');
     $metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist');
     $metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist');
     $metadata->mapField(array('id' => true, 'fieldName' => 'id', 'type' => 'integer', 'columnName' => 'id'));
     $metadata->mapField(array('fieldName' => 'name', 'type' => 'string', 'length' => 50, 'unique' => true, 'nullable' => true, 'columnName' => 'name'));
     $metadata->mapField(array('fieldName' => 'email', 'type' => 'string', 'columnName' => 'user_email', 'columnDefinition' => 'CHAR(32) NOT NULL'));
     $metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
     $metadata->mapOneToOne(array('fieldName' => 'address', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Address', 'cascade' => array(0 => 'remove'), 'mappedBy' => NULL, 'inversedBy' => 'user', 'joinColumns' => array(0 => array('name' => 'address_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE')), 'orphanRemoval' => false));
     $metadata->mapOneToMany(array('fieldName' => 'phonenumbers', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Phonenumber', 'cascade' => array(1 => 'persist'), 'mappedBy' => 'user', 'orphanRemoval' => true, 'orderBy' => array('number' => 'ASC')));
     $metadata->mapManyToMany(array('fieldName' => 'groups', 'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Group', 'cascade' => array(0 => 'remove', 1 => 'persist', 2 => 'refresh', 3 => 'merge', 4 => 'detach'), 'mappedBy' => NULL, 'joinTable' => array('name' => 'cms_users_groups', 'joinColumns' => array(0 => array('name' => 'user_id', 'referencedColumnName' => 'id', 'unique' => false, 'nullable' => false)), 'inverseJoinColumns' => array(0 => array('name' => 'group_id', 'referencedColumnName' => 'id', 'columnDefinition' => 'INT NULL'))), 'orderBy' => NULL));
     $metadata->table['uniqueConstraints'] = array('search_idx' => array('columns' => array('name', 'user_email')));
     $metadata->table['indexes'] = array('name_idx' => array('columns' => array('name')), 0 => array('columns' => array('user_email')));
     $metadata->setSequenceGeneratorDefinition(array('sequenceName' => 'tablename_seq', 'allocationSize' => 100, 'initialValue' => 1));
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:19,代码来源:AbstractMappingDriverTest.php

示例4: remapAssociation

 /**
  * @param \Doctrine\ORM\Mapping\ClassMetadataInfo $classMetadata
  * @param array                                   $mapping
  *
  * @return void
  */
 private function remapAssociation($classMetadata, $mapping)
 {
     $newMapping = $this->resolveTargetEntities[$mapping['targetEntity']];
     $newMapping = array_replace_recursive($mapping, $newMapping);
     $newMapping['fieldName'] = $mapping['fieldName'];
     unset($classMetadata->associationMappings[$mapping['fieldName']]);
     switch ($mapping['type']) {
         case ClassMetadata::MANY_TO_MANY:
             $classMetadata->mapManyToMany($newMapping);
             break;
         case ClassMetadata::MANY_TO_ONE:
             $classMetadata->mapManyToOne($newMapping);
             break;
         case ClassMetadata::ONE_TO_MANY:
             $classMetadata->mapOneToMany($newMapping);
             break;
         case ClassMetadata::ONE_TO_ONE:
             $classMetadata->mapOneToOne($newMapping);
             break;
     }
 }
开发者ID:AdactiveSAS,项目名称:doctrine2,代码行数:27,代码来源:ResolveTargetEntityListener.php

示例5: loadMetadataForClass


//.........这里部分代码省略.........
             $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 ($tblGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\TableGenerator')) {
                     throw MappingException::tableIdGeneratorNotImplemented($className);
                 }
             }
         } 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'][] = array('name' => $joinColumn->name, 'referencedColumnName' => $joinColumn->referencedColumnName, 'unique' => $joinColumn->unique, 'nullable' => $joinColumn->nullable, 'onDelete' => $joinColumn->onDelete, 'columnDefinition' => $joinColumn->columnDefinition);
                                 }
                                 foreach ($joinTableAnnot->inverseJoinColumns as $joinColumn) {
                                     $joinTable['inverseJoinColumns'][] = array('name' => $joinColumn->name, 'referencedColumnName' => $joinColumn->referencedColumnName, 'unique' => $joinColumn->unique, 'nullable' => $joinColumn->nullable, 'onDelete' => $joinColumn->onDelete, 'columnDefinition' => $joinColumn->columnDefinition);
                                 }
                             }
                             $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')) {
开发者ID:SerdarSanri,项目名称:doctrine-bundle,代码行数:67,代码来源:AnnotationDriver.php

示例6: loadMetadataForClass


//.........这里部分代码省略.........
                         }
                     }
                 }
                 $mapping['joinColumns'] = $joinColumns;
             }
             if (isset($oneToOneElement['cascade'])) {
                 $mapping['cascade'] = $oneToOneElement['cascade'];
             }
             if (isset($oneToOneElement['orphanRemoval'])) {
                 $mapping['orphanRemoval'] = (bool) $oneToOneElement['orphanRemoval'];
             }
             $metadata->mapOneToOne($mapping);
         }
     }
     // 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 manyToOne relationships
     if (isset($element['manyToOne'])) {
         foreach ($element['manyToOne'] as $name => $manyToOneElement) {
             $mapping = array('fieldName' => $name, 'targetEntity' => $manyToOneElement['targetEntity']);
             if (isset($associationIds[$mapping['fieldName']])) {
                 $mapping['id'] = true;
             }
             if (isset($manyToOneElement['fetch'])) {
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_' . $manyToOneElement['fetch']);
             }
             if (isset($manyToOneElement['inversedBy'])) {
                 $mapping['inversedBy'] = $manyToOneElement['inversedBy'];
             }
             $joinColumns = array();
             if (isset($manyToOneElement['joinColumn'])) {
                 $joinColumns[] = $this->_getJoinColumnMapping($manyToOneElement['joinColumn']);
             } else {
                 if (isset($manyToOneElement['joinColumns'])) {
                     foreach ($manyToOneElement['joinColumns'] as $name => $joinColumnElement) {
                         if (!isset($joinColumnElement['name'])) {
                             $joinColumnElement['name'] = $name;
                         }
                         $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement);
                     }
                 }
             }
             $mapping['joinColumns'] = $joinColumns;
             if (isset($manyToOneElement['cascade'])) {
                 $mapping['cascade'] = $manyToOneElement['cascade'];
             }
开发者ID:williamamed,项目名称:Raptor2,代码行数:67,代码来源:YamlDriver.php

示例7: evaluatePropertyAnnotations

 /**
  * Evaluate the property annotations and amend the metadata accordingly.
  *
  * @param ClassMetadataInfo $metadata
  * @return void
  * @throws MappingException
  */
 protected function evaluatePropertyAnnotations(ClassMetadataInfo $metadata)
 {
     $className = $metadata->name;
     $class = $metadata->getReflectionClass();
     $classSchema = $this->getClassSchema($className);
     foreach ($class->getProperties() as $property) {
         if (!$classSchema->hasProperty($property->getName()) || $classSchema->isPropertyTransient($property->getName()) || $metadata->isMappedSuperclass && !$property->isPrivate() || $metadata->isInheritedField($property->getName()) || $metadata->isInheritedAssociation($property->getName())) {
             continue;
         }
         $propertyMetaData = $classSchema->getProperty($property->getName());
         $mapping = array();
         $mapping['fieldName'] = $property->getName();
         $mapping['columnName'] = strtolower($property->getName());
         $mapping['targetEntity'] = $propertyMetaData['type'];
         $joinColumns = $this->evaluateJoinColumnAnnotations($property);
         // Field can only be annotated with one of:
         // @OneToOne, @OneToMany, @ManyToOne, @ManyToMany, @Column (optional)
         if ($oneToOneAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToOne')) {
             if ($oneToOneAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $oneToOneAnnotation->targetEntity;
             }
             if ($oneToOneAnnotation->inversedBy !== null || $oneToOneAnnotation->mappedBy === null) {
                 $mapping['joinColumns'] = $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property);
             }
             $mapping['mappedBy'] = $oneToOneAnnotation->mappedBy;
             $mapping['inversedBy'] = $oneToOneAnnotation->inversedBy;
             if ($oneToOneAnnotation->cascade) {
                 $mapping['cascade'] = $oneToOneAnnotation->cascade;
             } elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
                 $mapping['cascade'] = array('persist');
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
                 $mapping['cascade'] = array('all');
             }
             if ($oneToOneAnnotation->orphanRemoval) {
                 $mapping['orphanRemoval'] = $oneToOneAnnotation->orphanRemoval;
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false && $this->isValueObject($mapping['targetEntity'], $className) === false) {
                 $mapping['orphanRemoval'] = true;
             }
             $mapping['fetch'] = $this->getFetchMode($className, $oneToOneAnnotation->fetch);
             $metadata->mapOneToOne($mapping);
         } elseif ($oneToManyAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToMany')) {
             $mapping['mappedBy'] = $oneToManyAnnotation->mappedBy;
             if ($oneToManyAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $oneToManyAnnotation->targetEntity;
             } elseif (isset($propertyMetaData['elementType'])) {
                 $mapping['targetEntity'] = $propertyMetaData['elementType'];
             }
             if ($oneToManyAnnotation->cascade) {
                 $mapping['cascade'] = $oneToManyAnnotation->cascade;
             } elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
                 $mapping['cascade'] = array('persist');
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
                 $mapping['cascade'] = array('all');
             }
             $mapping['indexBy'] = $oneToManyAnnotation->indexBy;
             if ($oneToManyAnnotation->orphanRemoval) {
                 $mapping['orphanRemoval'] = $oneToManyAnnotation->orphanRemoval;
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false && $this->isValueObject($mapping['targetEntity'], $className) === false) {
                 $mapping['orphanRemoval'] = true;
             }
             $mapping['fetch'] = $this->getFetchMode($className, $oneToManyAnnotation->fetch);
             if ($orderByAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OrderBy')) {
                 $mapping['orderBy'] = $orderByAnnotation->value;
             }
             $metadata->mapOneToMany($mapping);
         } elseif ($manyToOneAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToOne')) {
             if ($manyToOneAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $manyToOneAnnotation->targetEntity;
             }
             $mapping['joinColumns'] = $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property);
             if ($manyToOneAnnotation->cascade) {
                 $mapping['cascade'] = $manyToOneAnnotation->cascade;
             } elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
                 $mapping['cascade'] = array('persist');
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
                 $mapping['cascade'] = array('all');
             }
             $mapping['inversedBy'] = $manyToOneAnnotation->inversedBy;
             $mapping['fetch'] = $this->getFetchMode($className, $manyToOneAnnotation->fetch);
             $metadata->mapManyToOne($mapping);
         } elseif ($manyToManyAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToMany')) {
             if ($manyToManyAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $manyToManyAnnotation->targetEntity;
             } elseif (isset($propertyMetaData['elementType'])) {
                 $mapping['targetEntity'] = $propertyMetaData['elementType'];
             }
             /** @var JoinTable $joinTableAnnotation */
             if ($joinTableAnnotation = $this->reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\JoinTable')) {
                 $joinTable = $this->evaluateJoinTableAnnotation($joinTableAnnotation, $property, $className, $mapping);
             } else {
                 $joinColumns = array(array('name' => null, 'referencedColumnName' => null));
                 $joinTable = array('name' => $this->inferJoinTableNameFromClassAndPropertyName($className, $property->getName()), 'joinColumns' => $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property, self::MAPPING_MM_REGULAR), 'inverseJoinColumns' => $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property));
             }
//.........这里部分代码省略.........
开发者ID:robertlemke,项目名称:flow-development-collection,代码行数:101,代码来源:FlowAnnotationDriver.php

示例8: mapValuesOnAttribute

 /**
  * @param string $attributeValueClass
  * @param ClassMetadataInfo $metadata
  */
 private function mapValuesOnAttribute($attributeValueClass, ClassMetadataInfo $metadata)
 {
     $valuesMapping = ['fieldName' => 'values', 'targetEntity' => $attributeValueClass, 'mappedBy' => 'attribute'];
     $metadata->mapOneToMany($valuesMapping);
 }
开发者ID:loic425,项目名称:Sylius,代码行数:9,代码来源:LoadMetadataSubscriber.php

示例9: evaluatePropertyAnnotations

 /**
  * Evaluate the property annotations and amend the metadata accordingly.
  *
  * @param ORM\ClassMetadataInfo $metadata
  * @return void
  * @throws ORM\MappingException
  */
 protected function evaluatePropertyAnnotations(ORM\ClassMetadataInfo $metadata)
 {
     $className = $metadata->name;
     $class = $metadata->getReflectionClass();
     $classSchema = $this->getClassSchema($className);
     foreach ($class->getProperties() as $property) {
         if (!$classSchema->hasProperty($property->getName()) || $classSchema->isPropertyTransient($property->getName()) || $metadata->isMappedSuperclass && !$property->isPrivate() || $metadata->isInheritedField($property->getName()) || $metadata->isInheritedAssociation($property->getName()) || $metadata->isInheritedEmbeddedClass($property->getName())) {
             continue;
         }
         $propertyMetaData = $classSchema->getProperty($property->getName());
         $mapping = [];
         $mapping['fieldName'] = $property->getName();
         $mapping['columnName'] = strtolower($property->getName());
         $mapping['targetEntity'] = $propertyMetaData['type'];
         $joinColumns = $this->evaluateJoinColumnAnnotations($property);
         // Field can only be annotated with one of:
         // @OneToOne, @OneToMany, @ManyToOne, @ManyToMany, @Column (optional)
         if ($oneToOneAnnotation = $this->reader->getPropertyAnnotation($property, ORM\OneToOne::class)) {
             if ($this->reader->getPropertyAnnotation($property, ORM\Id::class) !== null) {
                 $mapping['id'] = true;
             }
             if ($oneToOneAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $oneToOneAnnotation->targetEntity;
             }
             if ($oneToOneAnnotation->inversedBy !== null || $oneToOneAnnotation->mappedBy === null) {
                 $mapping['joinColumns'] = $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property);
             }
             $mapping['mappedBy'] = $oneToOneAnnotation->mappedBy;
             $mapping['inversedBy'] = $oneToOneAnnotation->inversedBy;
             if ($oneToOneAnnotation->cascade) {
                 $mapping['cascade'] = $oneToOneAnnotation->cascade;
             } elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
                 $mapping['cascade'] = ['persist'];
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
                 $mapping['cascade'] = ['all'];
             }
             if ($oneToOneAnnotation->orphanRemoval) {
                 $mapping['orphanRemoval'] = $oneToOneAnnotation->orphanRemoval;
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false && $this->isValueObject($mapping['targetEntity'], $className) === false) {
                 $mapping['orphanRemoval'] = true;
             }
             $mapping['fetch'] = $this->getFetchMode($className, $oneToOneAnnotation->fetch);
             $metadata->mapOneToOne($mapping);
         } elseif ($oneToManyAnnotation = $this->reader->getPropertyAnnotation($property, ORM\OneToMany::class)) {
             $mapping['mappedBy'] = $oneToManyAnnotation->mappedBy;
             if ($oneToManyAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $oneToManyAnnotation->targetEntity;
             } elseif (isset($propertyMetaData['elementType'])) {
                 $mapping['targetEntity'] = $propertyMetaData['elementType'];
             }
             if ($oneToManyAnnotation->cascade) {
                 $mapping['cascade'] = $oneToManyAnnotation->cascade;
             } elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
                 $mapping['cascade'] = ['persist'];
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
                 $mapping['cascade'] = ['all'];
             }
             $mapping['indexBy'] = $oneToManyAnnotation->indexBy;
             if ($oneToManyAnnotation->orphanRemoval) {
                 $mapping['orphanRemoval'] = $oneToManyAnnotation->orphanRemoval;
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false && $this->isValueObject($mapping['targetEntity'], $className) === false) {
                 $mapping['orphanRemoval'] = true;
             }
             $mapping['fetch'] = $this->getFetchMode($className, $oneToManyAnnotation->fetch);
             if ($orderByAnnotation = $this->reader->getPropertyAnnotation($property, ORM\OrderBy::class)) {
                 $mapping['orderBy'] = $orderByAnnotation->value;
             }
             $metadata->mapOneToMany($mapping);
         } elseif ($manyToOneAnnotation = $this->reader->getPropertyAnnotation($property, ORM\ManyToOne::class)) {
             if ($this->reader->getPropertyAnnotation($property, ORM\Id::class) !== null) {
                 $mapping['id'] = true;
             }
             if ($manyToOneAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $manyToOneAnnotation->targetEntity;
             }
             $mapping['joinColumns'] = $this->buildJoinColumnsIfNeeded($joinColumns, $mapping, $property);
             if ($manyToOneAnnotation->cascade) {
                 $mapping['cascade'] = $manyToOneAnnotation->cascade;
             } elseif ($this->isValueObject($mapping['targetEntity'], $className)) {
                 $mapping['cascade'] = ['persist'];
             } elseif ($this->isAggregateRoot($mapping['targetEntity'], $className) === false) {
                 $mapping['cascade'] = ['all'];
             }
             $mapping['inversedBy'] = $manyToOneAnnotation->inversedBy;
             $mapping['fetch'] = $this->getFetchMode($className, $manyToOneAnnotation->fetch);
             $metadata->mapManyToOne($mapping);
         } elseif ($manyToManyAnnotation = $this->reader->getPropertyAnnotation($property, ORM\ManyToMany::class)) {
             if ($manyToManyAnnotation->targetEntity) {
                 $mapping['targetEntity'] = $manyToManyAnnotation->targetEntity;
             } elseif (isset($propertyMetaData['elementType'])) {
                 $mapping['targetEntity'] = $propertyMetaData['elementType'];
             }
             /** @var ORM\JoinTable $joinTableAnnotation */
//.........这里部分代码省略.........
开发者ID:mkeitsch,项目名称:flow-development-collection,代码行数:101,代码来源:FlowAnnotationDriver.php

示例10: loadMetadataForClass


//.........这里部分代码省略.........
                 if (isset($oneToOneElement->{'join-column'})) {
                     $joinColumns[] = $this->_getJoinColumnMapping($oneToOneElement->{'join-column'});
                 } else {
                     if (isset($oneToOneElement->{'join-columns'})) {
                         foreach ($oneToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
                             $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement);
                         }
                     }
                 }
                 $mapping['joinColumns'] = $joinColumns;
             }
             if (isset($oneToOneElement->cascade)) {
                 $mapping['cascade'] = $this->_getCascadeMappings($oneToOneElement->cascade);
             }
             if (isset($oneToOneElement->{'orphan-removal'})) {
                 $mapping['orphanRemoval'] = (bool) $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\\AssociationMapping::FETCH_' . (string) $oneToManyElement['fetch']);
             }
             if (isset($oneToManyElement->cascade)) {
                 $mapping['cascade'] = $this->_getCascadeMappings($oneToManyElement->cascade);
             }
             if (isset($oneToManyElement->{'orphan-removal'})) {
                 $mapping['orphanRemoval'] = (bool) $oneToManyElement->{'orphan-removal'};
             }
             $metadata->mapOneToMany($mapping);
         }
     }
     // Evaluate <many-to-one ...> mappings
     if (isset($xmlRoot->{'many-to-one'})) {
         foreach ($xmlRoot->{'many-to-one'} as $manyToOneElement) {
             $mapping = array('fieldName' => (string) $manyToOneElement['field'], 'targetEntity' => (string) $manyToOneElement['target-entity']);
             if (isset($manyToOneElement['fetch'])) {
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . (string) $manyToOneElement['fetch']);
             }
             $joinColumns = array();
             if (isset($manyToOneElement->{'join-column'})) {
                 $joinColumns[] = $this->_getJoinColumnMapping($manyToOneElement->{'join-column'});
             } else {
                 if (isset($manyToOneElement->{'join-columns'})) {
                     foreach ($manyToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
                         if (!isset($joinColumnElement['name'])) {
                             $joinColumnElement['name'] = $name;
                         }
                         $joinColumns[] = $this->_getJoinColumnMapping($joinColumnElement);
                     }
                 }
             }
             $mapping['joinColumns'] = $joinColumns;
             if (isset($manyToOneElement->cascade)) {
                 $mapping['cascade'] = $this->_getCascadeMappings($manyToOneElement->cascade);
             }
             if (isset($manyToOneElement->{'orphan-removal'})) {
                 $mapping['orphanRemoval'] = (bool) $manyToOneElement->{'orphan-removal'};
             }
             $metadata->mapManyToOne($mapping);
         }
     }
开发者ID:nvdnkpr,项目名称:symfony-demo,代码行数:67,代码来源:XmlDriver.php

示例11: loadMetadataForClass


//.........这里部分代码省略.........
             }
             if (isset($columnAnnot->columnDefinition)) {
                 $mapping['columnDefinition'] = $columnAnnot->columnDefinition;
             }
             if ($idAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\Id')) {
                 $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 ($versionAnnot = $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 ($tblGeneratorAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\TableGenerator')) {
                     throw MappingException::tableIdGeneratorNotImplemented($className);
                 }
             }
         } else {
             if ($oneToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\OneToOne')) {
                 $mapping['targetEntity'] = $oneToOneAnnot->targetEntity;
                 $mapping['joinColumns'] = $joinColumns;
                 $mapping['mappedBy'] = $oneToOneAnnot->mappedBy;
                 $mapping['cascade'] = $oneToOneAnnot->cascade;
                 $mapping['orphanRemoval'] = $oneToOneAnnot->orphanRemoval;
                 $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . $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['orphanRemoval'] = $oneToManyAnnot->orphanRemoval;
                     $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . $oneToManyAnnot->fetch);
                     $metadata->mapOneToMany($mapping);
                 } else {
                     if ($manyToOneAnnot = $this->_reader->getPropertyAnnotation($property, 'Doctrine\\ORM\\Mapping\\ManyToOne')) {
                         $mapping['joinColumns'] = $joinColumns;
                         $mapping['cascade'] = $manyToOneAnnot->cascade;
                         $mapping['targetEntity'] = $manyToOneAnnot->targetEntity;
                         $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . $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'][] = array('name' => $joinColumn->name, 'referencedColumnName' => $joinColumn->referencedColumnName, 'unique' => $joinColumn->unique, 'nullable' => $joinColumn->nullable, 'onDelete' => $joinColumn->onDelete, 'onUpdate' => $joinColumn->onUpdate, 'columnDefinition' => $joinColumn->columnDefinition);
                                 }
                                 foreach ($joinTableAnnot->inverseJoinColumns as $joinColumn) {
                                     $joinTable['inverseJoinColumns'][] = array('name' => $joinColumn->name, 'referencedColumnName' => $joinColumn->referencedColumnName, 'unique' => $joinColumn->unique, 'nullable' => $joinColumn->nullable, 'onDelete' => $joinColumn->onDelete, 'onUpdate' => $joinColumn->onUpdate, 'columnDefinition' => $joinColumn->columnDefinition);
                                 }
                             }
                             $mapping['joinTable'] = $joinTable;
                             $mapping['targetEntity'] = $manyToManyAnnot->targetEntity;
                             $mapping['mappedBy'] = $manyToManyAnnot->mappedBy;
                             $mapping['cascade'] = $manyToManyAnnot->cascade;
                             $mapping['fetch'] = constant('Doctrine\\ORM\\Mapping\\AssociationMapping::FETCH_' . $manyToManyAnnot->fetch);
                             $metadata->mapManyToMany($mapping);
                         }
                     }
                 }
             }
         }
     }
     // Evaluate HasLifecycleCallbacks annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\HasLifecycleCallbacks'])) {
         foreach ($class->getMethods() as $method) {
             if ($method->isPublic()) {
                 $annotations = $this->_reader->getMethodAnnotations($method);
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PrePersist'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::prePersist);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PostPersist'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postPersist);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PreUpdate'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::preUpdate);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PostUpdate'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postUpdate);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PreRemove'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::preRemove);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PostRemove'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postRemove);
                 }
                 if (isset($annotations['Doctrine\\ORM\\Mapping\\PostLoad'])) {
                     $metadata->addLifecycleCallback($method->getName(), \Doctrine\ORM\Events::postLoad);
                 }
             }
         }
     }
 }
开发者ID:nvdnkpr,项目名称:symfony-demo,代码行数:101,代码来源:AnnotationDriver.php

示例12: mapOneToManyField

 private function mapOneToManyField($name, array $mapping, ClassMetadataInfo $metadata)
 {
     $oneToMany = array('fieldName' => $name, 'targetEntity' => $mapping['typeParenthese'], 'mappedBy' => $mapping['mappedBy']);
     if (isset($mapping['targetEntity'])) {
         $oneToMany['targetEntity'] = $mapping['targetEntity'];
     }
     if (isset($mapping['fetch'])) {
         $oneToMany['fetch'] = constant(sprintf('Doctrine\\ORM\\Mapping\\ClassMetadata::FETCH_%s', $mapping['fetch']));
     }
     if (isset($mapping['cascade'])) {
         $oneToMany['cascade'] = $mapping['cascade'];
     }
     if (isset($mapping['orphanRemoval'])) {
         $oneToMany['orphanRemoval'] = (bool) $mapping['orphanRemoval'];
     }
     if (isset($mapping['orderBy'])) {
         $oneToMany['orderBy'] = $mapping['orderBy'];
     }
     if (isset($mapping['indexBy'])) {
         $oneToMany['indexBy'] = $mapping['indexBy'];
     }
     $metadata->mapOneToMany($oneToMany);
 }
开发者ID:ruian,项目名称:KnpRadBundle,代码行数:23,代码来源:YamlDriver.php

示例13: buildBiDirecionalToOneAssociationMappings

 /**
  * Build to one (one to one, many to one) association mapping from class metadata with bi-direcional entities
  *
  * @param \Doctrine\ORM\Mapping\ClassMetadataInfo $metadata
  */
 private function buildBiDirecionalToOneAssociationMappings(ClassMetadataInfo $metadata)
 {
     $tableName = $metadata->table['name'];
     $foreignKeys = $this->getTableForeignKeys($this->tables[$tableName]);
     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);
         for ($i = 0; $i < count($cols); $i++) {
             $associationMapping['joinColumns'][] = array('name' => $cols[$i], 'referencedColumnName' => $fkCols[$i]);
         }
         $metadata->mapManyToOne($associationMapping);
     }
     foreach ($this->tables as $tableCandidate) {
         if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
             $foreignKeysCandidate = $tableCandidate->getForeignKeys();
         } else {
             $foreignKeysCandidate = array();
         }
         foreach ($foreignKeysCandidate as $foreignKey) {
             $foreignTable = $foreignKey->getForeignTableName();
             if ($foreignTable == $tableName && !isset($this->manyToManyTables[$tableCandidate->getName()])) {
                 $fkCols = $foreignKey->getForeignColumns();
                 $cols = $foreignKey->getColumns();
                 $localColumn = current($cols);
                 $associationMapping = array();
                 $associationMapping['fieldName'] = $this->getFieldNameForColumn($tableCandidate->getName(), $tableCandidate->getName(), true);
                 $associationMapping['targetEntity'] = $this->getClassNameForTable($tableCandidate->getName());
                 $associationMapping['mappedBy'] = $this->getFieldNameForColumn($tableCandidate->getName(), $localColumn, true);
                 try {
                     $primaryKeyColumns = $tableCandidate->getPrimaryKey()->getColumns();
                     if (count($primaryKeyColumns) == 1) {
                         $indexColumn = current($primaryKeyColumns);
                         $associationMapping['indexBy'] = $indexColumn;
                     }
                 } catch (SchemaException $e) {
                 }
                 $metadata->mapOneToMany($associationMapping);
             }
         }
     }
 }
开发者ID:controleonline,项目名称:core,代码行数:51,代码来源:RestDriver.php


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