1 | <?php |
||
18 | class Node |
||
19 | { |
||
20 | /** |
||
21 | * Node document. |
||
22 | * |
||
23 | * @var DOMDocument |
||
24 | */ |
||
25 | protected $document; |
||
26 | |||
27 | /** |
||
28 | * Node element. |
||
29 | * |
||
30 | * @var DOMElement |
||
31 | */ |
||
32 | protected $element; |
||
33 | |||
34 | /** |
||
35 | * Define the parent node name. |
||
36 | * |
||
37 | * @var string|null |
||
38 | */ |
||
39 | protected $parentNodeName = null; |
||
40 | |||
41 | /** |
||
42 | * Define the node name. |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $nodeName; |
||
47 | |||
48 | /** |
||
49 | * Node attributes. |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $attr = []; |
||
54 | |||
55 | /** |
||
56 | * Create a new node instance. |
||
57 | * |
||
58 | * @param array $attr |
||
59 | */ |
||
60 | public function __construct(array ...$attr) |
||
74 | |||
75 | /** |
||
76 | * Add a new node. |
||
77 | * |
||
78 | * @param \Kinedu\CfdiXML\Common\Node $node |
||
79 | * |
||
80 | * @return void |
||
81 | */ |
||
82 | public function add(Node $node) |
||
135 | |||
136 | /** |
||
137 | * Search the direct child of an element. |
||
138 | * |
||
139 | * @param DOMNodeList $children |
||
140 | * @param string $find |
||
141 | * |
||
142 | * @return DOMElement|null |
||
143 | */ |
||
144 | protected function getDirectChildElementByName(DOMNodeList $children, string $find) |
||
154 | |||
155 | /** |
||
156 | * @param string $schemaDefinition |
||
157 | * @return void |
||
158 | */ |
||
159 | public function setSchemaDefinition(string $schemaDefinition) |
||
172 | |||
173 | /** |
||
174 | * Get node attributes. |
||
175 | * |
||
176 | * @param string $index |
||
177 | * |
||
178 | * @return array|null |
||
179 | */ |
||
180 | public function getAttr(string $index = 'node') |
||
190 | |||
191 | /** |
||
192 | * Adds attributes to an element. |
||
193 | * |
||
194 | * @param DOMElement $element |
||
195 | * @param array $attr |
||
196 | * |
||
197 | * @return void |
||
198 | */ |
||
199 | public function setAttr(DOMElement $element, array $attr = null) |
||
207 | |||
208 | /** |
||
209 | * Get element. |
||
210 | * |
||
211 | * @return DOMElement |
||
212 | */ |
||
213 | public function getElement(): DOMElement |
||
217 | |||
218 | /** |
||
219 | * Get document. |
||
220 | * |
||
221 | * @return DOMDocument |
||
222 | */ |
||
223 | public function getDocument(): DOMDocument |
||
227 | |||
228 | /** |
||
229 | * Get wrapper node name. |
||
230 | * |
||
231 | * @return string|null |
||
232 | */ |
||
233 | public function getWrapperNodeName() |
||
237 | |||
238 | /** |
||
239 | * Get parent node name. |
||
240 | * |
||
241 | * @return string|null |
||
242 | */ |
||
243 | public function getParentNodeName() |
||
247 | |||
248 | /** |
||
249 | * Get node name. |
||
250 | * |
||
251 | * @return string |
||
252 | */ |
||
253 | public function getNodeName() |
||
257 | } |
||
258 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: