1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace libphonenumber; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Phone Number Description |
7
|
|
|
*/ |
8
|
|
|
class PhoneNumberDesc |
9
|
|
|
{ |
10
|
|
|
protected $hasNationalNumberPattern = false; |
11
|
|
|
protected $nationalNumberPattern = ""; |
12
|
|
|
protected $hasPossibleNumberPattern = false; |
13
|
|
|
protected $possibleNumberPattern = ""; |
14
|
|
|
protected $hasExampleNumber = false; |
15
|
|
|
protected $exampleNumber = ""; |
16
|
|
|
/** |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
protected $possibleLength; |
20
|
|
|
/** |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
protected $possibleLengthLocalOnly; |
24
|
|
|
|
25
|
1374 |
|
public function __construct() |
26
|
|
|
{ |
27
|
1374 |
|
$this->clear(); |
28
|
1374 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return PhoneNumberDesc |
32
|
|
|
*/ |
33
|
1374 |
|
public function clear() |
34
|
|
|
{ |
35
|
1374 |
|
$this->clearNationalNumberPattern(); |
36
|
1374 |
|
$this->clearPossibleNumberPattern(); |
37
|
1374 |
|
$this->clearPossibleLength(); |
38
|
1374 |
|
$this->clearPossibleLengthLocalOnly(); |
39
|
1374 |
|
$this->clearExampleNumber(); |
40
|
|
|
|
41
|
1374 |
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
3328 |
|
public function getPossibleLength() |
48
|
|
|
{ |
49
|
3328 |
|
return $this->possibleLength; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param array $possibleLength |
54
|
|
|
*/ |
55
|
1365 |
|
public function setPossibleLength($possibleLength) |
56
|
|
|
{ |
57
|
1365 |
|
$this->possibleLength = $possibleLength; |
58
|
1365 |
|
} |
59
|
|
|
|
60
|
8 |
|
public function addPossibleLength($possibleLength) |
61
|
|
|
{ |
62
|
8 |
|
if (!in_array($possibleLength, $this->possibleLength)) { |
63
|
8 |
|
$this->possibleLength[] = $possibleLength; |
64
|
8 |
|
} |
65
|
8 |
|
} |
66
|
|
|
|
67
|
1374 |
|
public function clearPossibleLength() |
68
|
|
|
{ |
69
|
1374 |
|
$this->possibleLength = array(); |
70
|
1374 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
3280 |
|
public function getPossibleLengthLocalOnly() |
76
|
|
|
{ |
77
|
3280 |
|
return $this->possibleLengthLocalOnly; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param array $possibleLengthLocalOnly |
82
|
|
|
*/ |
83
|
1350 |
|
public function setPossibleLengthLocalOnly($possibleLengthLocalOnly) |
84
|
|
|
{ |
85
|
1350 |
|
$this->possibleLengthLocalOnly = $possibleLengthLocalOnly; |
86
|
1350 |
|
} |
87
|
|
|
|
88
|
4 |
|
public function addPossibleLengthLocalOnly($possibleLengthLocalOnly) |
89
|
|
|
{ |
90
|
4 |
|
if (!in_array($possibleLengthLocalOnly, $this->possibleLengthLocalOnly)) { |
91
|
4 |
|
$this->possibleLengthLocalOnly[] = $possibleLengthLocalOnly; |
92
|
4 |
|
} |
93
|
4 |
|
} |
94
|
|
|
|
95
|
1374 |
|
public function clearPossibleLengthLocalOnly() |
96
|
|
|
{ |
97
|
1374 |
|
$this->possibleLengthLocalOnly = array(); |
98
|
1374 |
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return boolean |
102
|
|
|
*/ |
103
|
485 |
|
public function hasNationalNumberPattern() |
104
|
|
|
{ |
105
|
485 |
|
return $this->hasNationalNumberPattern; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
2968 |
|
public function getNationalNumberPattern() |
112
|
|
|
{ |
113
|
2968 |
|
return $this->nationalNumberPattern; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param string $value |
118
|
|
|
* @return PhoneNumberDesc |
119
|
|
|
*/ |
120
|
1357 |
|
public function setNationalNumberPattern($value) |
121
|
|
|
{ |
122
|
1357 |
|
$this->hasNationalNumberPattern = true; |
123
|
1357 |
|
$this->nationalNumberPattern = $value; |
124
|
|
|
|
125
|
1357 |
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return PhoneNumberDesc |
130
|
|
|
*/ |
131
|
1374 |
|
public function clearNationalNumberPattern() |
132
|
|
|
{ |
133
|
1374 |
|
$this->hasNationalNumberPattern = false; |
134
|
1374 |
|
$this->nationalNumberPattern = ''; |
135
|
1374 |
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return boolean |
140
|
|
|
*/ |
141
|
485 |
|
public function hasPossibleNumberPattern() |
142
|
|
|
{ |
143
|
485 |
|
return $this->hasPossibleNumberPattern; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return string |
148
|
|
|
*/ |
149
|
21 |
|
public function getPossibleNumberPattern() |
150
|
|
|
{ |
151
|
21 |
|
return $this->possibleNumberPattern; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return PhoneNumberDesc |
156
|
|
|
*/ |
157
|
1374 |
|
public function clearPossibleNumberPattern() |
158
|
|
|
{ |
159
|
1374 |
|
$this->hasPossibleNumberPattern = false; |
160
|
1374 |
|
$this->possibleNumberPattern = ''; |
161
|
1374 |
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param string $value |
166
|
|
|
* @return PhoneNumberDesc |
167
|
|
|
*/ |
168
|
|
|
public function setPossibleNumberPattern($value) |
169
|
|
|
{ |
170
|
|
|
$this->hasPossibleNumberPattern = true; |
171
|
|
|
$this->possibleNumberPattern = $value; |
172
|
|
|
|
173
|
|
|
return $this; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @return string |
178
|
|
|
*/ |
179
|
5345 |
|
public function hasExampleNumber() |
180
|
|
|
{ |
181
|
5345 |
|
return $this->hasExampleNumber; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @return string |
186
|
|
|
*/ |
187
|
3229 |
|
public function getExampleNumber() |
188
|
|
|
{ |
189
|
3229 |
|
return $this->exampleNumber; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @param string $value |
194
|
|
|
* @return PhoneNumberDesc |
195
|
|
|
*/ |
196
|
1332 |
|
public function setExampleNumber($value) |
197
|
|
|
{ |
198
|
1332 |
|
$this->hasExampleNumber = true; |
199
|
1332 |
|
$this->exampleNumber = $value; |
200
|
|
|
|
201
|
1332 |
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @return PhoneNumberDesc |
206
|
|
|
*/ |
207
|
1374 |
|
public function clearExampleNumber() |
208
|
|
|
{ |
209
|
1374 |
|
$this->hasExampleNumber = false; |
210
|
1374 |
|
$this->exampleNumber = ''; |
211
|
|
|
|
212
|
1374 |
|
return $this; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @param PhoneNumberDesc $other |
217
|
|
|
* @return PhoneNumberDesc |
218
|
|
|
*/ |
219
|
3 |
|
public function mergeFrom(PhoneNumberDesc $other) |
220
|
|
|
{ |
221
|
3 |
|
if ($other->hasNationalNumberPattern()) { |
222
|
3 |
|
$this->setNationalNumberPattern($other->getNationalNumberPattern()); |
223
|
3 |
|
} |
224
|
3 |
|
if ($other->hasPossibleNumberPattern()) { |
225
|
|
|
$this->setPossibleNumberPattern($other->getPossibleNumberPattern()); |
226
|
|
|
} |
227
|
3 |
|
if ($other->hasExampleNumber()) { |
228
|
3 |
|
$this->setExampleNumber($other->getExampleNumber()); |
229
|
3 |
|
} |
230
|
3 |
|
$this->setPossibleLength($other->getPossibleLength()); |
231
|
3 |
|
$this->setPossibleLengthLocalOnly($other->getPossibleLengthLocalOnly()); |
232
|
|
|
|
233
|
3 |
|
return $this; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* @param PhoneNumberDesc $other |
238
|
|
|
* @return boolean |
239
|
|
|
*/ |
240
|
|
|
public function exactlySameAs(PhoneNumberDesc $other) |
241
|
|
|
{ |
242
|
|
|
return $this->nationalNumberPattern === $other->nationalNumberPattern && |
243
|
|
|
$this->possibleNumberPattern === $other->possibleNumberPattern && |
244
|
|
|
$this->exampleNumber === $other->exampleNumber; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @return array |
249
|
|
|
*/ |
250
|
482 |
|
public function toArray() |
251
|
|
|
{ |
252
|
482 |
|
$data = array(); |
253
|
482 |
|
if ($this->hasNationalNumberPattern()) { |
254
|
482 |
|
$data['NationalNumberPattern'] = $this->getNationalNumberPattern(); |
255
|
482 |
|
} |
256
|
482 |
|
if ($this->hasPossibleNumberPattern()) { |
257
|
|
|
$data['PossibleNumberPattern'] = $this->getPossibleNumberPattern(); |
258
|
|
|
} |
259
|
482 |
|
if ($this->hasExampleNumber()) { |
260
|
482 |
|
$data['ExampleNumber'] = $this->getExampleNumber(); |
261
|
482 |
|
} |
262
|
|
|
|
263
|
482 |
|
$data['PossibleLength'] = $this->getPossibleLength(); |
264
|
482 |
|
$data['PossibleLengthLocalOnly'] = $this->getPossibleLengthLocalOnly(); |
265
|
|
|
|
266
|
482 |
|
return $data; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* @param array $input |
271
|
|
|
* @return PhoneNumberDesc |
272
|
|
|
*/ |
273
|
1346 |
|
public function fromArray(array $input) |
274
|
|
|
{ |
275
|
1346 |
|
if (isset($input['NationalNumberPattern']) && $input['NationalNumberPattern'] != '') { |
276
|
1346 |
|
$this->setNationalNumberPattern($input['NationalNumberPattern']); |
277
|
1346 |
|
} |
278
|
1346 |
|
if (isset($input['PossibleNumberPattern']) && $input['NationalNumberPattern'] != '') { |
279
|
|
|
$this->setPossibleNumberPattern($input['PossibleNumberPattern']); |
280
|
|
|
} |
281
|
1346 |
|
if (isset($input['ExampleNumber']) && $input['NationalNumberPattern'] != '') { |
282
|
1328 |
|
$this->setExampleNumber($input['ExampleNumber']); |
283
|
1328 |
|
} |
284
|
1346 |
|
$this->setPossibleLength($input['PossibleLength']); |
285
|
1346 |
|
$this->setPossibleLengthLocalOnly($input['PossibleLengthLocalOnly']); |
286
|
|
|
|
287
|
1346 |
|
return $this; |
288
|
|
|
} |
289
|
|
|
} |
290
|
|
|
|