1 | <?php |
||
25 | abstract class MeasuredObject implements JsonSerializable |
||
26 | { |
||
27 | /** |
||
28 | * Contains the value |
||
29 | * |
||
30 | * @var mixed |
||
31 | */ |
||
32 | protected $value; |
||
33 | |||
34 | /** |
||
35 | * Contains the unit of measurement |
||
36 | * |
||
37 | * @var Unit |
||
38 | */ |
||
39 | protected $unit; |
||
40 | |||
41 | /** |
||
42 | * @param mixed $value |
||
43 | * @param Unit $unit |
||
44 | * |
||
45 | * @throws InvalidArgumentException If given data is not an integer |
||
46 | */ |
||
47 | public function __construct($value, Unit $unit) |
||
52 | |||
53 | /** |
||
54 | * Sets the value |
||
55 | * |
||
56 | * @param mixed $value |
||
57 | * |
||
58 | * @return void |
||
59 | */ |
||
60 | protected function setValue($value) |
||
64 | |||
65 | /** |
||
66 | * Sets the unit |
||
67 | * |
||
68 | * @param Unit $unit |
||
69 | * |
||
70 | * @return void |
||
71 | */ |
||
72 | protected function setUnit(Unit $unit) |
||
76 | |||
77 | /** |
||
78 | * Getter for value |
||
79 | * |
||
80 | * @return mixed |
||
81 | */ |
||
82 | public function getValue() |
||
86 | |||
87 | /** |
||
88 | * Getter for unit |
||
89 | * |
||
90 | * @return Unit |
||
91 | */ |
||
92 | public function getUnit() |
||
96 | |||
97 | /** |
||
98 | * @inheritDoc |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | public function jsonSerialize() |
||
109 | |||
110 | /** |
||
111 | * Returns string representation |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | public function __toString() |
||
119 | } |
||
120 |