1 | <?php |
||
18 | abstract class JsonDataNode implements JsonDataNodeInterface |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * @var JsonDataNodeValidator $validator |
||
23 | */ |
||
24 | protected $validator; |
||
25 | |||
26 | /** |
||
27 | * @var array $data |
||
28 | */ |
||
29 | private $data = []; |
||
30 | |||
31 | /** |
||
32 | * @var string $domain |
||
33 | */ |
||
34 | private $domain; |
||
35 | |||
36 | /** |
||
37 | * @var boolean $initialized |
||
38 | */ |
||
39 | private $initialized = false; |
||
40 | |||
41 | /** |
||
42 | * @var string $node_name |
||
43 | */ |
||
44 | private $node_name; |
||
45 | |||
46 | |||
47 | /** |
||
48 | * JsonDataNodeHandler constructor. |
||
49 | * |
||
50 | * @param JsonDataNodeValidator $validator |
||
51 | * @throws DomainException |
||
52 | */ |
||
53 | public function __construct(JsonDataNodeValidator $validator) |
||
57 | |||
58 | |||
59 | /** |
||
60 | * for adding primitive data like arrays, integers, or strings |
||
61 | * |
||
62 | * @param string $key |
||
63 | * @param mixed $data |
||
64 | * @throws DomainException |
||
65 | */ |
||
66 | protected function addData($key, $data) |
||
72 | |||
73 | |||
74 | /** |
||
75 | * for embedding other JsonDataNode objects within this one |
||
76 | * |
||
77 | * @param JsonDataNode $data_node |
||
78 | * @throws DomainException |
||
79 | */ |
||
80 | public function addDataNode(JsonDataNode $data_node) |
||
93 | |||
94 | |||
95 | /** |
||
96 | * sets the domain (use case) that this data node provides data for |
||
97 | * |
||
98 | * @param string $domain |
||
99 | * @throws DomainException |
||
100 | */ |
||
101 | protected function setDomain($domain) |
||
108 | |||
109 | |||
110 | /** |
||
111 | * used to mark the data node as having been processed |
||
112 | * |
||
113 | * @param bool $initialized |
||
114 | */ |
||
115 | protected function setInitialized($initialized) |
||
119 | |||
120 | |||
121 | /** |
||
122 | * self explanatory (i hope) |
||
123 | * |
||
124 | * @param string $node_name |
||
125 | * @throws DomainException |
||
126 | */ |
||
127 | protected function setNodeName($node_name) |
||
132 | |||
133 | |||
134 | /** |
||
135 | * the actual data in key value array format |
||
136 | * |
||
137 | * @return array |
||
138 | */ |
||
139 | public function data() |
||
143 | |||
144 | |||
145 | /** |
||
146 | * the domain (use case) that this data node provides data for |
||
147 | * |
||
148 | * @return string |
||
149 | */ |
||
150 | public function domain() |
||
154 | |||
155 | |||
156 | /** |
||
157 | * true if the data node has been initialized, |
||
158 | * which entails retrieving the required data and adding it to the data node data array |
||
159 | * |
||
160 | * @return bool |
||
161 | */ |
||
162 | public function isInitialized() |
||
166 | |||
167 | |||
168 | /** |
||
169 | * true if the data node has NOT been initialized |
||
170 | * |
||
171 | * @return bool |
||
172 | */ |
||
173 | public function isNotInitialized() |
||
177 | |||
178 | |||
179 | /** |
||
180 | * Specify data which should be serialized to JSON |
||
181 | * |
||
182 | * @link https://php.net/manual/en/jsonserializable.jsonserialize.php |
||
183 | * @return mixed data which can be serialized by json_encode |
||
184 | */ |
||
185 | public function jsonSerialize() |
||
189 | |||
190 | |||
191 | /** |
||
192 | * self explanatory (i hope) |
||
193 | * |
||
194 | * @return string |
||
195 | */ |
||
196 | public function nodeName() |
||
200 | } |
||
201 |