|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the php-epp2 library. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Gunter Grodotzki <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE file |
|
9
|
|
|
* that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace AfriCC\EPP; |
|
13
|
|
|
|
|
14
|
|
|
use Exception; |
|
15
|
|
|
|
|
16
|
|
|
trait ContactTrait |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* this was once needed as the conversion done by COZA was faulty |
|
20
|
|
|
* the bug has since been fixed but this remains to allow testing |
|
21
|
|
|
* set true to force ascii usage on type=loc (which should allow UTF8) |
|
22
|
|
|
* |
|
23
|
|
|
* @var bool |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $force_ascii = false; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* set true to skip the generation of type=int (like .MX) |
|
29
|
|
|
* |
|
30
|
|
|
* @var bool |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $skip_int = false; |
|
33
|
|
|
|
|
34
|
|
|
abstract public function set($path = null, $value = null); |
|
35
|
|
|
|
|
36
|
|
|
public function forceAscii() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->force_ascii = true; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function skipInt() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->skip_int = true; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function appendId($path, $id) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->set($path, $id); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function appendName($path, $name) |
|
52
|
|
|
{ |
|
53
|
|
|
if ($this->force_ascii) { |
|
54
|
|
|
$this->set(sprintf($path, 'loc'), Translit::transliterate($name)); |
|
55
|
|
|
} else { |
|
56
|
|
|
$this->set(sprintf($path, 'loc'), $name); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
if (!$this->skip_int) { |
|
60
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($name)); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function appendOrganization($path, $org) |
|
65
|
|
|
{ |
|
66
|
|
|
if ($this->force_ascii) { |
|
67
|
|
|
$this->set(sprintf($path, 'loc'), Translit::transliterate($org)); |
|
68
|
|
|
} else { |
|
69
|
|
|
$this->set(sprintf($path, 'loc'), $org); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
if (!$this->skip_int) { |
|
73
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($org)); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function appendStreet($path, $street) |
|
78
|
|
|
{ |
|
79
|
|
|
if ($this->force_ascii) { |
|
80
|
|
|
$this->set(sprintf($path, 'loc'), Translit::transliterate($street)); |
|
81
|
|
|
} else { |
|
82
|
|
|
$this->set(sprintf($path, 'loc'), $street); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if (!$this->skip_int) { |
|
86
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($street)); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function appendCity($path, $city) |
|
91
|
|
|
{ |
|
92
|
|
|
if ($this->force_ascii) { |
|
93
|
|
|
$this->set(sprintf($path, 'loc'), Translit::transliterate($city)); |
|
94
|
|
|
} else { |
|
95
|
|
|
$this->set(sprintf($path, 'loc'), $city); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
if (!$this->skip_int) { |
|
99
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($city)); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function appendProvince($path, $sp) |
|
104
|
|
|
{ |
|
105
|
|
|
if ($this->force_ascii) { |
|
106
|
|
|
$this->set(sprintf($path, 'loc'), Translit::transliterate($sp)); |
|
107
|
|
|
} else { |
|
108
|
|
|
$this->set(sprintf($path, 'loc'), $sp); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
if (!$this->skip_int) { |
|
112
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($sp)); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function appendPostalCode($path, $pc) |
|
117
|
|
|
{ |
|
118
|
|
|
if ($this->force_ascii) { |
|
119
|
|
|
$this->set(sprintf($path, 'loc'), Translit::transliterate($pc)); |
|
120
|
|
|
} else { |
|
121
|
|
|
$this->set(sprintf($path, 'loc'), $pc); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
if (!$this->skip_int) { |
|
125
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($pc)); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function appendCountryCode($path, $cc) |
|
130
|
|
|
{ |
|
131
|
|
|
if (!Validator::isCountryCode($cc)) { |
|
132
|
|
|
throw new Exception(sprintf('the country-code: \'%s\' is unknown', $cc)); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
if ($this->force_ascii) { |
|
136
|
|
|
$this->set(sprintf($path, 'loc'), Translit::transliterate($cc)); |
|
137
|
|
|
} else { |
|
138
|
|
|
$this->set(sprintf($path, 'loc'), $cc); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
if (!$this->skip_int) { |
|
142
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($cc)); |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function appendVoice($path, $voice) |
|
147
|
|
|
{ |
|
148
|
|
|
$this->set($path, $voice); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function appendFax($path, $fax) |
|
152
|
|
|
{ |
|
153
|
|
|
$this->set($path, $fax); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
public function appendEmail($path, $email) |
|
157
|
|
|
{ |
|
158
|
|
|
if (!Validator::isEmail($email)) { |
|
159
|
|
|
throw new Exception(sprintf('%s is not a valid email', $email)); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
$this->set($path, $email); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
public function appendAuthInfo($path, $pw = null) |
|
166
|
|
|
{ |
|
167
|
|
|
if ($pw === null) { |
|
168
|
|
|
$pw = Random::auth(12); |
|
169
|
|
|
} |
|
170
|
|
|
$this->set($path, $pw); |
|
171
|
|
|
return $pw; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
public function appendDisclose($path) |
|
175
|
|
|
{ |
|
176
|
|
|
$this->set($path); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
public function appendRole($path, $role) |
|
180
|
|
|
{ |
|
181
|
|
|
$role = Validator::isValidContactRole($role); |
|
182
|
|
|
|
|
183
|
|
|
if ($role === false) { |
|
184
|
|
|
throw new Exception(sprintf('%s is not a valid contact role', $role)); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
$this->set($path, $role); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
public function appendType($path, $type) |
|
191
|
|
|
{ |
|
192
|
|
|
$type = Validator::isValidContactType($type); |
|
193
|
|
|
|
|
194
|
|
|
if ($type === false) { |
|
195
|
|
|
throw new Exception(sprintf('%s is not a valid contact type', $type)); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
$this->set($path, $type); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
public function appendLegalEmail($path, $email) |
|
202
|
|
|
{ |
|
203
|
|
|
$email = Validator::isEmail($email); |
|
204
|
|
|
|
|
205
|
|
|
if (!$email) { |
|
206
|
|
|
throw new Exception(sprintf('%s is not a valid contact type', $email)); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
$this->set($path, $email); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
public function appendFirstName($path, $firstName) |
|
213
|
|
|
{ |
|
214
|
|
|
if ($this->force_ascii) { |
|
215
|
|
|
$this->set(sprintf($path, 'loc'), Translit::transliterate($firstName)); |
|
216
|
|
|
} else { |
|
217
|
|
|
$this->set(sprintf($path, 'loc'), $firstName); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
if (!$this->skip_int) { |
|
221
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($firstName)); |
|
222
|
|
|
} |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
public function appendLastName($path, $lastName) |
|
226
|
|
|
{ |
|
227
|
|
|
if ($this->force_ascii) { |
|
228
|
|
|
$this->set(sprintf($path, 'loc'), Translit::transliterate($lastName)); |
|
229
|
|
|
} else { |
|
230
|
|
|
$this->set(sprintf($path, 'loc'), $lastName); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
if (!$this->skip_int) { |
|
234
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($lastName)); |
|
235
|
|
|
} |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
public function appendRegisterNumber($path, $number) |
|
239
|
|
|
{ |
|
240
|
|
|
if ($this->force_ascii) { |
|
241
|
|
|
$this->set(sprintf($path, 'loc'), Translit::transliterate($number)); |
|
242
|
|
|
} else { |
|
243
|
|
|
$this->set(sprintf($path, 'loc'), $number); |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
if (!$this->skip_int) { |
|
247
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($number)); |
|
248
|
|
|
} |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
public function appendIdentity($path, $identity) |
|
252
|
|
|
{ |
|
253
|
|
|
if ($this->force_ascii) { |
|
254
|
|
|
$this->set(sprintf($path, 'loc'), Translit::transliterate($identity)); |
|
255
|
|
|
} else { |
|
256
|
|
|
$this->set(sprintf($path, 'loc'), $identity); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
if (!$this->skip_int) { |
|
260
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($identity)); |
|
261
|
|
|
} |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
private function appendIsFinish($path, $finish) |
|
265
|
|
|
{ |
|
266
|
|
|
if ($this->force_ascii) { |
|
267
|
|
|
$this->set(sprintf($path, 'loc'), Translit::transliterate($finish)); |
|
268
|
|
|
} else { |
|
269
|
|
|
$this->set(sprintf($path, 'loc'), $finish); |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
if (!$this->skip_int) { |
|
273
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($finish)); |
|
274
|
|
|
} |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
public function appendBirthDay($path, $date) |
|
278
|
|
|
{ |
|
279
|
|
|
if ($this->force_ascii) { |
|
280
|
|
|
$this->set(sprintf($path, 'loc'), Translit::transliterate($date)); |
|
281
|
|
|
} else { |
|
282
|
|
|
$this->set(sprintf($path, 'loc'), $date); |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
if (!$this->skip_int) { |
|
286
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($date)); |
|
287
|
|
|
} |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
public function appendGender($path, $gender) |
|
291
|
|
|
{ |
|
292
|
|
|
if ($this->force_ascii) { |
|
293
|
|
|
$this->set(sprintf($path, 'loc'), Translit::transliterate($gender)); |
|
294
|
|
|
} else { |
|
295
|
|
|
$this->set(sprintf($path, 'loc'), $gender); |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
if (!$this->skip_int) { |
|
299
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($gender)); |
|
300
|
|
|
} |
|
301
|
|
|
} |
|
302
|
|
|
} |