-
-
Save peshi/8761720 to your computer and use it in GitHub Desktop.
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 Acme\DemoBundle\DBAL\Type; | |
use Doctrine\DBAL\Types\Type; | |
use Doctrine\DBAL\Platforms\AbstractPlatform; | |
/** | |
* Class SemicolonArrayType represents an array of values that will be persisted as a string of semicolon-separated strings. | |
* | |
* @see http://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_find-in-set | |
* @package Acme\DemoBundle\Type | |
*/ | |
class SemicolonArrayType extends Type | |
{ | |
/** | |
* Name of this type | |
*/ | |
const TYPE = 'semicolon_array'; | |
const DELIMITER = ';'; | |
/** | |
* @inheritDoc | |
*/ | |
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform) | |
{ | |
return $platform->getClobTypeDeclarationSQL($fieldDeclaration); | |
} | |
/** | |
* @inheritDoc | |
*/ | |
public function convertToPHPValue($value, AbstractPlatform $platform) | |
{ | |
if ($value === null) { | |
return null; | |
} | |
return explode(self::DELIMITER, $value); | |
} | |
/** | |
* @inheritDoc | |
*/ | |
public function convertToDatabaseValue($value, AbstractPlatform $platform) | |
{ | |
if (!is_array($value)) { | |
return $value; | |
} | |
return implode(self::DELIMITER, $value); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function requiresSQLCommentHint(AbstractPlatform $platform) | |
{ | |
return true; | |
} | |
/** | |
* @inheritDoc | |
*/ | |
public function getName() | |
{ | |
return self::TYPE; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Symfony 2.4.x