collection-crud/src/Types/MoneyType.php

32 lines
648 B
PHP
Raw Normal View History

2022-02-18 11:34:25 -05:00
<?php declare(strict_types=1);
namespace App\Types;
use App\ValueObject\Money;
2022-03-03 10:53:48 -05:00
use Doctrine\DBAL\Platforms\AbstractPlatform;
2022-03-03 10:53:48 -05:00
use Doctrine\DBAL\Types\Type;
2019-07-23 10:31:06 -04:00
2022-03-03 10:53:48 -05:00
class MoneyType extends Type
{
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return 'MONEY';
}
public function convertToPHPValue($value, AbstractPlatform $platform): float
{
return (float) (string) new Money($value);
}
public function getName(): string
{
return 'money';
}
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
2022-03-03 11:15:12 -05:00
return TRUE;
2022-03-03 10:53:48 -05:00
}
2018-02-14 15:08:03 -05:00
}