Skip to content

Instantly share code, notes, and snippets.

@cezarpopa
Forked from elenakondrateva/Tinyint.php
Created December 11, 2021 17:19
Show Gist options
  • Save cezarpopa/f244c0a8d30e40f81d2f47d4016d2378 to your computer and use it in GitHub Desktop.
Save cezarpopa/f244c0a8d30e40f81d2f47d4016d2378 to your computer and use it in GitHub Desktop.
Custom Doctrine DBAL type 'tinyint' for Symfony
<?php
namespace AppBundle\Doctrine\DBAL\Types;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class Tinyint extends Type
{
const TINYINT = 'tinyint';
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
$fieldDeclaration = array_merge([
'length' => 1,
], $fieldDeclaration);
return sprintf("TINYINT(%d)",
$fieldDeclaration['length']
);
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
return (int) $value;
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
return (int) $value;
}
public function getName()
{
return self::TINYINT;
}
public function getBindingType()
{
return \PDO::PARAM_INT;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment