| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wikimedia\Rdbms; |
| 4 |
|
| 5 |
use Doctrine\DBAL\Platforms\AbstractPlatform; |
| 6 |
use Doctrine\DBAL\Types\PhpIntegerMappingType; |
| 7 |
use Doctrine\DBAL\Types\Type; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class TinyIntType extends Type implements PhpIntegerMappingType { |
| 13 |
public const TINYINT = 'mwtinyint'; |
| 14 |
|
| 15 |
public function getSQLDeclaration( array $fieldDeclaration, AbstractPlatform $platform ) { |
| 16 |
if ( $platform->getName() == 'mysql' ) { |
| 17 |
if ( !empty( $fieldDeclaration['length'] ) && is_numeric( $fieldDeclaration['length'] ) ) { |
| 18 |
$length = $fieldDeclaration['length']; |
| 19 |
return "TINYINT($length)" . $this->getCommonIntegerTypeDeclarationForMySQL( $fieldDeclaration ); |
| 20 |
} |
| 21 |
return 'TINYINT' . $this->getCommonIntegerTypeDeclarationForMySQL( $fieldDeclaration ); |
| 22 |
} |
| 23 |
|
| 24 |
return $platform->getSmallIntTypeDeclarationSQL( $fieldDeclaration ); |
| 25 |
} |
| 26 |
|
| 27 |
protected function getCommonIntegerTypeDeclarationForMySQL( array $columnDef ) { |
| 28 |
$autoinc = ''; |
| 29 |
if ( !empty( $columnDef['autoincrement'] ) ) { |
| 30 |
$autoinc = ' AUTO_INCREMENT'; |
| 31 |
} |
| 32 |
|
| 33 |
return !empty( $columnDef['unsigned'] ) ? ' UNSIGNED' . $autoinc : $autoinc; |
| 34 |
} |
| 35 |
|
| 36 |
public function getName() { |
| 37 |
return self::TINYINT; |
| 38 |
} |
| 39 |
} |