本文整理汇总了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);
}
}
}
示例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));
}
示例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());
}
示例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);
}
示例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;
}
示例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'));
}
示例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'));
}
示例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);
}
示例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]);
}
示例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
}
示例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;
}
示例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;
}
示例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.");
}
示例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);
}
示例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()));
}
}