Add Symfony TinyInt SQL type
This commit is contained in:
5
php/symfony/config/packages/doctrine.yaml
Normal file
5
php/symfony/config/packages/doctrine.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
doctrine:
|
||||
dbal:
|
||||
# add TinyIntType
|
||||
types:
|
||||
tinyint: App\Doctrine\DBAL\Types\TinyintType
|
||||
42
php/symfony/src/Doctrine/DBAL/Types/TinyintType.php
Normal file
42
php/symfony/src/Doctrine/DBAL/Types/TinyintType.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user