1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics) |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as published |
9
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
18
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace App\Helpers; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
use Brick\Math\BigDecimal; |
25
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
26
|
|
|
use Doctrine\DBAL\Types\Type; |
27
|
|
|
|
28
|
|
|
class BigDecimalType extends Type |
29
|
|
|
{ |
30
|
|
|
public const BIG_DECIMAL = 'big_decimal'; |
31
|
|
|
|
32
|
|
|
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) |
33
|
|
|
{ |
34
|
|
|
return $platform->getDecimalTypeDeclarationSQL($fieldDeclaration); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $value |
39
|
|
|
* @param AbstractPlatform $platform |
40
|
|
|
* @return BigDecimal|\Brick\Math\BigNumber|mixed |
41
|
|
|
*/ |
42
|
|
|
public function convertToPHPValue($value, AbstractPlatform $platform) |
43
|
|
|
{ |
44
|
|
|
if ($value === null) { |
|
|
|
|
45
|
|
|
return null; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return BigDecimal::of($value); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param BigDecimal $value |
53
|
|
|
* @param AbstractPlatform $platform |
54
|
|
|
* @return mixed |
55
|
|
|
*/ |
56
|
|
|
public function convertToDatabaseValue($value, AbstractPlatform $platform) |
57
|
|
|
{ |
58
|
|
|
if ($value === null) { |
59
|
|
|
return null; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return (string) $value; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getName() |
66
|
|
|
{ |
67
|
|
|
return self::BIG_DECIMAL; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function requiresSQLCommentHint(AbstractPlatform $platform) |
71
|
|
|
{ |
72
|
|
|
return true; |
73
|
|
|
} |
74
|
|
|
} |