-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathbootstrap-types.php
49 lines (37 loc) · 1.15 KB
/
bootstrap-types.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
namespace Atk4\Data\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types as DbalTypes;
final class Types
{
public const MONEY = 'atk4_money';
}
class MoneyType extends DbalTypes\Type
{
public function getName(): string
{
return Types::MONEY;
}
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
{
return DbalTypes\Type::getType(DbalTypes\Types::FLOAT)->getSQLDeclaration($fieldDeclaration, $platform);
}
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
{
if ($value === null || trim((string) $value) === '') {
return null;
}
return (string) round((float) $value, 4);
}
public function convertToPHPValue($value, AbstractPlatform $platform): ?float
{
$v = $this->convertToDatabaseValue($value, $platform);
return $v === null ? null : (float) $v;
}
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
}
}
DbalTypes\Type::addType(Types::MONEY, MoneyType::class);