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


PHP ClassMetadata::setPrimaryTable方法代码示例

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


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

示例1: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string        $className
  * @param ClassMetadata $metadata
  *
  * @throws \Exception
  * @return void
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     if (!$metadata instanceof \Doctrine\ORM\Mapping\ClassMetadata) {
         throw new \Exception('Error: class metadata object is the wrong type');
     }
     $refClass = new \ReflectionClass($className);
     $classDocBlock = $refClass->getDocComment();
     if (!$classDocBlock || strpos($classDocBlock, '@Table') === false) {
         $metadata->setPrimaryTable(['name' => $this->_getTableName($className)]);
     }
     $needAutoGenerator = false;
     foreach ($refClass->getProperties(\ReflectionProperty::IS_PUBLIC) as $prop) {
         $propName = $prop->getName();
         try {
             $mapping = $metadata->getFieldMapping($propName);
         } catch (MappingException $e) {
             $mapping = null;
         }
         if (!$mapping) {
             if ($propName == 'createdAt') {
                 if (!$this->isTransient($className) && !$refClass->isAbstract() && call_user_func($className . '::useAutoTimestamp')) {
                     $metadata->mapField(['fieldName' => 'createdAt', 'columnName' => call_user_func($className . '::getCreatedAtColumn'), 'type' => 'datetime']);
                 }
             } else {
                 if ($propName == 'updatedAt') {
                     if (!$this->isTransient($className) && !$refClass->isAbstract() && call_user_func($className . '::useAutoTimestamp')) {
                         $metadata->mapField(['fieldName' => 'updatedAt', 'columnName' => call_user_func($className . '::getUpdatedAtColumn'), 'type' => 'datetime']);
                     }
                 } else {
                     $columnName = Inflector::tableize($propName);
                     $fieldMap = ['fieldName' => $propName, 'columnName' => $columnName, 'type' => $this->_getDefaultDataType($columnName)];
                     if ($columnName == 'id') {
                         $fieldMap['id'] = true;
                         $fieldMap['autoincrement'] = true;
                         $fieldMap['unsigned'] = true;
                         $needAutoGenerator = true;
                     } else {
                         if (in_array($columnName, ['price', 'tax', 'amount', 'cost', 'total'])) {
                             // DECIMAL(10,2)
                             $fieldMap['precision'] = 10;
                             $fieldMap['scale'] = 2;
                         }
                     }
                     $metadata->mapField($fieldMap);
                 }
             }
         }
     }
     if ($needAutoGenerator && !$metadata->usesIdGenerator()) {
         $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_AUTO);
     }
 }
开发者ID:packaged,项目名称:mappers,代码行数:61,代码来源:AutoMappingDriver.php

示例2: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string        $className
  * @param ClassMetadata $metadata
  *
  * @return void
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     if (!$this->isTransient($className)) {
         throw new MappingException('Class ' . $className . 'has no appropriate ModelConfiguration');
     }
     $modelConfig = $className::getConfiguration();
     $table = $modelConfig->getTable();
     $table['name'] = SQL_TABLE_PREFIX . $table['name'];
     $metadata->setPrimaryTable($table);
     foreach ($modelConfig->getFields() as $fieldName => $config) {
         self::mapTypes($config);
         if (!$config['doctrineIgnore']) {
             $metadata->mapField($config);
         }
     }
 }
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:24,代码来源:DoctrineMappingDriver.php

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

示例4: loadMetadataForClass

 /**
  * {@inheritDoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */
     /* @var $xmlRoot SimpleXMLElement */
     $xmlRoot = $this->getElement($className);
     if ($xmlRoot->getName() == 'entity') {
         if (isset($xmlRoot['repository-class'])) {
             $metadata->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
         }
         if (isset($xmlRoot['read-only']) && $this->evaluateBoolean($xmlRoot['read-only'])) {
             $metadata->markReadOnly();
         }
     } else {
         if ($xmlRoot->getName() == 'mapped-superclass') {
             $metadata->setCustomRepositoryClass(isset($xmlRoot['repository-class']) ? (string) $xmlRoot['repository-class'] : null);
             $metadata->isMappedSuperclass = true;
         } else {
             throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
         }
     }
     // Evaluate <entity...> attributes
     $table = array();
     if (isset($xmlRoot['table'])) {
         $table['name'] = (string) $xmlRoot['table'];
     }
     $metadata->setPrimaryTable($table);
     // Evaluate named queries
     if (isset($xmlRoot->{'named-queries'})) {
         foreach ($xmlRoot->{'named-queries'}->{'named-query'} as $namedQueryElement) {
             $metadata->addNamedQuery(array('name' => (string) $namedQueryElement['name'], 'query' => (string) $namedQueryElement['query']));
         }
     }
     // Evaluate native named queries
     if (isset($xmlRoot->{'named-native-queries'})) {
         foreach ($xmlRoot->{'named-native-queries'}->{'named-native-query'} as $nativeQueryElement) {
             $metadata->addNamedNativeQuery(array('name' => isset($nativeQueryElement['name']) ? (string) $nativeQueryElement['name'] : null, 'query' => isset($nativeQueryElement->query) ? (string) $nativeQueryElement->query : null, 'resultClass' => isset($nativeQueryElement['result-class']) ? (string) $nativeQueryElement['result-class'] : null, 'resultSetMapping' => isset($nativeQueryElement['result-set-mapping']) ? (string) $nativeQueryElement['result-set-mapping'] : null));
         }
     }
     // Evaluate sql result set mapping
     if (isset($xmlRoot->{'sql-result-set-mappings'})) {
         foreach ($xmlRoot->{'sql-result-set-mappings'}->{'sql-result-set-mapping'} as $rsmElement) {
             $entities = array();
             $columns = array();
             foreach ($rsmElement as $entityElement) {
                 //<entity-result/>
                 if (isset($entityElement['entity-class'])) {
                     $entityResult = array('fields' => array(), 'entityClass' => (string) $entityElement['entity-class'], 'discriminatorColumn' => isset($entityElement['discriminator-column']) ? (string) $entityElement['discriminator-column'] : null);
                     foreach ($entityElement as $fieldElement) {
                         $entityResult['fields'][] = array('name' => isset($fieldElement['name']) ? (string) $fieldElement['name'] : null, 'column' => isset($fieldElement['column']) ? (string) $fieldElement['column'] : null);
                     }
                     $entities[] = $entityResult;
                 }
                 //<column-result/>
                 if (isset($entityElement['name'])) {
                     $columns[] = array('name' => (string) $entityElement['name']);
                 }
             }
             $metadata->addSqlResultSetMapping(array('name' => (string) $rsmElement['name'], 'entities' => $entities, 'columns' => $columns));
         }
     }
     /* not implemented specially anyway. use table = schema.table
        if (isset($xmlRoot['schema'])) {
            $metadata->table['schema'] = (string)$xmlRoot['schema'];
        }*/
     if (isset($xmlRoot['inheritance-type'])) {
         $inheritanceType = (string) $xmlRoot['inheritance-type'];
         $metadata->setInheritanceType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceType));
         if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
             // Evaluate <discriminator-column...>
             if (isset($xmlRoot->{'discriminator-column'})) {
                 $discrColumn = $xmlRoot->{'discriminator-column'};
                 $metadata->setDiscriminatorColumn(array('name' => isset($discrColumn['name']) ? (string) $discrColumn['name'] : null, 'type' => isset($discrColumn['type']) ? (string) $discrColumn['type'] : null, 'length' => isset($discrColumn['length']) ? (string) $discrColumn['length'] : null, 'columnDefinition' => isset($discrColumn['column-definition']) ? (string) $discrColumn['column-definition'] : null));
             } else {
                 $metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
             }
             // Evaluate <discriminator-map...>
             if (isset($xmlRoot->{'discriminator-map'})) {
                 $map = array();
                 foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) {
                     $map[(string) $discrMapElement['value']] = (string) $discrMapElement['class'];
                 }
                 $metadata->setDiscriminatorMap($map);
             }
         }
     }
     // Evaluate <change-tracking-policy...>
     if (isset($xmlRoot['change-tracking-policy'])) {
         $metadata->setChangeTrackingPolicy(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper((string) $xmlRoot['change-tracking-policy'])));
     }
     // Evaluate <indexes...>
     if (isset($xmlRoot->indexes)) {
         $metadata->table['indexes'] = array();
         foreach ($xmlRoot->indexes->index as $index) {
             $columns = explode(',', (string) $index['columns']);
             if (isset($index['name'])) {
                 $metadata->table['indexes'][(string) $index['name']] = array('columns' => $columns);
             } else {
//.........这里部分代码省略.........
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:101,代码来源:XmlDriver.php

示例5: loadMetadataForClass

 /**
  * {@inheritDoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */
     $class = $metadata->getReflectionClass();
     if (!$class) {
         // this happens when running annotation driver in combination with
         // static reflection services. This is not the nicest fix
         $class = new \ReflectionClass($metadata->name);
     }
     $classAnnotations = $this->reader->getClassAnnotations($class);
     if ($classAnnotations) {
         foreach ($classAnnotations as $key => $annot) {
             if (!is_numeric($key)) {
                 continue;
             }
             $classAnnotations[get_class($annot)] = $annot;
         }
     }
     // Evaluate Entity annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Entity'])) {
         $entityAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\Entity'];
         if ($entityAnnot->repositoryClass !== null) {
             $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass);
         }
         if ($entityAnnot->readOnly) {
             $metadata->markReadOnly();
         }
     } else {
         if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\MappedSuperclass'])) {
             $mappedSuperclassAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\MappedSuperclass'];
             $metadata->setCustomRepositoryClass($mappedSuperclassAnnot->repositoryClass);
             $metadata->isMappedSuperclass = true;
         } else {
             if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Embeddable'])) {
                 $metadata->isEmbeddedClass = true;
             } else {
                 throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
             }
         }
     }
     // Evaluate Table annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Table'])) {
         $tableAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\Table'];
         $primaryTable = array('name' => $tableAnnot->name, 'schema' => $tableAnnot->schema);
         if ($tableAnnot->indexes !== null) {
             foreach ($tableAnnot->indexes as $indexAnnot) {
                 $index = array('columns' => $indexAnnot->columns);
                 if (!empty($indexAnnot->flags)) {
                     $index['flags'] = $indexAnnot->flags;
                 }
                 if (!empty($indexAnnot->options)) {
                     $index['options'] = $indexAnnot->options;
                 }
                 if (!empty($indexAnnot->name)) {
                     $primaryTable['indexes'][$indexAnnot->name] = $index;
                 } else {
                     $primaryTable['indexes'][] = $index;
                 }
             }
         }
         if ($tableAnnot->uniqueConstraints !== null) {
             foreach ($tableAnnot->uniqueConstraints as $uniqueConstraintAnnot) {
                 $uniqueConstraint = array('columns' => $uniqueConstraintAnnot->columns);
                 if (!empty($uniqueConstraintAnnot->options)) {
                     $uniqueConstraint['options'] = $uniqueConstraintAnnot->options;
                 }
                 if (!empty($uniqueConstraintAnnot->name)) {
                     $primaryTable['uniqueConstraints'][$uniqueConstraintAnnot->name] = $uniqueConstraint;
                 } else {
                     $primaryTable['uniqueConstraints'][] = $uniqueConstraint;
                 }
             }
         }
         if ($tableAnnot->options) {
             $primaryTable['options'] = $tableAnnot->options;
         }
         $metadata->setPrimaryTable($primaryTable);
     }
     // Evaluate @Cache annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\Cache'])) {
         $cacheAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\Cache'];
         $cacheMap = array('region' => $cacheAnnot->region, 'usage' => constant('Doctrine\\ORM\\Mapping\\ClassMetadata::CACHE_USAGE_' . $cacheAnnot->usage));
         $metadata->enableCache($cacheMap);
     }
     // Evaluate NamedNativeQueries annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\NamedNativeQueries'])) {
         $namedNativeQueriesAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\NamedNativeQueries'];
         foreach ($namedNativeQueriesAnnot->value as $namedNativeQuery) {
             $metadata->addNamedNativeQuery(array('name' => $namedNativeQuery->name, 'query' => $namedNativeQuery->query, 'resultClass' => $namedNativeQuery->resultClass, 'resultSetMapping' => $namedNativeQuery->resultSetMapping));
         }
     }
     // Evaluate SqlResultSetMappings annotation
     if (isset($classAnnotations['Doctrine\\ORM\\Mapping\\SqlResultSetMappings'])) {
         $sqlResultSetMappingsAnnot = $classAnnotations['Doctrine\\ORM\\Mapping\\SqlResultSetMappings'];
         foreach ($sqlResultSetMappingsAnnot->value as $resultSetMapping) {
             $entities = array();
             $columns = array();
//.........这里部分代码省略.........
开发者ID:aschempp,项目名称:doctrine2,代码行数:101,代码来源:AnnotationDriver.php

示例6: loadMetadataForClass

 /**
  * {@inheritDoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */
     $element = $this->getElement($className);
     if ($element['type'] == 'entity') {
         if (isset($element['repositoryClass'])) {
             $metadata->setCustomRepositoryClass($element['repositoryClass']);
         }
         if (isset($element['readOnly']) && $element['readOnly'] == true) {
             $metadata->markReadOnly();
         }
     } else {
         if ($element['type'] == 'mappedSuperclass') {
             $metadata->setCustomRepositoryClass(isset($element['repositoryClass']) ? $element['repositoryClass'] : null);
             $metadata->isMappedSuperclass = true;
         } else {
             if ($element['type'] == 'embeddable') {
                 $metadata->isEmbeddedClass = true;
             } else {
                 throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
             }
         }
     }
     // Evaluate root level properties
     $table = array();
     if (isset($element['table'])) {
         $table['name'] = $element['table'];
     }
     // Evaluate second level cache
     if (isset($element['cache'])) {
         $metadata->enableCache($this->cacheToArray($element['cache']));
     }
     $metadata->setPrimaryTable($table);
     // Evaluate named queries
     if (isset($element['namedQueries'])) {
         foreach ($element['namedQueries'] as $name => $queryMapping) {
             if (is_string($queryMapping)) {
                 $queryMapping = array('query' => $queryMapping);
             }
             if (!isset($queryMapping['name'])) {
                 $queryMapping['name'] = $name;
             }
             $metadata->addNamedQuery($queryMapping);
         }
     }
     // Evaluate named native queries
     if (isset($element['namedNativeQueries'])) {
         foreach ($element['namedNativeQueries'] as $name => $mappingElement) {
             if (!isset($mappingElement['name'])) {
                 $mappingElement['name'] = $name;
             }
             $metadata->addNamedNativeQuery(array('name' => $mappingElement['name'], 'query' => isset($mappingElement['query']) ? $mappingElement['query'] : null, 'resultClass' => isset($mappingElement['resultClass']) ? $mappingElement['resultClass'] : null, 'resultSetMapping' => isset($mappingElement['resultSetMapping']) ? $mappingElement['resultSetMapping'] : null));
         }
     }
     // Evaluate sql result set mappings
     if (isset($element['sqlResultSetMappings'])) {
         foreach ($element['sqlResultSetMappings'] as $name => $resultSetMapping) {
             if (!isset($resultSetMapping['name'])) {
                 $resultSetMapping['name'] = $name;
             }
             $entities = array();
             $columns = array();
             if (isset($resultSetMapping['entityResult'])) {
                 foreach ($resultSetMapping['entityResult'] as $entityResultElement) {
                     $entityResult = array('fields' => array(), 'entityClass' => isset($entityResultElement['entityClass']) ? $entityResultElement['entityClass'] : null, 'discriminatorColumn' => isset($entityResultElement['discriminatorColumn']) ? $entityResultElement['discriminatorColumn'] : null);
                     if (isset($entityResultElement['fieldResult'])) {
                         foreach ($entityResultElement['fieldResult'] as $fieldResultElement) {
                             $entityResult['fields'][] = array('name' => isset($fieldResultElement['name']) ? $fieldResultElement['name'] : null, 'column' => isset($fieldResultElement['column']) ? $fieldResultElement['column'] : null);
                         }
                     }
                     $entities[] = $entityResult;
                 }
             }
             if (isset($resultSetMapping['columnResult'])) {
                 foreach ($resultSetMapping['columnResult'] as $columnResultAnnot) {
                     $columns[] = array('name' => isset($columnResultAnnot['name']) ? $columnResultAnnot['name'] : null);
                 }
             }
             $metadata->addSqlResultSetMapping(array('name' => $resultSetMapping['name'], 'entities' => $entities, 'columns' => $columns));
         }
     }
     /* not implemented specially anyway. use table = schema.table
        if (isset($element['schema'])) {
            $metadata->table['schema'] = $element['schema'];
        }*/
     if (isset($element['inheritanceType'])) {
         $metadata->setInheritanceType(constant('Doctrine\\ORM\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($element['inheritanceType'])));
         if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) {
             // Evaluate discriminatorColumn
             if (isset($element['discriminatorColumn'])) {
                 $discrColumn = $element['discriminatorColumn'];
                 $metadata->setDiscriminatorColumn(array('name' => isset($discrColumn['name']) ? (string) $discrColumn['name'] : null, 'type' => isset($discrColumn['type']) ? (string) $discrColumn['type'] : null, 'length' => isset($discrColumn['length']) ? (string) $discrColumn['length'] : null, 'columnDefinition' => isset($discrColumn['columnDefinition']) ? (string) $discrColumn['columnDefinition'] : null));
             } else {
                 $metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255));
             }
             // Evaluate discriminatorMap
             if (isset($element['discriminatorMap'])) {
//.........这里部分代码省略.........
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:101,代码来源:YamlDriver.php

示例7: loadMetadataForClass


//.........这里部分代码省略.........
         $builder->addField('targetEntityClass', 'string');
         $builder->addField('revisionType', 'string');
         $builder->addField('title', 'string', array('nullable' => true));
         $metadata->setTableName($moduleOptions->getRevisionEntityTableName());
         return;
     }
     // Revision is managed here rather than a separate namespace and driver
     if ($className == 'SoliantEntityAudit\\Entity\\Revision') {
         $builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();
         $builder->addField('comment', 'text', array('nullable' => true));
         $builder->addField('timestamp', 'datetime');
         // Add association between RevisionEntity and Revision
         $builder->addOneToMany('revisionEntities', 'SoliantEntityAudit\\Entity\\RevisionEntity', 'revision');
         // Add assoication between User and Revision
         $userMetadata = $metadataFactory->getMetadataFor($moduleOptions->getUserEntityClassName());
         $builder->createManyToOne('user', $userMetadata->getName())->addJoinColumn('user_id', $userMetadata->getSingleIdentifierColumnName())->build();
         $metadata->setTableName($moduleOptions->getRevisionTableName());
         return;
     }
     #        $builder->createField('audit_id', 'integer')->isPrimaryKey()->generatedValue()->build();
     $identifiers = array();
     #        $metadata->setIdentifier(array('audit_id'));
     //  Build a discovered many to many join class
     $joinClasses = $moduleOptions->getJoinClasses();
     if (in_array($className, array_keys($joinClasses))) {
         $builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();
         $builder->addManyToOne('targetRevisionEntity', 'SoliantEntityAudit\\Entity\\RevisionEntity');
         $builder->addManyToOne('sourceRevisionEntity', 'SoliantEntityAudit\\Entity\\RevisionEntity');
         $metadata->setTableName($moduleOptions->getTableNamePrefix() . $joinClasses[$className]['joinTable']['name'] . $moduleOptions->getTableNameSuffix());
         //            $metadata->setIdentifier($identifiers);
         return;
     }
     // Get the entity this entity audits
     $metadataClassName = $metadata->getName();
     $metadataClass = new $metadataClassName();
     $auditedClassMetadata = $metadataFactory->getMetadataFor($metadataClass->getAuditedEntityClass());
     try {
         $builder->addManyToOne($moduleOptions->getRevisionEntityFieldName(), 'SoliantEntityAudit\\Entity\\RevisionEntity');
     } catch (MappingException $e) {
         // do nothing
     }
     // Compound keys removed in favor of auditId (audit_id)
     $identifiers[] = $moduleOptions->getRevisionEntityFieldName();
     // Add fields from target to audit entity
     foreach ($auditedClassMetadata->getFieldNames() as $fieldName) {
         $fieldMapping = $auditedClassMetadata->getFieldMapping($fieldName);
         if (!isset($fieldMapping['inherited']) && !isset($fieldMapping['declared'])) {
             $fieldMapping['nullable'] = true;
             $fieldMapping['quoted'] = true;
             $builder->addField($fieldName, $auditedClassMetadata->getTypeOfField($fieldName), $fieldMapping);
         }
         if ($auditedClassMetadata->isIdentifier($fieldName)) {
             $identifiers[] = $fieldName;
         }
     }
     foreach ($auditedClassMetadata->getAssociationMappings() as $mapping) {
         if (!isset($mapping['inherited']) && !isset($mapping['declared'])) {
             if (!$mapping['isOwningSide']) {
                 continue;
             }
             if (isset($mapping['joinTable'])) {
                 continue;
             }
             if (isset($mapping['joinTableColumns'])) {
                 foreach ($mapping['joinTableColumns'] as $field) {
                     $builder->addField($mapping['fieldName'], 'integer', array('nullable' => true, 'columnName' => $field));
                 }
             } elseif (isset($mapping['joinColumnFieldNames'])) {
                 foreach ($mapping['joinColumnFieldNames'] as $field) {
                     $builder->addField($mapping['fieldName'], 'integer', array('nullable' => true, 'columnName' => $field));
                 }
             } else {
                 throw new \Exception('Unhandled association mapping');
             }
         }
     }
     if ($auditedClassMetadata->isInheritanceTypeJoined() || $auditedClassMetadata->isInheritanceTypeSingleTable()) {
         $metadata->setInheritanceType($auditedClassMetadata->inheritanceType);
         $metadata->setDiscriminatorColumn($auditedClassMetadata->discriminatorColumn);
         $parentAuditClasses = array();
         $subAuditClasses = array();
         foreach ($auditedClassMetadata->parentClasses as $idx => $parentClass) {
             $parentAuditClass = 'SoliantEntityAudit\\Entity\\' . str_replace('\\', '_', $parentClass);
             $parentAuditClasses[$idx] = $parentAuditClass;
         }
         $metadata->setParentClasses($parentAuditClasses);
         foreach ($auditedClassMetadata->subClasses as $idx => $subClass) {
             $subAuditClass = 'SoliantEntityAudit\\Entity\\' . str_replace('\\', '_', $subClass);
             $subAuditClasses[$idx] = $subAuditClass;
         }
         $metadata->setSubClasses($subAuditClasses);
         foreach ($auditedClassMetadata->discriminatorMap as $mapName => $mapClass) {
             $mapAuditClass = 'SoliantEntityAudit\\Entity\\' . str_replace('\\', '_', $mapClass);
             $metadata->addDiscriminatorMapClass($mapName, $mapAuditClass);
         }
     }
     $metadata->setPrimaryTable(array('name' => $moduleOptions->getTableNamePrefix() . $auditedClassMetadata->getTableName() . $moduleOptions->getTableNameSuffix()));
     $metadata->setIdentifier($identifiers);
     return;
 }
开发者ID:VOONWerbeagentur,项目名称:SoliantEntityAudit,代码行数:101,代码来源:AuditDriver.php

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

示例9: loadMetadataForClass

 /**
  * {@inheritDoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $this->reverseEngineerMappingFromDatabase();
     if (!isset($this->classToTableNames[$className])) {
         throw new \InvalidArgumentException("Unknown class " . $className);
     }
     $tableName = $this->classToTableNames[$className];
     $metadata->name = $className;
     $metadata->table['name'] = $tableName;
     $columns = $this->tables[$tableName]->getColumns();
     $indexes = $this->tables[$tableName]->getIndexes();
     $metadata->setPrimaryTable(array('indexes' => $indexes));
     try {
         $primaryKeyColumns = $this->tables[$tableName]->getPrimaryKey()->getColumns();
     } catch (SchemaException $e) {
         $primaryKeyColumns = array();
     }
     if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
         $foreignKeys = $this->tables[$tableName]->getForeignKeys();
     } else {
         $foreignKeys = array();
     }
     $allForeignKeyColumns = array();
     foreach ($foreignKeys as $foreignKey) {
         $allForeignKeyColumns = array_merge($allForeignKeyColumns, $foreignKey->getLocalColumns());
     }
     $ids = array();
     $fieldMappings = array();
     $autoincrement = false;
     foreach ($columns as $column) {
         $fieldMapping = array();
         if (in_array($column->getName(), $allForeignKeyColumns)) {
             continue;
         } else {
             if ($primaryKeyColumns && in_array($column->getName(), $primaryKeyColumns)) {
                 $fieldMapping['id'] = true;
                 if ($column->getAutoincrement()) {
                     $autoincrement = true;
                 }
             }
         }
         $fieldMapping['fieldName'] = $this->getFieldNameForColumn($tableName, $column->getName(), false);
         $fieldMapping['columnName'] = $column->getName();
         $fieldMapping['type'] = strtolower((string) $column->getType());
         $fieldMapping['default'] = $column->getType()->convertToPHPValue($column->getDefault(), $this->_sm->getDatabasePlatform());
         if ($column->getType() instanceof \Doctrine\DBAL\Types\StringType) {
             $fieldMapping['length'] = $column->getLength();
             $fieldMapping['fixed'] = $column->getFixed();
         } else {
             if ($column->getType() instanceof \Doctrine\DBAL\Types\IntegerType) {
                 $fieldMapping['unsigned'] = $column->getUnsigned();
             }
         }
         $fieldMapping['nullable'] = $column->getNotNull() ? false : true;
         if (isset($fieldMapping['id'])) {
             $ids[] = $fieldMapping;
         } else {
             $fieldMappings[] = $fieldMapping;
         }
     }
     if ($ids) {
         // We need to check for the columns here, because we might have associations as id as well.
         if (count($primaryKeyColumns) == 1) {
             $metadata->setIdGeneratorType($autoincrement ? ClassMetadataInfo::GENERATOR_TYPE_AUTO : ClassMetadataInfo::GENERATOR_TYPE_NONE);
         }
         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();
//.........这里部分代码省略.........
开发者ID:logical-and,项目名称:doctrine-patched,代码行数:101,代码来源:DatabaseDriver.php


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