Created
April 14, 2015 20:37
-
-
Save guilhermeblanco/2456d17864c55bdf016e to your computer and use it in GitHub Desktop.
This file contains 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
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; | |
} | |
} |
This file contains 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
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; | |
} | |
} |
This file contains 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
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