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\Validator\Constraints\BigDecimal; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
use Brick\Math\BigDecimal; |
25
|
|
|
use Symfony\Component\Validator\Constraints\AbstractComparisonValidator; |
26
|
|
|
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Validates values are greater than or equal to the previous (>=). |
30
|
|
|
* |
31
|
|
|
* @author Daniel Holmes <[email protected]> |
32
|
|
|
* @author Bernhard Schussek <[email protected]> |
33
|
|
|
*/ |
34
|
|
|
class BigDecimalGreaterThenOrEqualValidator extends AbstractComparisonValidator |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
protected function compareValues($value1, $value2) |
40
|
|
|
{ |
41
|
|
|
if ($value1 instanceof BigDecimal) { |
42
|
|
|
$value1 = (string) $value1; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if ($value2 instanceof BigDecimal) { |
46
|
|
|
$value2 = (string) $value2; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return null === $value2 || $value1 >= $value2; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
protected function getErrorCode() |
56
|
|
|
{ |
57
|
|
|
return GreaterThanOrEqual::TOO_LOW_ERROR; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|