-
-
Save cezarpopa/f244c0a8d30e40f81d2f47d4016d2378 to your computer and use it in GitHub Desktop.
Custom Doctrine DBAL type 'tinyint' for Symfony
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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