Skip to content

Instantly share code, notes, and snippets.

@guilhermeblanco
Created April 14, 2015 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilhermeblanco/2456d17864c55bdf016e to your computer and use it in GitHub Desktop.
Save guilhermeblanco/2456d17864c55bdf016e to your computer and use it in GitHub Desktop.
namespace Doctrine\DBAL\Type;
use Doctrine\DBAL\Generator\SQL;
use Doctrine\DBAL\Platform\Platform;
class CustomIntegerType extends AbstractType implements Type
{
public function generateType(Platform $platform)
{
$internalType = ($this->options['length'] > 10) ? 'BIGINT' : 'INT';
$type = new SQL\Type($internalType);
$type->setName('custom_integer');
$type->setOptions([
'nullable' => false,
'default' => 0,
]);
return $type;
}
function convertDatabaseToValue($value)
{
return (int) $value;
}
function convertValueToDatabase($value)
{
return $value;
}
}
namespace Doctrine\DBAL\Type;
use Doctrine\DBAL\Platform\Platform;
class IntegerType extends AbstractType implements Type
{
public function generateType(Platform $platform)
{
return $this->platform->createIntegerType($this->options);
}
function convertDatabaseToValue($value)
{
return (int) $value;
}
function convertValueToDatabase($value)
{
return $value;
}
}
namespace Doctrine\DBAL\Type;
use Doctrine\DBAL\Platform\Platform;
interface Type
{
function setOptions(Options $options);
function generateType(Platform $platform);
function convertDatabaseToValue($value);
function convertValueToDatabase($value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment