1 | <?php |
||
26 | class Node |
||
27 | { |
||
28 | use RecordsIterateTrait; |
||
29 | |||
30 | /** |
||
31 | * @var Zone |
||
32 | */ |
||
33 | private $zone; |
||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | private $name; |
||
38 | /** |
||
39 | * @var RecordAppender |
||
40 | */ |
||
41 | private $recordAppender; |
||
42 | /** |
||
43 | * @var RecordsStore |
||
44 | */ |
||
45 | private $recordsStore; |
||
46 | /** |
||
47 | * @var RecordsStore |
||
48 | */ |
||
49 | private $removedRecordsStore; |
||
50 | |||
51 | /** |
||
52 | * @param Zone $zone |
||
53 | * @param $name |
||
54 | */ |
||
55 | 1 | public function __construct(Zone $zone, string $name) |
|
56 | { |
||
57 | 1 | $this->zone = $zone; |
|
58 | 1 | $this->name = mb_strtolower(trim($name)); |
|
59 | 1 | $this->recordAppender = new RecordAppender($this); |
|
60 | 1 | $this->recordsStore = new RecordsStore(); |
|
61 | 1 | $this->removedRecordsStore = new RecordsStore(); |
|
62 | 1 | } |
|
63 | |||
64 | /** |
||
65 | * @return RecordAppender |
||
66 | */ |
||
67 | 1 | public function getRecordAppender() : RecordAppender |
|
68 | { |
||
69 | 1 | return $this->recordAppender; |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * @return Record[] |
||
74 | */ |
||
75 | public function iterateRemoved() |
||
76 | { |
||
77 | foreach ($this->getRemovedRecordsStore()->iterate() as $record) { |
||
78 | yield $record; |
||
79 | } |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @return RecordsStore |
||
84 | */ |
||
85 | protected function getRemovedRecordsStore() |
||
86 | { |
||
87 | return $this->removedRecordsStore; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @param eRecordType|null $type |
||
92 | * @return Record[] |
||
93 | */ |
||
94 | 1 | public function iterateRecords(eRecordType $type = NULL) |
|
95 | { |
||
96 | 1 | foreach ($this->getRecordsStore()->iterate($type) as $record) { |
|
97 | 1 | yield $record; |
|
98 | } |
||
99 | 1 | } |
|
100 | |||
101 | /** |
||
102 | * @param eRecordType|NULL $type |
||
103 | */ |
||
104 | public function removeRecords(eRecordType $type = NULL) |
||
105 | { |
||
106 | foreach ($this->iterateRecords($type) as $record) { |
||
107 | $record->remove(); |
||
108 | } |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * @return bool |
||
113 | */ |
||
114 | public function isEmptyNode() : bool |
||
115 | { |
||
116 | return $this->getRecordsStore()->count() === 0; |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * @return RecordsStore |
||
121 | */ |
||
122 | 1 | protected function getRecordsStore() : RecordsStore |
|
126 | |||
127 | /** |
||
128 | * @internal |
||
129 | * @param Record $record |
||
130 | * @param eRecordNotification $notification |
||
131 | * @return Node |
||
132 | */ |
||
133 | 1 | public function notify(Record $record, eRecordNotification $notification) : Node |
|
150 | |||
151 | 1 | public function sort() |
|
155 | |||
156 | /** |
||
157 | * @internal |
||
158 | * Full validate zone via build in validators |
||
159 | * @return bool |
||
160 | */ |
||
161 | 1 | public function validate() : bool |
|
184 | |||
185 | /** |
||
186 | * @return Zone |
||
187 | */ |
||
188 | 1 | public function getZone() : Zone |
|
192 | |||
193 | /** |
||
194 | * @return string |
||
195 | */ |
||
196 | 1 | public function getName() : string |
|
200 | } |