Add Symfony TinyInt SQL type

This commit is contained in:
2026-03-05 14:01:05 +01:00
parent d5c38ce578
commit a705df675f
2 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,5 @@
doctrine:
dbal:
# add TinyIntType
types:
tinyint: App\Doctrine\DBAL\Types\TinyintType

View File

@ -0,0 +1,42 @@
<?php
namespace App\Doctrine\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
class TinyintType extends Type {
private const string TINYINT = 'tinyint';
public function getName(): string {
return self::TINYINT;
}
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string {
$declaration = "TINYINT(1)";
if(!empty($column['unsigned'])) {
$declaration .= " UNSIGNED";
}
if(!empty($column['autoincrement'])) {
$declaration .= ' AUTO_INCREMENT';
}
$declaration .= " COMMENT '(DC2Type:tinyint)'";
return $declaration;
}
public function convertToPHPValue($value, AbstractPlatform $platform): ?int {
return $value === null
? null
: (int)$value;
}
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?int {
return $value === null
? null
: (int)$value;
}
}