1 | <?php |
||
27 | class Node |
||
28 | { |
||
29 | use RecordsIterateTrait; |
||
30 | |||
31 | /** |
||
32 | * @var Zone |
||
33 | */ |
||
34 | private $zone; |
||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | private $name; |
||
39 | /** |
||
40 | * @var RecordAppender |
||
41 | */ |
||
42 | private $recordAppender; |
||
43 | /** |
||
44 | * @var RecordsStore |
||
45 | */ |
||
46 | private $recordsStore; |
||
47 | /** |
||
48 | * @var RecordsStore |
||
49 | */ |
||
50 | private $removedRecordsStore; |
||
51 | |||
52 | /** |
||
53 | * @param Zone $zone |
||
54 | * @param $name |
||
55 | */ |
||
56 | 1 | public function __construct(Zone $zone, string $name) |
|
64 | |||
65 | /** |
||
66 | * @return RecordAppender |
||
67 | */ |
||
68 | 1 | public function getRecordAppender() : RecordAppender |
|
72 | |||
73 | /** |
||
74 | * @return Record[] |
||
75 | */ |
||
76 | public function iterateRemoved() |
||
82 | |||
83 | /** |
||
84 | * @return RecordsStore |
||
85 | */ |
||
86 | protected function getRemovedRecordsStore() |
||
90 | |||
91 | /** |
||
92 | * @param eRecordType|null $type |
||
93 | * @return Record[] |
||
94 | */ |
||
95 | 1 | public function iterateRecords(eRecordType $type = NULL) |
|
101 | |||
102 | /** |
||
103 | * @param eRecordType|NULL $type |
||
104 | */ |
||
105 | public function removeRecords(eRecordType $type = NULL) |
||
111 | |||
112 | /** |
||
113 | * @return bool |
||
114 | */ |
||
115 | public function isEmptyNode() : bool |
||
119 | |||
120 | /** |
||
121 | * @return RecordsStore |
||
122 | */ |
||
123 | 1 | protected function getRecordsStore() : RecordsStore |
|
127 | |||
128 | /** |
||
129 | * @internal |
||
130 | * @param Record $record |
||
131 | * @param eRecordNotification $notification |
||
132 | * @return Node |
||
133 | */ |
||
134 | 1 | public function notify(Record $record, eRecordNotification $notification) : Node |
|
151 | |||
152 | 1 | public function sort() |
|
156 | |||
157 | /** |
||
158 | * @internal |
||
159 | * Full validate zone via build in validators |
||
160 | * @return bool |
||
161 | */ |
||
162 | 1 | public function validate() : bool |
|
163 | { |
||
164 | 1 | $errorsStore = $this->getZone()->getErrorsStore(); |
|
165 | |||
166 | 1 | if (!ConflictTypesValidator::validate($this)) { |
|
167 | $errorsStore->add(ValidationError::makeNodeError($this, eErrorCode::CONFLICT_RECORD_TYPES_ERROR())); |
||
168 | } |
||
169 | |||
170 | 1 | if (!CnameNumberCheck::validate($this)) { |
|
171 | $errorsStore->add(ValidationError::makeNodeError($this, eErrorCode::MULTIPLE_CNAME_ERROR())); |
||
172 | } |
||
173 | |||
174 | 1 | if ($this->getName() === "@" && ! SoaNumberCheck::validate($this)) { |
|
175 | $errorsStore->add(ValidationError::makeNodeError($this, eErrorCode::SOA_ERROR())); |
||
176 | } |
||
177 | |||
178 | 1 | $isValidNodeName = DnsZoneDomainNameValidator::validate($this->getName()); |
|
179 | 1 | foreach ($this->iterateRecords() as $record) { |
|
180 | 1 | if(!$isValidNodeName) { |
|
181 | 1 | $errorsStore->add(ValidationError::makeRecordError($record, eErrorCode::WRONG_NODE_NAME(), "name")); |
|
182 | } |
||
183 | /** @noinspection PhpInternalEntityUsedInspection */ |
||
184 | 1 | $record->validate(); |
|
185 | } |
||
186 | |||
187 | 1 | return !$errorsStore->isHasErrors(); |
|
188 | } |
||
189 | |||
190 | /** |
||
191 | * @return Zone |
||
192 | */ |
||
193 | 1 | public function getZone() : Zone |
|
197 | |||
198 | /** |
||
199 | * @return string |
||
200 | */ |
||
201 | 1 | public function getName() : string |
|
205 | } |