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


PHP ClassMetadataInfo::getIdGeneratorType方法代码示例

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


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

示例1: exportClassMetadata

 /**
  * Converts a single ClassMetadata instance to the exported format
  * and returns it
  *
  * @param ClassMetadataInfo $metadata 
  * @return mixed $exported
  */
 public function exportClassMetadata(ClassMetadataInfo $metadata)
 {
     $xml = new \SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><doctrine-mapping/>");
     $xml->addAttribute('xmlns', 'http://doctrine-project.org/schemas/orm/doctrine-mapping');
     $xml->addAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     $xml->addAttribute('xsi:schemaLocation', 'http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd');
     if ($metadata->isMappedSuperclass) {
         $root = $xml->addChild('mapped-superclass');
     } else {
         $root = $xml->addChild('entity');
     }
     if ($metadata->customRepositoryClassName) {
         $root->addAttribute('repository-class', $metadata->customRepositoryClassName);
     }
     $root->addAttribute('name', $metadata->name);
     if (isset($metadata->primaryTable['name'])) {
         $root->addAttribute('table', $metadata->primaryTable['name']);
     }
     if (isset($metadata->primaryTable['schema'])) {
         $root->addAttribute('schema', $metadata->primaryTable['schema']);
     }
     if (isset($metadata->primaryTable['inheritance-type'])) {
         $root->addAttribute('inheritance-type', $metadata->primaryTable['inheritance-type']);
     }
     if ($metadata->discriminatorColumn) {
         $discriminatorColumnXml = $root->addChild('discriminiator-column');
         $discriminatorColumnXml->addAttribute('name', $metadata->discriminatorColumn['name']);
         $discriminatorColumnXml->addAttribute('type', $metadata->discriminatorColumn['type']);
         $discriminatorColumnXml->addAttribute('length', $metadata->discriminatorColumn['length']);
     }
     if ($metadata->discriminatorMap) {
         $discriminatorMapXml = $root->addChild('discriminator-map');
         foreach ($metadata->discriminatorMap as $value => $className) {
             $discriminatorMappingXml = $discriminatorMapXml->addChild('discriminator-mapping');
             $discriminatorMappingXml->addAttribute('value', $value);
             $discriminatorMappingXml->addAttribute('class', $className);
         }
     }
     $root->addChild('change-tracking-policy', $this->_getChangeTrackingPolicyString($metadata->changeTrackingPolicy));
     if (isset($metadata->primaryTable['indexes'])) {
         $indexesXml = $root->addChild('indexes');
         foreach ($metadata->primaryTable['indexes'] as $name => $index) {
             $indexXml = $indexesXml->addChild('index');
             $indexXml->addAttribute('name', $name);
             $indexXml->addAttribute('columns', implode(',', $index['columns']));
         }
     }
     if (isset($metadata->primaryTable['uniqueConstraints'])) {
         $uniqueConstraintsXml = $root->addChild('unique-constraints');
         foreach ($metadata->primaryTable['uniqueConstraints'] as $unique) {
             $uniqueConstraintXml = $uniqueConstraintsXml->addChild('unique-constraint');
             $uniqueConstraintXml->addAttribute('name', $name);
             $uniqueConstraintXml->addAttribute('columns', implode(',', $unique['columns']));
         }
     }
     $fields = $metadata->fieldMappings;
     $id = array();
     foreach ($fields as $name => $field) {
         if (isset($field['id']) && $field['id']) {
             $id[$name] = $field;
             unset($fields[$name]);
         }
     }
     if ($idGeneratorType = $this->_getIdGeneratorTypeString($metadata->getIdGeneratorType())) {
         $id[$metadata->getSingleIdentifierFieldName()]['generator']['strategy'] = $idGeneratorType;
     }
     if ($fields) {
         foreach ($fields as $field) {
             $fieldXml = $root->addChild('field');
             $fieldXml->addAttribute('name', $field['fieldName']);
             $fieldXml->addAttribute('type', $field['type']);
             if (isset($field['columnName'])) {
                 $fieldXml->addAttribute('column', $field['columnName']);
             }
             if (isset($field['length'])) {
                 $fieldXml->addAttribute('length', $field['length']);
             }
             if (isset($field['precision'])) {
                 $fieldXml->addAttribute('precision', $field['precision']);
             }
             if (isset($field['scale'])) {
                 $fieldXml->addAttribute('scale', $field['scale']);
             }
             if (isset($field['unique']) && $field['unique']) {
                 $fieldXml->addAttribute('unique', $field['unique']);
             }
             if (isset($field['options'])) {
                 $optionsXml = $fieldXml->addChild('options');
                 foreach ($field['options'] as $key => $value) {
                     $optionsXml->addAttribute($key, $value);
                 }
             }
             if (isset($field['version'])) {
//.........这里部分代码省略.........
开发者ID:nvdnkpr,项目名称:symfony-demo,代码行数:101,代码来源:XmlExporter.php


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