File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ namespace mle86 \Value ;
3+
4+
5+ /**
6+ * This extension of AbstractValue provides easy serializability
7+ * for the Value objects. It implements the PHP 5.4 JsonSerializable interface.
8+ *
9+ * @author Maximilian Eul
10+ */
11+ abstract class AbstractSerializableValue
12+ extends AbstractValue
13+ implements \JsonSerializable
14+ {
15+
16+ /**
17+ * Returns the wrapped value -- like value(), but with an explicit
18+ * string typecast. This allows string concatenation of Value objects.
19+ * (The typecast is necessary to prevent type mismatch errors
20+ * for number-wrapping classes.)
21+ *
22+ * @return string
23+ */
24+ public function __toString () {
25+ return (string )$ this ->value ();
26+ }
27+
28+
29+ /**
30+ * Returns the wrapped value -- like value().
31+ * This enables json_encode() to encode the Value object.
32+ *
33+ * @return mixed
34+ */
35+ public function jsonSerialize () {
36+ return $ this ->value ();
37+ }
38+
39+ }
40+
You can’t perform that action at this time.
0 commit comments