Skip to content

Commit 9af1743

Browse files
authored
Merge pull request doctrine#2603 from deeky666/DBAL-2594
[DBAL-2594] Mark commented types implicitly
2 parents 475097d + fa75b7b commit 9af1743

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

lib/Doctrine/DBAL/Platforms/AbstractPlatform.php

+6
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,12 @@ public function registerDoctrineTypeMapping($dbType, $doctrineType)
400400

401401
$dbType = strtolower($dbType);
402402
$this->doctrineTypeMapping[$dbType] = $doctrineType;
403+
404+
$doctrineType = Type::getType($doctrineType);
405+
406+
if ($doctrineType->requiresSQLCommentHint($this)) {
407+
$this->markDoctrineTypeCommented($doctrineType);
408+
}
403409
}
404410

405411
/**

tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php

+16
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Doctrine\DBAL\Schema\Table;
1414
use Doctrine\DBAL\Schema\TableDiff;
1515
use Doctrine\DBAL\Types\Type;
16+
use Doctrine\Tests\Types\CommentedType;
1617

1718
abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
1819
{
@@ -107,6 +108,21 @@ public function testRegisterUnknownDoctrineMappingType()
107108
$this->_platform->registerDoctrineTypeMapping('foo', 'bar');
108109
}
109110

111+
/**
112+
* @group DBAL-2594
113+
*/
114+
public function testRegistersCommentedDoctrineMappingTypeImplicitly()
115+
{
116+
if (!Type::hasType('my_commented')) {
117+
Type::addType('my_commented', CommentedType::class);
118+
}
119+
120+
$type = Type::getType('my_commented');
121+
$this->_platform->registerDoctrineTypeMapping('foo', 'my_commented');
122+
123+
$this->assertTrue($this->_platform->isCommentedDoctrineType($type));
124+
}
125+
110126
/**
111127
* @group DBAL-939
112128
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Doctrine\Tests\Types;
4+
5+
use Doctrine\DBAL\Platforms\AbstractPlatform;
6+
use Doctrine\DBAL\Types\Type;
7+
8+
class CommentedType extends Type
9+
{
10+
public function getName()
11+
{
12+
return 'my_commented';
13+
}
14+
15+
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
16+
{
17+
return strtoupper($this->getName());
18+
}
19+
20+
public function requiresSQLCommentHint(AbstractPlatform $platform)
21+
{
22+
return true;
23+
}
24+
}

0 commit comments

Comments
 (0)