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


PHP Type::getType方法代码示例

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


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

示例1: hydrateEntity

 public function hydrateEntity($entity, array $values)
 {
     $classMetadata = $this->em->getClassMetadata(get_class($entity));
     foreach ($values as $fieldName => $value) {
         if ($classMetadata->hasField($fieldName)) {
             $fieldMappping = $classMetadata->getFieldMapping($fieldName);
             if (null === $fieldMappping) {
                 throw new HydrationException($fieldName);
             }
             $type = Type::getType($classMetadata->fieldMappings[$fieldName]['type']);
             $value = $type->convertToPHPValue($value, $this->em->getConnection()->getDatabasePlatform());
             $classMetadata->setFieldValue($entity, $fieldName, $value);
         } elseif (isset($classMetadata->associationMappings[$fieldName])) {
             $fieldMapping = $classMetadata->associationMappings[$fieldName];
             if (ClassMetadataInfo::MANY_TO_MANY === $fieldMapping['type']) {
                 // expecting an array of ids in $value
                 if (1 === count($fieldMapping['relationToTargetKeyColumns'])) {
                     $columnName = array_pop($fieldMapping['relationToTargetKeyColumns']);
                     $otherSideMapping = $this->em->getClassMetadata($fieldMapping['targetEntity']);
                     $value = $this->em->getRepository($fieldMapping['targetEntity'])->findBy(array($otherSideMapping->fieldNames[$columnName] => $value));
                 }
                 $classMetadata->setFieldValue($entity, $fieldName, $value);
             } elseif (ClassMetadataInfo::MANY_TO_ONE === $fieldMapping['type']) {
                 // expecting an array of ids in $value
                 $value = $this->em->getRepository($fieldMapping['targetEntity'])->find($value);
                 $classMetadata->setFieldValue($entity, $fieldName, $value);
             }
         } else {
             throw new HydrationException($fieldName);
         }
     }
 }
开发者ID:gobjila,项目名称:BackBee,代码行数:32,代码来源:RestHydrator.php

示例2: getFieldByTagVaule

 private function getFieldByTagVaule($tag_value)
 {
     $value_and_params = $this->parseTagValueAndParameters($tag_value);
     $type = trim($value_and_params['value']);
     $params = $value_and_params['parameters'];
     return new \Hitar\FieldType($params, \Doctrine\DBAL\Types\Type::getType($type));
 }
开发者ID:kasonyang,项目名称:hitar,代码行数:7,代码来源:OrmAnnotation.php

示例3: table_should_contain_binary_uuid_column

 /**
  * @test
  */
 public function table_should_contain_binary_uuid_column()
 {
     $uuidColumn = $this->table->getColumn('uuid');
     $this->assertEquals(16, $uuidColumn->getLength());
     $this->assertEquals(Type::getType(Type::BINARY), $uuidColumn->getType());
     $this->assertTrue($uuidColumn->getFixed());
 }
开发者ID:2dotstwice,项目名称:broadway,代码行数:10,代码来源:BinaryDBALEventStoreTest.php

示例4: convertResultsInternal

 protected function convertResultsInternal($results, AbstractPlatform $platform, CaseSensor $sensor)
 {
     if (is_array($results)) {
         $results = current($results);
     }
     return Type::getType($this->type)->convertToPHPValue($results, $platform);
 }
开发者ID:ritalin,项目名称:omelet,代码行数:7,代码来源:BuiltinDomain.php

示例5: walkSelectStatement

 /**
  * Walks down a SelectStatement AST node, modifying it to retrieve DISTINCT ids
  * of the root Entity
  *
  * @param SelectStatement $AST
  * @return void
  */
 public function walkSelectStatement(SelectStatement $AST)
 {
     $parent = null;
     $parentName = null;
     $selectExpressions = array();
     foreach ($this->_getQueryComponents() as $dqlAlias => $qComp) {
         // preserve mixed data in query for ordering
         if (isset($qComp['resultVariable'])) {
             $selectExpressions[] = new SelectExpression($qComp['resultVariable'], $dqlAlias);
             continue;
         }
         if ($qComp['parent'] === null && $qComp['nestingLevel'] == 0) {
             $parent = $qComp;
             $parentName = $dqlAlias;
             continue;
         }
     }
     $identifier = $parent['metadata']->getSingleIdentifierFieldName();
     $this->_getQuery()->setHint(self::IDENTIFIER_TYPE, Type::getType($parent['metadata']->getTypeOfField($identifier)));
     $pathExpression = new PathExpression(PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $parentName, $identifier);
     $pathExpression->type = PathExpression::TYPE_STATE_FIELD;
     array_unshift($selectExpressions, new SelectExpression($pathExpression, '_dctrn_id'));
     $AST->selectClause->selectExpressions = $selectExpressions;
     if (isset($AST->orderByClause)) {
         foreach ($AST->orderByClause->orderByItems as $item) {
             if ($item->expression instanceof PathExpression) {
                 $pathExpression = new PathExpression(PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $item->expression->identificationVariable, $item->expression->field);
                 $pathExpression->type = PathExpression::TYPE_STATE_FIELD;
                 $AST->selectClause->selectExpressions[] = new SelectExpression($pathExpression, '_dctrn_ord' . $this->_aliasCounter++);
             }
         }
     }
     $AST->selectClause->isDistinct = true;
 }
开发者ID:davidbui2,项目名称:doctrine2,代码行数:41,代码来源:LimitSubqueryWalker.php

示例6: up

 /**
  * @inheritdoc
  */
 public function up(Schema $schema, QueryBag $queries)
 {
     $table = $schema->getTable('orocrm_sales_opportunity');
     $table->getColumn('probability')->setType(Type::getType('percent'));
     $table->getColumn('budget_amount')->setType(Type::getType('money'));
     $table->getColumn('close_revenue')->setType(Type::getType('money'));
 }
开发者ID:antrampa,项目名称:crm,代码行数:10,代码来源:OroCRMSalesBundle.php

示例7: up

 /**
  * {@inheritdoc}
  */
 public function up(Schema $schema, QueryBag $queries)
 {
     $table = $schema->getTable('orocrm_magento_cart');
     $table->getColumn('items_qty')->setType(Type::getType('float'));
     $table = $schema->getTable('orocrm_magento_order_items');
     $table->getColumn('qty')->setType(Type::getType('float'));
 }
开发者ID:antrampa,项目名称:crm,代码行数:10,代码来源:OroCRMMagentoBundle.php

示例8: createService

 /**
  * Create service
  *
  * @param  ServiceLocatorInterface $validators
  * @return mixed
  */
 public function createService(ServiceLocatorInterface $validators)
 {
     if (isset($this->options['enum'])) {
         $this->options['enum'] = DoctrineType::getType($this->options['enum']);
     }
     return new EnumValidator($this->options);
 }
开发者ID:bvoronov,项目名称:zb-utils,代码行数:13,代码来源:EnumValidatorFactory.php

示例9: testAlterTableSql

 public function testAlterTableSql()
 {
     $changes = array('name' => 'userlist', 'add' => array('quota' => array('type' => Type::getType('integer'))));
     $sql = $this->_platform->getAlterTableSql('mytable', $changes);
     $this->assertEquals('ALTER TABLE mytable ADD quota INT DEFAULT NULL', $sql[0]);
     $this->assertEquals('ALTER TABLE mytable RENAME TO userlist', $sql[1]);
 }
开发者ID:jackbravo,项目名称:doctrine,代码行数:7,代码来源:PostgreSqlPlatformTest.php

示例10: I_can_register_all_codes_at_once

 /**
  * @test
  */
 public function I_can_register_all_codes_at_once()
 {
     $typeName = $this->getExpectedTypeName();
     self::assertFalse(Type::hasType($typeName), "Type of name '{$typeName}' should not be registered yet");
     /** @var ScalarEnumType $typeClass */
     $typeClass = $this->getTypeClass();
     foreach ($this->getRelatedCodeClasses() as $relatedCodeClass) {
         self::assertFalse($typeClass::hasSubTypeEnum($relatedCodeClass), "Sub-type enum of a class '{$relatedCodeClass}' should not be registered yet");
     }
     $typeClass::registerSelf();
     self::assertTrue(Type::hasType($typeName), "Type of name '{$typeName}' is not registered");
     $testedType = Type::getType($typeName);
     $platform = $this->createPlatform();
     foreach ($this->getRelatedCodeClasses() as $relatedCodeClass) {
         self::assertTrue($typeClass::hasSubTypeEnum($relatedCodeClass), "Sub-type enum of a class '{$relatedCodeClass}' is not registered");
         foreach ($relatedCodeClass::getPossibleValues() as $possibleValue) {
             $asPhp = $testedType->convertToPHPValue($relatedCodeClass . '::' . $possibleValue, $platform);
             self::assertInstanceOf($relatedCodeClass, $asPhp);
             /** @var AbstractCode $asPhp */
             self::assertSame($possibleValue, $asPhp->getValue());
         }
     }
     $typeClass::registerSelf();
     // test if can call registering repeatedly
 }
开发者ID:jaroslavtyc,项目名称:drd-plus-codes,代码行数:28,代码来源:AbstractCodeTypeTest.php

示例11: walkSelectStatement

 /**
  * Walks down a SelectStatement AST node, modifying it to retrieve DISTINCT ids
  * of the root Entity.
  *
  * @param SelectStatement $AST
  *
  * @return void
  *
  * @throws \RuntimeException
  */
 public function walkSelectStatement(SelectStatement $AST)
 {
     $queryComponents = $this->_getQueryComponents();
     // Get the root entity and alias from the AST fromClause
     $from = $AST->fromClause->identificationVariableDeclarations;
     $fromRoot = reset($from);
     $rootAlias = $fromRoot->rangeVariableDeclaration->aliasIdentificationVariable;
     $rootClass = $queryComponents[$rootAlias]['metadata'];
     $selectExpressions = array();
     foreach ($queryComponents as $dqlAlias => $qComp) {
         // Preserve mixed data in query for ordering.
         if (isset($qComp['resultVariable'])) {
             $selectExpressions[] = new SelectExpression($qComp['resultVariable'], $dqlAlias);
             continue;
         }
     }
     $identifier = $rootClass->getSingleIdentifierFieldName();
     if (isset($rootClass->associationMappings[$identifier])) {
         throw new \RuntimeException("Paginating an entity with foreign key as identifier only works when using the Output Walkers. Call Paginator#setUseOutputWalkers(true) before iterating the paginator.");
     }
     $this->_getQuery()->setHint(self::IDENTIFIER_TYPE, Type::getType($rootClass->getTypeOfField($identifier)));
     $pathExpression = new PathExpression(PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $rootAlias, $identifier);
     $pathExpression->type = PathExpression::TYPE_STATE_FIELD;
     array_unshift($selectExpressions, new SelectExpression($pathExpression, '_dctrn_id'));
     $AST->selectClause->selectExpressions = $selectExpressions;
     if (isset($AST->orderByClause)) {
         foreach ($AST->orderByClause->orderByItems as $item) {
             if (!$item->expression instanceof PathExpression) {
                 continue;
             }
             $AST->selectClause->selectExpressions[] = new SelectExpression($this->createSelectExpressionItem($item->expression), '_dctrn_ord' . $this->_aliasCounter++);
         }
     }
     $AST->selectClause->isDistinct = true;
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:45,代码来源:LimitSubqueryWalker.php

示例12: convertValue

 /**
  * {@inheritdoc}
  */
 public function convertValue($value, array $options, ConversionHints $hints)
 {
     if (2 === $hints->conversionStrategy || 3 === $hints->conversionStrategy) {
         return DBALType::getType('date')->convertToDatabaseValue($value, $hints->connection->getDatabasePlatform());
     }
     return (int) $value;
 }
开发者ID:rollerworks,项目名称:search-doctrine-dbal,代码行数:10,代码来源:AgeDateConversion.php

示例13: testCreateTemporaryTableNotAutoCommitTransaction

 /**
  * @group DDC-1337
  * @return void
  */
 public function testCreateTemporaryTableNotAutoCommitTransaction()
 {
     if ($this->_conn->getDatabasePlatform()->getName() == 'sqlanywhere' || $this->_conn->getDatabasePlatform()->getName() == 'oracle') {
         $this->markTestSkipped("Test does not work on Oracle and SQL Anywhere.");
     }
     $platform = $this->_conn->getDatabasePlatform();
     $columnDefinitions = array("id" => array("type" => Type::getType("integer"), "notnull" => true));
     $tempTable = $platform->getTemporaryTableName("my_temporary");
     $createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' (' . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')';
     $table = new Table("nontemporary");
     $table->addColumn("id", "integer");
     $table->setPrimaryKey(array('id'));
     foreach ($platform->getCreateTableSQL($table) as $sql) {
         $this->_conn->executeQuery($sql);
     }
     $this->_conn->beginTransaction();
     $this->_conn->insert("nontemporary", array("id" => 1));
     $this->_conn->exec($createTempTableSQL);
     $this->_conn->insert("nontemporary", array("id" => 2));
     $this->_conn->rollback();
     try {
         $this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable));
     } catch (\Exception $e) {
     }
     $rows = $this->_conn->fetchAll('SELECT * FROM nontemporary');
     $this->assertEquals(array(), $rows, "In an event of an error this result has one row, because of an implicit commit.");
 }
开发者ID:selimcr,项目名称:servigases,代码行数:31,代码来源:TemporaryTableTest.php

示例14: test_importSchemaArray

 public function test_importSchemaArray()
 {
     $instance = new Xoops\Core\Database\Schema\ExportVisitor();
     $table = new Doctrine\DBAL\Schema\Table('system_group');
     $type = Type::getType(Type::INTEGER);
     $col_name = 'groupid';
     $column = new Doctrine\DBAL\Schema\Column($col_name, $type);
     $instance->acceptColumn($table, $column);
     $columns = array('groupid');
     $fk_table = 'system_permission';
     $fk_name = 'fk_name';
     $fk_options = array('o' => 'o1');
     $fk_columns = array('system_permission');
     $fk_constraint = new Doctrine\DBAL\Schema\ForeignKeyConstraint($columns, $fk_table, $fk_columns, $fk_name, $fk_options);
     $instance->acceptForeignKey($table, $fk_constraint);
     $name = 'index_name';
     $columns = array('name', 'description');
     $unique = true;
     $primary = true;
     $index = new Doctrine\DBAL\Schema\Index($name, $columns, $unique, $primary);
     $instance->acceptIndex($table, $index);
     $name = 'sequence_name';
     $alloc_size = 10;
     $initial_value = 11;
     $sequence = new Doctrine\DBAL\Schema\Sequence($name, $alloc_size, $initial_value);
     $instance->acceptSequence($sequence);
     $schema = $instance->getSchemaArray();
     $import = new $this->myClass();
     $value = $import->importSchemaArray($schema);
     $this->assertInstanceOf('Doctrine\\DBAL\\Schema\\Schema', $value);
 }
开发者ID:ming-hai,项目名称:XoopsCore,代码行数:31,代码来源:ImportSchemaTest.php

示例15: changePrimaryKeyType

 /**
  * @param Schema   $schema
  * @param QueryBag $queries
  * @param string   $tableName
  * @param string   $columnName
  * @param string   $type
  *
  * @throws \Exception
  */
 public function changePrimaryKeyType(Schema $schema, QueryBag $queries, $tableName, $columnName, $type)
 {
     $targetColumn = $schema->getTable($tableName)->getColumn($columnName);
     $type = Type::getType($type);
     if ($targetColumn->getType() === $type) {
         return;
     }
     /** @var ForeignKeyConstraint[] $foreignKeys */
     $foreignKeys = [];
     foreach ($schema->getTables() as $table) {
         /** @var ForeignKeyConstraint[] $tableForeignKeys */
         $tableForeignKeys = array_filter($table->getForeignKeys(), function (ForeignKeyConstraint $tableForeignKey) use($tableName, $columnName) {
             if ($tableForeignKey->getForeignTableName() !== $tableName) {
                 return false;
             }
             return $tableForeignKey->getForeignColumns() === [$columnName];
         });
         foreach ($tableForeignKeys as $tableForeignKey) {
             $foreignKeys[$tableForeignKey->getName()] = $tableForeignKey;
             $foreignKeyTableName = $tableForeignKey->getLocalTable()->getName();
             $foreignKeyColumnNames = $tableForeignKey->getLocalColumns();
             $queries->addPreQuery($this->platform->getDropForeignKeySQL($tableForeignKey, $foreignKeyTableName));
             $column = $schema->getTable($foreignKeyTableName)->getColumn(reset($foreignKeyColumnNames));
             if ($column instanceof ExtendColumn) {
                 $column->disableExtendOptions()->setType($type)->enableExtendOptions();
             } else {
                 $column->setType($type);
             }
         }
     }
     $targetColumn->setType($type);
     foreach ($foreignKeys as $foreignKey) {
         $queries->addPostQuery($this->platform->getCreateForeignKeySQL($foreignKey, $foreignKey->getLocalTable()));
     }
 }
开发者ID:Maksold,项目名称:platform,代码行数:44,代码来源:ChangeTypeExtension.php


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