1
|
|
|
<?php |
2
|
|
|
namespace AlgoWeb\xsdTypes; |
3
|
|
|
|
4
|
|
|
use AlgoWeb\xsdTypes\Facets\DigitsTrait; |
5
|
|
|
use AlgoWeb\xsdTypes\Facets\MinMaxTrait; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* The type xsd:decimal represents a decimal number of arbitrary precision. Schema processors vary in the number of |
9
|
|
|
* significant digits they support, but a conforming processor must support a minimum of 18 significant digits. |
10
|
|
|
* The format of xsd:decimal is a sequence of digits optionally preceded by a sign ("+" or "-") and optionally |
11
|
|
|
* containing a period. The value may start or end with a period. If the fractional part is 0, then the period and |
12
|
|
|
* trailing zeros may be omitted. Leading and trailing zeros are permitted, but they are not considered significant. |
13
|
|
|
* That is, the decimal values 3.0 and 3.0000 are considered equal. |
14
|
|
|
* @package AlgoWeb\xsdTypes |
15
|
|
|
*/ |
16
|
|
|
class xsDecimal extends xsAnySimpleType |
17
|
|
|
{ |
18
|
|
|
use DigitsTrait, MinMaxTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Construct. |
22
|
|
|
* |
23
|
|
|
* @param float $value |
24
|
|
|
*/ |
25
|
|
|
public function __construct($value) |
26
|
|
|
{ |
27
|
|
|
parent::__construct($value); |
28
|
|
|
$this->setWhiteSpaceFacet('collapse'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
protected function fixValue() |
32
|
|
|
{ |
33
|
|
|
parent::fixValue(); |
34
|
|
|
$this->value = $this->fixFractionDigits($this->value); |
35
|
|
|
$this->value = filter_var($this->value, FILTER_VALIDATE_FLOAT, ['options' => [ |
36
|
|
|
'default' => '', // value to return if the filter fails |
37
|
|
|
'decimal' => '.' |
38
|
|
|
]]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function isOK() |
42
|
|
|
{ |
43
|
|
|
$this->checkTotalDigits($this->value); |
44
|
|
|
$this->checkFractionDigits($this->value); |
45
|
|
|
$this->CheckMinMax($this->value); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|