1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LTDBeget\dns\configurator\zoneEntities\record; |
4
|
|
|
|
5
|
|
|
use LTDBeget\dns\configurator\errors\ValidationError; |
6
|
|
|
use LTDBeget\dns\configurator\validators\DnsZoneDomainNameValidator; |
7
|
|
|
use LTDBeget\dns\configurator\validators\Int16Validator; |
8
|
|
|
use LTDBeget\dns\configurator\zoneEntities\Node; |
9
|
|
|
use LTDBeget\dns\configurator\zoneEntities\record\base\Record; |
10
|
|
|
use LTDBeget\dns\enums\eErrorCode; |
11
|
|
|
use LTDBeget\dns\enums\eRecordType; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class NaptrRecord |
15
|
|
|
* |
16
|
|
|
* @package LTDBeget\dns\configurator\zoneEntities\record |
17
|
|
|
*/ |
18
|
|
|
class NaptrRecord extends Record |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var Int |
22
|
|
|
*/ |
23
|
|
|
protected $order; |
24
|
|
|
/** |
25
|
|
|
* @var Int |
26
|
|
|
*/ |
27
|
|
|
protected $preference; |
28
|
|
|
/** |
29
|
|
|
* @var int |
30
|
|
|
*/ |
31
|
|
|
protected $flags; |
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $services; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $regexp; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $replacement; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* NaptrRecord constructor. |
49
|
|
|
* |
50
|
|
|
* @param Node $node |
51
|
|
|
* @param int $ttl |
52
|
|
|
* @param int $order |
53
|
|
|
* @param int $preference |
54
|
|
|
* @param string $flags |
55
|
|
|
* @param string $services |
56
|
|
|
* @param string $regexp |
57
|
|
|
* @param string $replacement |
58
|
|
|
*/ |
59
|
|
|
public function __construct(Node $node, int $ttl, |
60
|
|
|
int $order, int $preference, string $flags, string $services, |
61
|
|
|
string $regexp, string $replacement) |
62
|
|
|
{ |
63
|
|
|
$this->order = $order; |
64
|
|
|
$this->preference = $preference; |
65
|
|
|
$this->flags = $flags; |
|
|
|
|
66
|
|
|
$this->services = $services; |
67
|
|
|
$this->regexp = $regexp; |
68
|
|
|
$this->replacement = $replacement; |
69
|
|
|
parent::__construct($node, eRecordType::NAPTR(), $ttl); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
public function __toString(): string |
76
|
|
|
{ |
77
|
|
|
return $this->getMainRecordPart() . ' ' . |
78
|
|
|
implode(' ', [ |
79
|
|
|
$this->getOrder(), |
80
|
|
|
$this->getPreference(), |
81
|
|
|
$this->getFlags(), |
82
|
|
|
$this->getServices(), |
83
|
|
|
$this->getRegexp(), |
84
|
|
|
$this->getReplacement() |
85
|
|
|
]); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return Int |
90
|
|
|
*/ |
91
|
|
|
public function getOrder() |
92
|
|
|
{ |
93
|
|
|
return $this->order; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param Int $order |
98
|
|
|
* |
99
|
|
|
* @return Record |
100
|
|
|
*/ |
101
|
|
|
public function setOrder(Int $order) |
102
|
|
|
{ |
103
|
|
|
return $this->setAttribute('order', $order); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return Int |
108
|
|
|
*/ |
109
|
|
|
public function getPreference() |
110
|
|
|
{ |
111
|
|
|
return $this->preference; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param Int $preference |
116
|
|
|
* |
117
|
|
|
* @return Record |
118
|
|
|
*/ |
119
|
|
|
public function setPreference(Int $preference) |
120
|
|
|
{ |
121
|
|
|
return $this->setAttribute('preference', $preference); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
|
|
public function getFlags() |
128
|
|
|
{ |
129
|
|
|
return $this->flags; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param string $flags |
134
|
|
|
* |
135
|
|
|
* @return Record |
136
|
|
|
*/ |
137
|
|
|
public function setFlags(string $flags) |
138
|
|
|
{ |
139
|
|
|
return $this->setAttribute('flags', $flags); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
|
|
public function getServices() |
146
|
|
|
{ |
147
|
|
|
return $this->services; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param string $services |
152
|
|
|
* |
153
|
|
|
* @return Record |
154
|
|
|
*/ |
155
|
|
|
public function setServices(string $services) |
156
|
|
|
{ |
157
|
|
|
return $this->setAttribute('services', $services); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @return string |
162
|
|
|
*/ |
163
|
|
|
public function getRegexp() |
164
|
|
|
{ |
165
|
|
|
return $this->regexp; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param string $regexp |
170
|
|
|
* |
171
|
|
|
* @return Record |
172
|
|
|
*/ |
173
|
|
|
public function setRegexp(string $regexp) |
174
|
|
|
{ |
175
|
|
|
return $this->setAttribute('regexp', $regexp); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @return string |
180
|
|
|
*/ |
181
|
|
|
public function getReplacement() |
182
|
|
|
{ |
183
|
|
|
return $this->replacement; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @param string $replacement |
188
|
|
|
* |
189
|
|
|
* @return Record |
190
|
|
|
*/ |
191
|
|
|
public function setReplacement(string $replacement) |
192
|
|
|
{ |
193
|
|
|
return $this->setAttribute('replacement', $replacement); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @return bool |
198
|
|
|
*/ |
199
|
|
View Code Duplication |
public function validate(): bool |
|
|
|
|
200
|
|
|
{ |
201
|
|
|
$errorStorage = $this->getNode()->getZone()->getErrorsStore(); |
202
|
|
|
|
203
|
|
|
if (!DnsZoneDomainNameValidator::validate($this->getReplacement())) { |
204
|
|
|
$errorStorage->add(ValidationError::makeRecordError($this, eErrorCode::WRONG_DOMAIN_NAME(), 'replacement')); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
$integerAttributes = [ |
208
|
|
|
'order' => $this->getOrder(), |
209
|
|
|
'preference' => $this->getPreference(), |
210
|
|
|
]; |
211
|
|
|
|
212
|
|
|
foreach ($integerAttributes as $atr => $value) { |
213
|
|
|
if (!Int16Validator::validate($value)) { |
214
|
|
|
$errorStorage->add(ValidationError::makeRecordError($this, eErrorCode::WRONG_INT16(), $atr)); |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** @noinspection PhpInternalEntityUsedInspection */ |
219
|
|
|
return parent::validate(); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @return array |
224
|
|
|
*/ |
225
|
|
|
protected function recordDataToArray(): array |
226
|
|
|
{ |
227
|
|
|
return [ |
228
|
|
|
'ORDER' => $this->getOrder(), |
229
|
|
|
'PREFERENCE' => $this->getPreference(), |
230
|
|
|
'FLAGS' => $this->getFlags(), |
231
|
|
|
'SERVICES' => $this->getServices(), |
232
|
|
|
'REGEXP' => $this->getRegexp(), |
233
|
|
|
'REPLACEMENT' => $this->getReplacement(), |
234
|
|
|
]; |
235
|
|
|
} |
236
|
|
|
} |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.