-
-
Save andrewprofile/18a14a9046b2b7612140a3a96c6a7afc 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 | |
| declare(strict_types=1); | |
| namespace User\Infrastructure\Doctrine\DBAL\Types; | |
| use User\Domain\Model\UserId; | |
| use Doctrine\DBAL\Platforms\AbstractPlatform; | |
| use Doctrine\DBAL\Types\Type; | |
| /** | |
| * Class UserIdType | |
| * @package User\Infrastructure\Doctrine\DBAL\Types | |
| */ | |
| class UserIdType extends Type | |
| { | |
| const NAME = 'userId'; | |
| /** | |
| * @return string | |
| */ | |
| public function getName() | |
| { | |
| return self::NAME; | |
| } | |
| /** | |
| * @param mixed $value | |
| * @param AbstractPlatform $platform | |
| * @return null|string | |
| */ | |
| public function convertToDatabaseValue($value, AbstractPlatform $platform) | |
| { | |
| if ($value instanceof UserId) { | |
| return $value->getValue(); | |
| } | |
| if ($value) { | |
| return (string)$value; | |
| } | |
| return null; | |
| } | |
| /** | |
| * @param mixed $value | |
| * @param AbstractPlatform $platform | |
| * @return mixed|UserId | |
| * @throws \Assert\AssertionFailedException | |
| */ | |
| public function convertToPHPValue($value, AbstractPlatform $platform) | |
| { | |
| if ($value === null || $value instanceof UserId) { | |
| return $value; | |
| } | |
| return new UserId($value); | |
| } | |
| /** | |
| * @param array $fieldDeclaration | |
| * @param AbstractPlatform $platform | |
| * @return string | |
| */ | |
| public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) | |
| { | |
| return $platform->getGuidTypeDeclarationSQL($fieldDeclaration); | |
| } | |
| /** | |
| * @param AbstractPlatform $platform | |
| * @return bool | |
| */ | |
| public function requiresSQLCommentHint(AbstractPlatform $platform) | |
| { | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment