Created
June 10, 2014 17:53
-
-
Save nkt/0f24505e4cdf78c01a10 to your computer and use it in GitHub Desktop.
Doctrine2 enum type implementation.
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
<?php | |
namespace Nkt\Doctrine\Type; | |
use Doctrine\DBAL\Platforms\AbstractPlatform; | |
use Doctrine\DBAL\Types\Type; | |
/** | |
* Enum type | |
* @author Gusakov Nikita <[email protected]> | |
* @license MIT | |
*/ | |
class EnumType extends Type | |
{ | |
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) | |
{ | |
if (!isset($fieldDeclaration['variants']) || !is_array($fieldDeclaration['variants'])) { | |
throw new \InvalidArgumentException('You have to define array of variants'); | |
} | |
$variants = array_map(function ($variant) use ($platform) { | |
return "'$variant'"; | |
}, $fieldDeclaration['variants']); | |
return 'ENUM(' . join(', ', $variants) . ')'; | |
} | |
public function requiresSQLCommentHint(AbstractPlatform $platform) | |
{ | |
return true; | |
} | |
public function getName() | |
{ | |
return 'enum'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add next code in your
app/config/config.yml