1 | <?php |
||
24 | class Unit |
||
25 | { |
||
26 | /** |
||
27 | * @var float The value. |
||
28 | * |
||
29 | * @internal |
||
30 | */ |
||
31 | private $value; |
||
32 | |||
33 | /** |
||
34 | * @var string The value's unit. |
||
35 | * |
||
36 | * @internal |
||
37 | */ |
||
38 | private $unit; |
||
39 | |||
40 | /** |
||
41 | * @var string The value's description. |
||
42 | * |
||
43 | * @internal |
||
44 | */ |
||
45 | private $description; |
||
46 | |||
47 | /** |
||
48 | * @var float|null The value's measurement precision. Can be null if unknown. |
||
49 | */ |
||
50 | private $precision; |
||
51 | |||
52 | /** |
||
53 | * Create a new unit object. |
||
54 | * |
||
55 | 16 | * @param float $value The value. |
|
56 | * @param string $unit The unit of the value. |
||
57 | 16 | * @param string $description The description of the value. |
|
58 | 16 | * @param float|null $precision The precision of the value, or null if unknown. |
|
59 | 16 | * |
|
60 | 16 | * @internal |
|
61 | */ |
||
62 | public function __construct($value = 0.0, $unit = "", $description = "", $precision = null) |
||
69 | 1 | ||
70 | /** |
||
71 | 1 | * Get the value as formatted string with unit. |
|
72 | * |
||
73 | * @return string The value as formatted string with unit. |
||
74 | * |
||
75 | * The unit is not included if it is empty. |
||
76 | */ |
||
77 | public function __toString() |
||
81 | 8 | ||
82 | /** |
||
83 | * Get the value's unit. |
||
84 | * |
||
85 | 8 | * @return string The value's unit. |
|
86 | 2 | * |
|
87 | 6 | * This also converts 'celsius' to '°C' and 'fahrenheit' to '°F'. |
|
88 | 1 | */ |
|
89 | public function getUnit() |
||
101 | 9 | ||
102 | /** |
||
103 | * Get the value. |
||
104 | * |
||
105 | * @return float The value. |
||
106 | */ |
||
107 | public function getValue() |
||
111 | 2 | ||
112 | /** |
||
113 | * Get the value's description. |
||
114 | * |
||
115 | * @return string The value's description. |
||
116 | */ |
||
117 | public function getDescription() |
||
121 | 3 | ||
122 | /** |
||
123 | 3 | * Get the value's precision. |
|
124 | 2 | * |
|
125 | * @return float|null The value's precision. Can be null if unknown. |
||
126 | 1 | */ |
|
127 | public function getPrecision() |
||
131 | |||
132 | /** |
||
133 | * Get the value as formatted string with unit. |
||
134 | * |
||
135 | * @return string The value as formatted string with unit. |
||
136 | * |
||
137 | * The unit is not included if it is empty. |
||
138 | */ |
||
139 | public function getFormatted() |
||
147 | } |
||
148 |