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. |
29
|
|
|
* |
30
|
|
|
* @var bool |
31
|
|
|
*/ |
32
|
|
|
protected $skip_int = false; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Set true to skip the generation of type=loc. |
36
|
|
|
* |
37
|
|
|
* @var bool |
38
|
|
|
*/ |
39
|
|
|
protected $skip_loc = false; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $path |
43
|
|
|
* @param mixed $value |
44
|
|
|
* |
45
|
|
|
* @return \DOMElement |
46
|
|
|
*/ |
47
|
|
|
abstract public function set($path = null, $value = null); |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Whether to force ASCI on loc contacts |
51
|
|
|
* |
52
|
|
|
* @param bool $value |
53
|
|
|
* |
54
|
|
|
* @see \AfriCC\EPP\ContactTrait::force_ascii |
55
|
|
|
*/ |
56
|
|
|
public function forceAscii($value = true) |
57
|
|
|
{ |
58
|
|
|
$this->force_ascii = $value; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Skip the generation of type=int. |
63
|
|
|
* |
64
|
|
|
* @param bool $value |
65
|
|
|
*/ |
66
|
|
|
public function skipInt($value = true) |
67
|
|
|
{ |
68
|
|
|
$this->skip_int = $value; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Skip the generation of type=loc. |
73
|
|
|
* |
74
|
|
|
* @param bool $value |
75
|
|
|
*/ |
76
|
|
|
public function skipLoc($value = true) |
77
|
|
|
{ |
78
|
|
|
$this->skip_loc = $value; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function appendId($path, $id) |
82
|
|
|
{ |
83
|
|
|
$this->set($path, $id); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function appendName($path, $name) |
87
|
|
|
{ |
88
|
|
|
if (!$this->skip_loc) { |
89
|
|
|
$this->set(sprintf($path, 'loc'), $this->force_ascii ? Translit::transliterate($name) : $name); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if (!$this->skip_int) { |
93
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($name)); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function appendOrganization($path, $org) |
98
|
|
|
{ |
99
|
|
|
if (!$this->skip_loc) { |
100
|
|
|
$this->set(sprintf($path, 'loc'), $this->force_ascii ? Translit::transliterate($org) : $org); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if (!$this->skip_int) { |
104
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($org)); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function appendStreet($path, $street) |
109
|
|
|
{ |
110
|
|
|
if (!$this->skip_loc) { |
111
|
|
|
$this->set(sprintf($path, 'loc'), $this->force_ascii ? Translit::transliterate($street) : $street); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
if (!$this->skip_int) { |
115
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($street)); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function appendCity($path, $city) |
120
|
|
|
{ |
121
|
|
|
if (!$this->skip_loc) { |
122
|
|
|
$this->set(sprintf($path, 'loc'), $this->force_ascii ? Translit::transliterate($city) : $city); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
if (!$this->skip_int) { |
126
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($city)); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function appendProvince($path, $sp) |
131
|
|
|
{ |
132
|
|
|
if (!$this->skip_loc) { |
133
|
|
|
$this->set(sprintf($path, 'loc'), $this->force_ascii ? Translit::transliterate($sp) : $sp); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
if (!$this->skip_int) { |
137
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($sp)); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function appendPostalCode($path, $pc) |
142
|
|
|
{ |
143
|
|
|
if (!$this->skip_loc) { |
144
|
|
|
$this->set(sprintf($path, 'loc'), $this->force_ascii ? Translit::transliterate($pc) : $pc); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
if (!$this->skip_int) { |
148
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($pc)); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function appendCountryCode($path, $cc) |
153
|
|
|
{ |
154
|
|
|
if (!Validator::isCountryCode($cc)) { |
155
|
|
|
throw new Exception(sprintf('the country-code: \'%s\' is unknown', $cc)); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
if (!$this->skip_loc) { |
159
|
|
|
$this->set(sprintf($path, 'loc'), $this->force_ascii ? Translit::transliterate($cc) : $cc); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
if (!$this->skip_int) { |
163
|
|
|
$this->set(sprintf($path, 'int'), Translit::transliterate($cc)); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function appendVoice($path, $voice, $extension = null) |
168
|
|
|
{ |
169
|
|
|
$node = $this->set($path, $voice); |
170
|
|
|
|
171
|
|
|
if (!is_null($extension)) { |
172
|
|
|
$node->setAttribute('x', $extension); |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function appendFax($path, $fax, $extension = null) |
177
|
|
|
{ |
178
|
|
|
$node = $this->set($path, $fax); |
179
|
|
|
|
180
|
|
|
if (!is_null($extension)) { |
181
|
|
|
$node->setAttribute('x', $extension); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function appendEmail($path, $email) |
186
|
|
|
{ |
187
|
|
|
if (!Validator::isEmail($email)) { |
188
|
|
|
throw new Exception(sprintf('%s is not a valid email', $email)); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
$this->set($path, $email); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function appendAuthInfo($path, $pw = null) |
195
|
|
|
{ |
196
|
|
|
if ($pw === null) { |
197
|
|
|
$pw = Random::auth(12); |
198
|
|
|
} |
199
|
|
|
$this->set($path, $pw); |
200
|
|
|
|
201
|
|
|
return $pw; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function appendDisclose($path) |
205
|
|
|
{ |
206
|
|
|
$this->set($path); |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
|