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


PHP ClassMetadata::getTypeOfColumn方法代码示例

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


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

示例1: createField

 /**
  * @param FormBuilder $form
  * @param ClassMetadata $metaData
  * @param string $fieldName
  * @throws DoctrineTypeNotSupportedException
  */
 public function createField($form, $metaData, $fieldName)
 {
     $type = $metaData->getTypeOfColumn($fieldName);
     switch ($type) {
         case 'string':
             $formField = $this->createFieldString();
             break;
         case 'text':
             $formField = $this->createFieldText();
             break;
         case 'bigint':
         case 'integer':
             $formField = $this->createFieldInteger($metaData, $fieldName);
             break;
         case 'boolean':
             $formField = $this->createFieldBoolean();
             break;
         case 'datetime':
             $formField = $this->createFieldDateTime();
             break;
         case 'decimal':
             $formField = $this->createFieldDecimal();
             break;
         default:
             throw new DoctrineTypeNotSupportedException($type);
     }
     $formField->setLabel($this->translateName($fieldName));
     $formField->setName($fieldName);
     if (!$metaData->isNullable($fieldName)) {
         $formField->setRequired(true);
     }
     $form->addField($formField);
 }
开发者ID:itephp,项目名称:doctrine-bridge,代码行数:39,代码来源:DoctrineDesigner.php

示例2: update

 /**
  * @param object $entity
  * @return int
  * @throws \Doctrine\ORM\Mapping\MappingException
  */
 public function update($entity)
 {
     $identifiers = [];
     $types = ['id' => \PDO::PARAM_INT];
     foreach ($this->metaData->getIdentifierColumnNames() as $columnName) {
         $fieldName = $this->metaData->getFieldForColumn($columnName);
         $value = $this->metaData->getFieldValue($entity, $fieldName);
         $identifiers[$columnName] = $value;
     }
     $updateSet = [];
     foreach ($this->metaData->getColumnNames() as $columnName) {
         if (isset($identifiers[$columnName])) {
             continue;
         }
         $fieldName = $this->metaData->getFieldForColumn($columnName);
         $typeName = $this->metaData->getTypeOfColumn($fieldName);
         $type = \Doctrine\DBAL\Types\Type::getType($typeName);
         $value = $type->convertToDatabaseValue($entity->{$fieldName}, $this->em->getConnection()->getDatabasePlatform());
         $types[$columnName] = $type->getBindingType();
         $updateSet[$columnName] = $value;
     }
     return $this->em->getConnection()->update($this->metaData->getTableName(), $updateSet, $identifiers, $types);
 }
开发者ID:lynx,项目名称:lynx,代码行数:28,代码来源:DBAL.php

示例3: _gatherRelationJoinColumns

 /**
  * Gather columns and fk constraints that are required for one part of relationship.
  *
  * @param array $joinColumns
  * @param \Doctrine\DBAL\Schema\Table $theJoinTable
  * @param ClassMetadata $class
  * @param \Doctrine\ORM\Mapping\AssociationMapping $mapping
  * @param array $primaryKeyColumns
  * @param array $uniqueConstraints
  */
 private function _gatherRelationJoinColumns($joinColumns, $theJoinTable, $class, $mapping, &$primaryKeyColumns, &$uniqueConstraints)
 {
     $localColumns = array();
     $foreignColumns = array();
     $fkOptions = array();
     foreach ($joinColumns as $joinColumn) {
         $columnName = $joinColumn['name'];
         $referencedFieldName = $class->getFieldName($joinColumn['referencedColumnName']);
         if (!$class->hasField($referencedFieldName)) {
             throw new \Doctrine\ORM\ORMException("Column name `" . $joinColumn['referencedColumnName'] . "` referenced for relation from " . $mapping['sourceEntity'] . " towards " . $mapping['targetEntity'] . " does not exist.");
         }
         $primaryKeyColumns[] = $columnName;
         $localColumns[] = $columnName;
         $foreignColumns[] = $joinColumn['referencedColumnName'];
         if (!$theJoinTable->hasColumn($joinColumn['name'])) {
             // Only add the column to the table if it does not exist already.
             // It might exist already if the foreign key is mapped into a regular
             // property as well.
             $fieldMapping = $class->getFieldMapping($referencedFieldName);
             $columnDef = null;
             if (isset($joinColumn['columnDefinition'])) {
                 $columnDef = $joinColumn['columnDefinition'];
             } else {
                 if (isset($fieldMapping['columnDefinition'])) {
                     $columnDef = $fieldMapping['columnDefinition'];
                 }
             }
             $columnOptions = array('notnull' => false, 'columnDefinition' => $columnDef);
             if (isset($joinColumn['nullable'])) {
                 $columnOptions['notnull'] = !$joinColumn['nullable'];
             }
             if ($fieldMapping['type'] == "string") {
                 $columnOptions['length'] = $fieldMapping['length'];
             } else {
                 if ($fieldMapping['type'] == "decimal") {
                     $columnOptions['scale'] = $fieldMapping['scale'];
                     $columnOptions['precision'] = $fieldMapping['precision'];
                 }
             }
             $theJoinTable->addColumn($columnName, $class->getTypeOfColumn($joinColumn['referencedColumnName']), $columnOptions);
         }
         if (isset($joinColumn['unique']) && $joinColumn['unique'] == true) {
             $uniqueConstraints[] = array('columns' => array($columnName));
         }
         if (isset($joinColumn['onUpdate'])) {
             $fkOptions['onUpdate'] = $joinColumn['onUpdate'];
         }
         if (isset($joinColumn['onDelete'])) {
             $fkOptions['onDelete'] = $joinColumn['onDelete'];
         }
     }
     $theJoinTable->addUnnamedForeignKeyConstraint($class->getTableName(), $localColumns, $foreignColumns, $fkOptions);
 }
开发者ID:jackbravo,项目名称:symfony-sandbox,代码行数:63,代码来源:SchemaTool.php


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