PluginProbe
PayPlug for WooCommerce (Official) / 2.5.2
PayPlug for WooCommerce (Official) v2.5.2
3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 All 101 releases
payplug / lib / libphonenumber / NumberFormat.php

NumberFormat.php in PayPlug for WooCommerce (Official) 2.5.2, at lib/libphonenumber/NumberFormat.php

354 lines 8.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace libphonenumber;
4
5 /**
6 * Number Format
7 */
8 class NumberFormat
9 {
10 /**
11 * @var string
12 */
13 protected $pattern;
14 /**
15 * @var bool
16 */
17 protected $hasPattern = false;
18
19 /**
20 * @var string
21 */
22 protected $format;
23
24 /**
25 * @var bool
26 */
27 protected $hasFormat = false;
28
29 /**
30 * @var array
31 */
32 protected $leadingDigitsPattern = array();
33
34 /**
35 * @var string
36 */
37 protected $nationalPrefixFormattingRule;
38
39 /**
40 * @var bool
41 */
42 protected $hasNationalPrefixFormattingRule = false;
43 /**
44 * @var bool
45 */
46 protected $nationalPrefixOptionalWhenFormatting = false;
47
48 /**
49 * @var bool
50 */
51 protected $hasNationalPrefixOptionalWhenFormatting = false;
52
53 /**
54 * @var string
55 */
56 protected $domesticCarrierCodeFormattingRule;
57
58 /**
59 * @var bool
60 */
61 protected $hasDomesticCarrierCodeFormattingRule = false;
62
63 public function __construct()
64 {
65 $this->clear();
66 }
67
68 /**
69 * @return NumberFormat
70 */
71 public function clear()
72 {
73 $this->hasPattern = false;
74 $this->pattern = null;
75
76 $this->hasFormat = false;
77 $this->format = null;
78
79 $this->leadingDigitsPattern = array();
80
81 $this->hasNationalPrefixFormattingRule = false;
82 $this->nationalPrefixFormattingRule = null;
83
84 $this->hasNationalPrefixOptionalWhenFormatting = false;
85 $this->nationalPrefixOptionalWhenFormatting = false;
86
87 $this->hasDomesticCarrierCodeFormattingRule = false;
88 $this->domesticCarrierCodeFormattingRule = null;
89
90 return $this;
91 }
92
93 /**
94 * @return boolean
95 */
96 public function hasPattern()
97 {
98 return $this->hasPattern;
99 }
100
101 /**
102 * @return string
103 */
104 public function getPattern()
105 {
106 return $this->pattern;
107 }
108
109 /**
110 * @param string $value
111 * @return NumberFormat
112 */
113 public function setPattern($value)
114 {
115 $this->hasPattern = true;
116 $this->pattern = $value;
117
118 return $this;
119 }
120
121 /**
122 * @return boolean
123 */
124 public function hasNationalPrefixOptionalWhenFormatting()
125 {
126 return $this->hasNationalPrefixOptionalWhenFormatting;
127 }
128
129 /**
130 * @return boolean
131 */
132 public function getNationalPrefixOptionalWhenFormatting()
133 {
134 return $this->nationalPrefixOptionalWhenFormatting;
135 }
136
137 /**
138 * @param boolean $nationalPrefixOptionalWhenFormatting
139 */
140 public function setNationalPrefixOptionalWhenFormatting($nationalPrefixOptionalWhenFormatting)
141 {
142 $this->hasNationalPrefixOptionalWhenFormatting = true;
143 $this->nationalPrefixOptionalWhenFormatting = $nationalPrefixOptionalWhenFormatting;
144 }
145
146 /**
147 * @return boolean
148 */
149 public function hasFormat()
150 {
151 return $this->hasFormat;
152 }
153
154 /**
155 * @return string
156 */
157 public function getFormat()
158 {
159 return $this->format;
160 }
161
162 /**
163 * @param string $value
164 * @return NumberFormat
165 */
166 public function setFormat($value)
167 {
168 $this->hasFormat = true;
169 $this->format = $value;
170
171 return $this;
172 }
173
174 /**
175 * @return string[]
176 */
177 public function leadingDigitPatterns()
178 {
179 return $this->leadingDigitsPattern;
180 }
181
182 /**
183 * @return int
184 */
185 public function leadingDigitsPatternSize()
186 {
187 return count($this->leadingDigitsPattern);
188 }
189
190 /**
191 * @param int $index
192 * @return string
193 */
194 public function getLeadingDigitsPattern($index)
195 {
196 return $this->leadingDigitsPattern[$index];
197 }
198
199 /**
200 * @param string $value
201 * @return NumberFormat
202 */
203 public function addLeadingDigitsPattern($value)
204 {
205 $this->leadingDigitsPattern[] = $value;
206
207 return $this;
208 }
209
210 /**
211 * @return boolean
212 */
213 public function hasNationalPrefixFormattingRule()
214 {
215 return $this->hasNationalPrefixFormattingRule;
216 }
217
218 /**
219 * @return string
220 */
221 public function getNationalPrefixFormattingRule()
222 {
223 return $this->nationalPrefixFormattingRule;
224 }
225
226 /**
227 * @param string $value
228 * @return NumberFormat
229 */
230 public function setNationalPrefixFormattingRule($value)
231 {
232 $this->hasNationalPrefixFormattingRule = true;
233 $this->nationalPrefixFormattingRule = $value;
234
235 return $this;
236 }
237
238 /**
239 * @return NumberFormat
240 */
241 public function clearNationalPrefixFormattingRule()
242 {
243 $this->nationalPrefixFormattingRule = null;
244
245 return $this;
246 }
247
248 /**
249 * @return boolean
250 */
251 public function hasDomesticCarrierCodeFormattingRule()
252 {
253 return $this->hasDomesticCarrierCodeFormattingRule;
254 }
255
256 /**
257 * @return string
258 */
259 public function getDomesticCarrierCodeFormattingRule()
260 {
261 return $this->domesticCarrierCodeFormattingRule;
262 }
263
264 /**
265 * @param string $value
266 * @return NumberFormat
267 */
268 public function setDomesticCarrierCodeFormattingRule($value)
269 {
270 $this->hasDomesticCarrierCodeFormattingRule = true;
271 $this->domesticCarrierCodeFormattingRule = $value;
272
273 return $this;
274 }
275
276 /**
277 * @param NumberFormat $other
278 * @return NumberFormat
279 */
280 public function mergeFrom(NumberFormat $other)
281 {
282 if ($other->hasPattern()) {
283 $this->setPattern($other->getPattern());
284 }
285 if ($other->hasFormat()) {
286 $this->setFormat($other->getFormat());
287 }
288 $leadingDigitsPatternSize = $other->leadingDigitsPatternSize();
289 for ($i = 0; $i < $leadingDigitsPatternSize; $i++) {
290 $this->addLeadingDigitsPattern($other->getLeadingDigitsPattern($i));
291 }
292 if ($other->hasNationalPrefixFormattingRule()) {
293 $this->setNationalPrefixFormattingRule($other->getNationalPrefixFormattingRule());
294 }
295 if ($other->hasDomesticCarrierCodeFormattingRule()) {
296 $this->setDomesticCarrierCodeFormattingRule($other->getDomesticCarrierCodeFormattingRule());
297 }
298 if ($other->hasNationalPrefixOptionalWhenFormatting()) {
299 $this->setNationalPrefixOptionalWhenFormatting($other->getNationalPrefixOptionalWhenFormatting());
300 }
301
302 return $this;
303 }
304
305 /**
306 * @return array
307 */
308 public function toArray()
309 {
310 $output = array();
311 $output['pattern'] = $this->getPattern();
312 $output['format'] = $this->getFormat();
313
314 $output['leadingDigitsPatterns'] = $this->leadingDigitPatterns();
315
316 if ($this->hasNationalPrefixFormattingRule()) {
317 $output['nationalPrefixFormattingRule'] = $this->getNationalPrefixFormattingRule();
318 }
319
320 if ($this->hasDomesticCarrierCodeFormattingRule()) {
321 $output['domesticCarrierCodeFormattingRule'] = $this->getDomesticCarrierCodeFormattingRule();
322 }
323
324 if ($this->hasNationalPrefixOptionalWhenFormatting()) {
325 $output['nationalPrefixOptionalWhenFormatting'] = $this->getNationalPrefixOptionalWhenFormatting();
326 }
327
328 return $output;
329 }
330
331 /**
332 * @param array $input
333 */
334 public function fromArray(array $input)
335 {
336 $this->setPattern($input['pattern']);
337 $this->setFormat($input['format']);
338 foreach ($input['leadingDigitsPatterns'] as $leadingDigitsPattern) {
339 $this->addLeadingDigitsPattern($leadingDigitsPattern);
340 }
341
342 if (isset($input['nationalPrefixFormattingRule']) && $input['nationalPrefixFormattingRule'] !== '') {
343 $this->setNationalPrefixFormattingRule($input['nationalPrefixFormattingRule']);
344 }
345 if (isset($input['domesticCarrierCodeFormattingRule']) && $input['domesticCarrierCodeFormattingRule'] !== '') {
346 $this->setDomesticCarrierCodeFormattingRule($input['domesticCarrierCodeFormattingRule']);
347 }
348
349 if (isset($input['nationalPrefixOptionalWhenFormatting'])) {
350 $this->setNationalPrefixOptionalWhenFormatting($input['nationalPrefixOptionalWhenFormatting']);
351 }
352 }
353 }
354