當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ClassMetadata::mapOneToMany方法代碼示例

本文整理匯總了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::mapOneToMany方法的典型用法代碼示例。如果您正苦於以下問題:PHP ClassMetadata::mapOneToMany方法的具體用法?PHP ClassMetadata::mapOneToMany怎麽用?PHP ClassMetadata::mapOneToMany使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\Common\Persistence\Mapping\ClassMetadata的用法示例。


在下文中一共展示了ClassMetadata::mapOneToMany方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: mapOneToMany

 private function mapOneToMany(ClassMetadata $metadata)
 {
     foreach ($this->variables as $class) {
         if ($class['option']['model'] !== $metadata->getName()) {
             continue;
         }
         $metadata->mapOneToMany(array('fieldName' => 'values', 'targetEntity' => $class['option_value']['model'], 'mappedBy' => 'option', 'cascade' => array('all')));
     }
 }
開發者ID:bcremer,項目名稱:Sylius,代碼行數:9,代碼來源:LoadMetadataSubscriber.php

示例2: mapTranslatable

 /**
  * {@inheritDoc}
  */
 public function mapTranslatable(ClassMetadata $meta, $translationClassName)
 {
     $rc = $meta->getReflectionClass();
     if (!$rc->hasProperty('translations') || $meta->hasAssociation('translations') || !$rc->isSubclassOf($this->translatableClass)) {
         return;
     }
     if (!$meta->hasAssociation('translations')) {
         $meta->mapOneToMany(['targetEntity' => $translationClassName, 'fieldName' => 'translations', 'mappedBy' => 'object', 'orphanRemoval' => true, 'cascade' => ['persist', 'remove'], 'fetch' => 'EXTRA_LAZY', 'inherited' => $this->getRootObjectClass($meta)]);
     }
 }
開發者ID:coolms,項目名稱:doctrine,代碼行數:13,代碼來源:ORM.php

示例3: mapOneToMany

 /**
  * @param ClassMetadata $metadata
  */
 private function mapOneToMany(ClassMetadata $metadata)
 {
     foreach ($this->variables as $class) {
         if ($class['option']['classes']['model'] !== $metadata->getName()) {
             continue;
         }
         $mapping = ['fieldName' => 'values', 'targetEntity' => $class['option_value']['classes']['model'], 'mappedBy' => 'option', 'orphanRemoval' => true, 'cascade' => ['all']];
         $metadata->mapOneToMany($mapping);
     }
 }
開發者ID:ReissClothing,項目名稱:Sylius,代碼行數:13,代碼來源:LoadMetadataSubscriber.php

示例4: mapHierarchy

 /**
  * {@inheritDoc}
  */
 public function mapHierarchy(ClassMetadata $meta)
 {
     if ($meta->isMappedSuperclass || !$meta->isRootEntity()) {
         return;
     }
     $rc = $meta->getReflectionClass();
     if ($rc->hasProperty('parent') && !$meta->hasAssociation('parent')) {
         $meta->mapManyToOne(['targetEntity' => $meta->getName(), 'fieldName' => 'parent', 'inversedBy' => 'children', 'cascade' => ['persist']]);
     }
     if ($rc->hasProperty('children') && !$meta->hasAssociation('children')) {
         $meta->mapOneToMany(['targetEntity' => $meta->getName(), 'fieldName' => 'children', 'mappedBy' => 'parent', 'cascade' => ['persist', 'remove'], 'fetch' => 'EXTRA_LAZY']);
     }
 }
開發者ID:coolms,項目名稱:doctrine,代碼行數:16,代碼來源:ORM.php

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

示例6: loadMetadataForClass


//.........這裏部分代碼省略.........
             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);
         }
     }
     // 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->joinColumnToArray($manyToOneElement->{'join-column'});
             } else {
                 if (isset($manyToOneElement->{'join-columns'})) {
                     foreach ($manyToOneElement->{'join-columns'}->{'join-column'} as $joinColumnElement) {
                         $joinColumns[] = $this->joinColumnToArray($joinColumnElement);
                     }
                 }
             }
             $mapping['joinColumns'] = $joinColumns;
             if (isset($manyToOneElement->cascade)) {
                 $mapping['cascade'] = $this->_getCascadeMappings($manyToOneElement->cascade);
             }
             $metadata->mapManyToOne($mapping);
         }
     }
開發者ID:dracony,項目名稱:forked-php-orm-benchmark,代碼行數:67,代碼來源:XmlDriver.php

示例7: loadMetadataForClass


//.........這裏部分代碼省略.........
             } 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) {
                                     $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')) {
開發者ID:aschempp,項目名稱:doctrine2,代碼行數:67,代碼來源:AnnotationDriver.php

示例8: loadMetadataForClass


//.........這裏部分代碼省略.........
             }
             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']));
             }
         }
     }
     // 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->joinColumnToArray($manyToOneElement['joinColumn']);
             } else {
                 if (isset($manyToOneElement['joinColumns'])) {
                     foreach ($manyToOneElement['joinColumns'] as $joinColumnName => $joinColumnElement) {
                         if (!isset($joinColumnElement['name'])) {
                             $joinColumnElement['name'] = $joinColumnName;
                         }
                         $joinColumns[] = $this->joinColumnToArray($joinColumnElement);
                     }
                 }
             }
開發者ID:dracony,項目名稱:forked-php-orm-benchmark,代碼行數:67,代碼來源:YamlDriver.php

示例9: 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::mapOneToMany方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。