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


PHP ClassMetadataInfo::getDiscriminatorColumn方法代码示例

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


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

示例1: exportClassMetadata

 /**
  * Converts a single ClassMetadata instance to the exported format
  * and returns it
  *
  * TODO: Should this code be pulled out in to a toArray() method in ClassMetadata
  *
  * @param ClassMetadataInfo $metadata 
  * @return mixed $exported
  */
 public function exportClassMetadata(ClassMetadataInfo $metadata)
 {
     $array = array();
     if ($metadata->isMappedSuperclass) {
         $array['type'] = 'mappedSuperclass';
     } else {
         $array['type'] = 'entity';
     }
     $array['table'] = $metadata->primaryTable['name'];
     if (isset($metadata->primaryTable['schema'])) {
         $array['schema'] = $metadata->primaryTable['schema'];
     }
     $inheritanceType = $metadata->getInheritanceType();
     if ($inheritanceType !== ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
         $array['inheritanceType'] = $this->_getInheritanceTypeString($inheritanceType);
     }
     if ($column = $metadata->getDiscriminatorColumn()) {
         $array['discriminatorColumn'] = $column;
     }
     if ($map = $metadata->discriminatorMap) {
         $array['discriminatorMap'] = $map;
     }
     if ($metadata->changeTrackingPolicy !== ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT) {
         $array['changeTrackingPolicy'] = $this->_getChangeTrackingPolicyString($metadata->changeTrackingPolicy);
     }
     if (isset($metadata->primaryTable['indexes'])) {
         $array['indexes'] = $metadata->primaryTable['indexes'];
     }
     if (isset($metadata->primaryTable['uniqueConstraints'])) {
         $array['uniqueConstraints'] = $metadata->primaryTable['uniqueConstraints'];
     }
     $fieldMappings = $metadata->fieldMappings;
     $ids = array();
     foreach ($fieldMappings as $name => $fieldMapping) {
         if (isset($fieldMapping['length'])) {
             $fieldMapping['type'] = $fieldMapping['type'] . '(' . $fieldMapping['length'] . ')';
             unset($fieldMapping['length']);
         }
         $fieldMapping['column'] = $fieldMapping['columnName'];
         unset($fieldMapping['columnName'], $fieldMapping['fieldName']);
         if ($fieldMapping['column'] == $name) {
             unset($fieldMapping['column']);
         }
         if (isset($fieldMapping['id']) && $fieldMapping['id']) {
             $ids[$name] = $fieldMapping;
             unset($fieldMappings[$name]);
             continue;
         }
         $fieldMappings[$name] = $fieldMapping;
     }
     if ($idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) {
         $ids[$metadata->getSingleIdentifierFieldName()]['generator']['strategy'] = $this->_getIdGeneratorTypeString($metadata->generatorType);
     }
     if ($ids) {
         $array['fields'] = $ids;
     }
     if ($fieldMappings) {
         if (!isset($array['fields'])) {
             $array['fields'] = array();
         }
         $array['fields'] = array_merge($array['fields'], $fieldMappings);
     }
     $associations = array();
     foreach ($metadata->associationMappings as $name => $associationMapping) {
         $associationMappingArray = array('targetEntity' => $associationMapping->targetEntityName, 'cascade' => array('remove' => $associationMapping->isCascadeRemove, 'persist' => $associationMapping->isCascadePersist, 'refresh' => $associationMapping->isCascadeRefresh, 'merge' => $associationMapping->isCascadeMerge, 'detach' => $associationMapping->isCascadeDetach));
         if ($associationMapping instanceof OneToOneMapping) {
             $joinColumns = $associationMapping->joinColumns;
             $newJoinColumns = array();
             foreach ($joinColumns as $joinColumn) {
                 $newJoinColumns[$joinColumn['name']]['referencedColumnName'] = $joinColumn['referencedColumnName'];
             }
             $oneToOneMappingArray = array('mappedBy' => $associationMapping->mappedByFieldName, 'joinColumns' => $newJoinColumns, 'orphanRemoval' => $associationMapping->orphanRemoval);
             $associationMappingArray = array_merge($associationMappingArray, $oneToOneMappingArray);
             $array['oneToOne'][$name] = $associationMappingArray;
         } else {
             if ($associationMapping instanceof OneToManyMapping) {
                 $oneToManyMappingArray = array('mappedBy' => $associationMapping->mappedByFieldName, 'orphanRemoval' => $associationMapping->orphanRemoval);
                 $associationMappingArray = array_merge($associationMappingArray, $oneToManyMappingArray);
                 $array['oneToMany'][$name] = $associationMappingArray;
             } else {
                 if ($associationMapping instanceof ManyToManyMapping) {
                     $manyToManyMappingArray = array('mappedBy' => $associationMapping->mappedByFieldName, 'joinTable' => $associationMapping->joinTable);
                     $associationMappingArray = array_merge($associationMappingArray, $manyToManyMappingArray);
                     $array['manyToMany'][$name] = $associationMappingArray;
                 }
             }
         }
     }
     return \sfYaml::dump(array($metadata->name => $array), 10);
 }
开发者ID:nvdnkpr,项目名称:symfony-demo,代码行数:99,代码来源:YamlExporter.php


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