當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。