|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace libphonenumber; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Number Format |
|
7
|
|
|
*/ |
|
8
|
|
|
class NumberFormat |
|
9
|
|
|
{ |
|
10
|
|
|
protected $pattern = null; |
|
11
|
|
|
protected $format = null; |
|
12
|
|
|
protected $leadingDigitsPattern = array(); |
|
13
|
|
|
protected $nationalPrefixFormattingRule = null; |
|
14
|
|
|
protected $domesticCarrierCodeFormattingRule = null; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @return boolean |
|
18
|
|
|
*/ |
|
19
|
3 |
|
public function hasPattern() |
|
20
|
|
|
{ |
|
21
|
3 |
|
return isset($this->pattern); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @return string |
|
26
|
|
|
*/ |
|
27
|
46 |
|
public function getPattern() |
|
28
|
|
|
{ |
|
29
|
46 |
|
return $this->pattern; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param string $value |
|
34
|
|
|
* @return NumberFormat |
|
35
|
|
|
*/ |
|
36
|
556 |
|
public function setPattern($value) |
|
37
|
|
|
{ |
|
38
|
556 |
|
$this->pattern = $value; |
|
39
|
|
|
|
|
40
|
556 |
|
return $this; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return boolean |
|
45
|
|
|
*/ |
|
46
|
3 |
|
public function hasFormat() |
|
47
|
|
|
{ |
|
48
|
3 |
|
return isset($this->format); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
46 |
|
public function getFormat() |
|
55
|
|
|
{ |
|
56
|
46 |
|
return $this->format; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param string $value |
|
61
|
|
|
* @return NumberFormat |
|
62
|
|
|
*/ |
|
63
|
556 |
|
public function setFormat($value) |
|
64
|
|
|
{ |
|
65
|
556 |
|
$this->format = $value; |
|
66
|
|
|
|
|
67
|
556 |
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return string |
|
72
|
|
|
*/ |
|
73
|
|
|
public function leadingDigitPatterns() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->leadingDigitsPattern; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return int |
|
80
|
|
|
*/ |
|
81
|
44 |
|
public function leadingDigitsPatternSize() |
|
82
|
|
|
{ |
|
83
|
44 |
|
return count($this->leadingDigitsPattern); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param int $index |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
39 |
|
public function getLeadingDigitsPattern($index) |
|
91
|
|
|
{ |
|
92
|
39 |
|
return $this->leadingDigitsPattern[$index]; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @param string $value |
|
97
|
|
|
* @return NumberFormat |
|
98
|
|
|
*/ |
|
99
|
410 |
|
public function addLeadingDigitsPattern($value) |
|
100
|
|
|
{ |
|
101
|
410 |
|
$this->leadingDigitsPattern[] = $value; |
|
102
|
|
|
|
|
103
|
410 |
|
return $this; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return boolean |
|
108
|
|
|
*/ |
|
109
|
3 |
|
public function hasNationalPrefixFormattingRule() |
|
110
|
|
|
{ |
|
111
|
3 |
|
return isset($this->nationalPrefixFormattingRule); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
42 |
|
public function getNationalPrefixFormattingRule() |
|
118
|
|
|
{ |
|
119
|
42 |
|
return $this->nationalPrefixFormattingRule; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @param string $value |
|
124
|
|
|
* @return NumberFormat |
|
125
|
|
|
*/ |
|
126
|
556 |
|
public function setNationalPrefixFormattingRule($value) |
|
127
|
|
|
{ |
|
128
|
556 |
|
$this->nationalPrefixFormattingRule = $value; |
|
129
|
|
|
|
|
130
|
556 |
|
return $this; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return NumberFormat |
|
135
|
|
|
*/ |
|
136
|
2 |
|
public function clearNationalPrefixFormattingRule() |
|
137
|
|
|
{ |
|
138
|
2 |
|
$this->nationalPrefixFormattingRule = null; |
|
139
|
|
|
|
|
140
|
2 |
|
return $this; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @return boolean |
|
145
|
|
|
*/ |
|
146
|
3 |
|
public function hasDomesticCarrierCodeFormattingRule() |
|
147
|
|
|
{ |
|
148
|
3 |
|
return isset($this->domesticCarrierCodeFormattingRule); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @return string |
|
153
|
|
|
*/ |
|
154
|
4 |
|
public function getDomesticCarrierCodeFormattingRule() |
|
155
|
|
|
{ |
|
156
|
4 |
|
return $this->domesticCarrierCodeFormattingRule; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @param string $value |
|
161
|
|
|
* @return NumberFormat |
|
162
|
|
|
*/ |
|
163
|
556 |
|
public function setDomesticCarrierCodeFormattingRule($value) |
|
164
|
|
|
{ |
|
165
|
556 |
|
$this->domesticCarrierCodeFormattingRule = $value; |
|
166
|
|
|
|
|
167
|
556 |
|
return $this; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @param NumberFormat $other |
|
172
|
|
|
* @return NumberFormat |
|
173
|
|
|
*/ |
|
174
|
3 |
|
public function mergeFrom(NumberFormat $other) |
|
175
|
|
|
{ |
|
176
|
3 |
|
if ($other->hasPattern()) { |
|
177
|
3 |
|
$this->setPattern($other->getPattern()); |
|
178
|
|
|
} |
|
179
|
3 |
|
if ($other->hasFormat()) { |
|
180
|
3 |
|
$this->setFormat($other->getFormat()); |
|
181
|
|
|
} |
|
182
|
3 |
|
$leadingDigitsPatternSize = $other->leadingDigitsPatternSize(); |
|
183
|
3 |
|
for ($i = 0; $i < $leadingDigitsPatternSize; $i++) { |
|
184
|
2 |
|
$this->addLeadingDigitsPattern($other->getLeadingDigitsPattern($i)); |
|
185
|
|
|
} |
|
186
|
3 |
|
if ($other->hasNationalPrefixFormattingRule()) { |
|
187
|
3 |
|
$this->setNationalPrefixFormattingRule($other->getNationalPrefixFormattingRule()); |
|
188
|
|
|
} |
|
189
|
3 |
|
if ($other->hasDomesticCarrierCodeFormattingRule()) { |
|
190
|
2 |
|
$this->setDomesticCarrierCodeFormattingRule($other->getDomesticCarrierCodeFormattingRule()); |
|
191
|
|
|
} |
|
192
|
3 |
|
return $this; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* @return array |
|
197
|
|
|
*/ |
|
198
|
|
|
public function toArray() |
|
199
|
|
|
{ |
|
200
|
|
|
$output = array(); |
|
201
|
|
|
$output['pattern'] = $this->getPattern(); |
|
202
|
|
|
$output['format'] = $this->getFormat(); |
|
203
|
|
|
|
|
204
|
|
|
$output['leadingDigitsPatterns'] = $this->leadingDigitPatterns(); |
|
205
|
|
|
|
|
206
|
|
|
if ($this->hasNationalPrefixFormattingRule()) { |
|
207
|
|
|
$output['nationalPrefixFormattingRule'] = $this->getNationalPrefixFormattingRule(); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
if ($this->hasDomesticCarrierCodeFormattingRule()) { |
|
211
|
|
|
$output['domesticCarrierCodeFormattingRule'] = $this->getDomesticCarrierCodeFormattingRule(); |
|
212
|
|
|
} |
|
213
|
|
|
return $output; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @param array $input |
|
218
|
|
|
*/ |
|
219
|
556 |
|
public function fromArray(array $input) |
|
220
|
|
|
{ |
|
221
|
556 |
|
$this->setPattern($input['pattern']); |
|
222
|
556 |
|
$this->setFormat($input['format']); |
|
223
|
556 |
|
foreach ($input['leadingDigitsPatterns'] as $leadingDigitsPattern) { |
|
224
|
410 |
|
$this->addLeadingDigitsPattern($leadingDigitsPattern); |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
556 |
|
if (isset($input['nationalPrefixFormattingRule'])) { |
|
228
|
556 |
|
$this->setNationalPrefixFormattingRule($input['nationalPrefixFormattingRule']); |
|
229
|
|
|
} |
|
230
|
556 |
|
if (isset($input['domesticCarrierCodeFormattingRule'])) { |
|
231
|
556 |
|
$this->setDomesticCarrierCodeFormattingRule($input['domesticCarrierCodeFormattingRule']); |
|
232
|
|
|
} |
|
233
|
556 |
|
} |
|
234
|
|
|
} |
|
235
|
|
|
|