collection-crud/src/Types/MoneyType.php

31 lines
588 B
PHP
Raw Permalink 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
2023-07-21 10:35:15 -04:00
class MoneyType extends Type {
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return 'MONEY';
}
2022-03-03 10:53:48 -05:00
2023-07-21 10:35:15 -04:00
public function convertToPHPValue($value, AbstractPlatform $platform): float
{
return (float) (string) new Money($value);
}
2022-03-03 10:53:48 -05:00
2023-07-21 10:35:15 -04:00
public function getName(): string
{
return 'money';
}
2022-03-03 10:53:48 -05:00
2023-07-21 10:35:15 -04:00
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return TRUE;
}
2018-02-14 15:08:03 -05:00
}