Add Symfony TinyInt SQL type #5

Merged
preciel merged 1 commits from symfony-tiny-int into main 2026-03-05 13:01:19 +00:00
2 changed files with 47 additions and 0 deletions
Showing only changes of commit a705df675f - Show all commits

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;
}
}