1: <?php
2:
3: /**
4: * Class CompositeNode
5: *
6: * @version 1.0.2
7: * @author v.raskin
8: * @package vsword.node
9: */
10: abstract class CompositeNode extends Node {
11:
12: protected $childrens = array();
13:
14: /**
15: * @return int
16: */
17: public function addNode(INode $node) {
18: $this->childrens[] = $node;
19: $node->setParent($this);
20: return sizeof($this->childrens) - 1;
21: }
22:
23: /**
24: * @return INode[]
25: */
26: public function getChildrens() {
27: return $this->childrens;
28: }
29:
30: /**
31: * @return INode
32: */
33: public function getNode($index) {
34: return isset($this->childrens[$index]) ? $this->childrens[$index] : NULL;
35: }
36:
37: /**
38: *
39: * @return INode
40: */
41: public function getLastNode() {
42: return sizeof($this->childrens) > 0 ? $this->childrens[sizeof($this->childrens)-1] : NULL;
43: }
44:
45: public function afterNode() {
46: return NULL;
47: }
48:
49:
50: /**
51: * @return string
52: */
53: public function look($tab = '') {
54: $str = parent::look($tab);
55: $tab .= "\t";
56: foreach($this->childrens as $child)
57: $str .= $tab.$child->look($tab);
58: return $str;
59: }
60:
61: }
62:
63:
64:
65:
66:
67:
68:
69:
70: