1 | <?php |
||
51 | class StringGuarantee implements Guarantee |
||
52 | { |
||
53 | /** |
||
54 | * the string data that we represent |
||
55 | * @var string |
||
56 | */ |
||
57 | private $data = ''; |
||
58 | |||
59 | /** |
||
60 | * does $data hold a real value? |
||
61 | * @var boolean |
||
62 | */ |
||
63 | private $isEmpty = true; |
||
64 | |||
65 | /** |
||
66 | * create a read-only, string guarantee from another piece of data |
||
67 | * |
||
68 | * @param mixed $data |
||
69 | * the data to wrap |
||
70 | */ |
||
71 | public function __construct($data) |
||
80 | |||
81 | /** |
||
82 | * return the value of this guarantee (if it has one), or $default if |
||
83 | * this guarantee is empty |
||
84 | * |
||
85 | * @param string $default |
||
86 | * the value to return if this guarantee is empty |
||
87 | * @return string |
||
88 | */ |
||
89 | public function getOrElse($default) |
||
98 | |||
99 | /** |
||
100 | * does this guarantee contain a value? |
||
101 | * |
||
102 | * @return boolean |
||
103 | * TRUE if this guarantee does NOT contain a value |
||
104 | * FALSE otherwise |
||
105 | */ |
||
106 | public function isEmpty() |
||
110 | |||
111 | /** |
||
112 | * get an iterator to traverse the wrapped data |
||
113 | * |
||
114 | * @return Iterator |
||
115 | */ |
||
116 | public function getIterator() |
||
121 | |||
122 | /** |
||
123 | * convert our wrapped data into a JSON string |
||
124 | * |
||
125 | * @return string |
||
126 | */ |
||
127 | public function jsonSerialize() |
||
132 | |||
133 | /** |
||
134 | * convert our data into a string |
||
135 | * |
||
136 | * @return string |
||
137 | */ |
||
138 | public function __toString() |
||
142 | } |
||
143 |