PhoneNumber.php
10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<?php
namespace Faker\Provider\el_GR;
/**
* @see https://en.wikipedia.org/wiki/Telephone_numbers_in_Greece
* @see https://github.com/giggsey/libphonenumber-for-php/blob/master/src/data/PhoneNumberMetadata_GR.php
*/
class PhoneNumber extends \Faker\Provider\PhoneNumber
{
protected static $internationalCallPrefixes = ['', '+30'];
protected static $formats = [
'{{fixedLineNumber}}',
'{{mobileNumber}}',
'{{personalNumber}}',
'{{tollFreeNumber}}',
'{{sharedCostNumber}}',
'{{premiumRateNumber}}',
];
protected static $areaCodes = [
// Zone 22: Central Greece and the Aegean Islands
2221, 2222, 2223, 2224, 2226, 2227, 2228, 2229,
2231, 2232, 2233, 2234, 2235, 2236, 2237, 2238,
2241, 2242, 2243, 2244, 2245, 2246, 2247,
2251, 2252, 2253, 2254,
2261, 2262, 2263, 2264, 2265, 2266, 2267, 2268,
2271, 2272, 2273, 2274, 2275,
2281, 2282, 2283, 2284, 2285, 2286, 2287, 2288, 2289,
2291, 2292, 2293, 2294, 2295, 2296, 2297, 2298, 2299,
// Zone 23: Central Macedonia and Florina
231,
2321, 2322, 2323, 2324, 2325, 2327,
2331, 2332, 2333,
2341, 2343,
2351, 2352, 2353,
2371, 2372, 2373, 2374, 2375, 2376, 2377,
2381, 2382, 2384, 2385, 2386,
2391, 2392, 2393, 2394, 2395, 2396, 2397, 2399,
// Zone 24: Thessaly and West Macedonia (excluding Florina)
241,
2421, 2422, 2423, 2424, 2425, 2426, 2427, 2428,
2431, 2432, 2433, 2434,
2441, 2443, 2444, 2445,
2461, 2462, 2463, 2464, 2465, 2467, 2468,
2491, 2492, 2493, 2494, 2495,
// Zone 25: East Macedonia and Thrace
251,
2521, 2522, 2523, 2524,
2531, 2532, 2533, 2534, 2535,
2541, 2542, 2544,
2591, 2592, 2593, 2594,
2551, 2552, 2553, 2554, 2555, 2556,
// Zone 26: West Greece, Ionian Island and Epirus
261,
2621, 2622, 2623, 2624, 2625, 2626,
2631, 2632, 2634, 2635,
2661, 2662, 2663, 2664, 2665, 2666,
2691, 2692, 2693, 2694, 2695, 2696,
2641, 2642, 2643, 2644, 2645, 2646, 2647,
2651, 2653, 2654, 2655, 2656, 2657, 2658, 2659,
2671, 2674,
2681, 2682, 2683, 2684, 2685,
// Zone 27: Peloponnese and Kythera
271,
2721, 2722, 2723, 2724, 2725,
2731, 2732, 2733, 2734, 2735, 2736,
2741, 2742, 2743, 2744, 2745, 2746, 2747,
2751, 2752, 2753, 2754, 2755, 2757,
2761, 2763, 2765,
2791, 2792, 2795, 2797,
// Zone 28: Crete
281,
2821, 2822, 2823, 2824, 2825,
2831, 2832, 2833, 2834,
2841, 2842, 2843, 2844,
2891, 2892, 2893, 2894, 2895, 2897,
];
protected static $fixedLineFormats = [
'{{internationalCodePrefix}}21########',
'{{internationalCodePrefix}} 21# ### ####',
'{{internationalCodePrefix}}{{areaCode}}######',
'{{internationalCodePrefix}} {{areaCode}} ######',
];
protected static $mobileCodes = [
685, 687, 688, 689,
690, 691, 693, 694, 695, 696, 697, 698, 699,
];
protected static $mobileFormats = [
'{{internationalCodePrefix}}{{mobileCode}}#######',
'{{internationalCodePrefix}} {{mobileCode}} ### ####',
];
protected static $personalFormats = [
'{{internationalCodePrefix}}70########',
'{{internationalCodePrefix}} 70 #### ####',
];
protected static $tollFreeFormats = [
'{{internationalCodePrefix}}800#######',
'{{internationalCodePrefix}} 800 ### ####',
];
protected static $sharedCostCodes = [801, 806, 812, 825, 850, 875];
protected static $sharedCostFormats = [
'{{internationalCodePrefix}}{{sharedCostCode}}#######',
'{{internationalCodePrefix}} {{sharedCostCode}} ### ####',
];
protected static $premiumRateCodes = [901, 909];
protected static $premiumRateFormats = [
'{{internationalCodePrefix}}{{premiumRateCode}}#######',
'{{internationalCodePrefix}} {{premiumRateCode}} ### ####',
];
/**
* Generate a country calling code prefix.
*
* @example Prefix an empty string: ''
* @example Prefix the country calling code: '+30'
*
* @internal Used to generate phone numbers with or without prefixes.
*
* @return string
*/
public static function internationalCodePrefix()
{
return static::randomElement(static::$internationalCallPrefixes);
}
/**
* Generate an area code for a fixed line number.
*
* Doesn't include codes for Greater Athens Metropolitan Area (21#) because
* this zone uses 3 digits, and phone numbers have a different formatting.
*
* Area codes in all the other zones use 4 digits.
* The capital of each zone uses 3 digits and the 4th digit can be any number.
* The other areas in each zone use 4 digits, but not every number is valid for the 4th digit.
*
* @example Thessaloniki has code '231', so '2310' and '2313' are valid.
* @example Serres has code '232', but '2326', '2328' and '2329' are not valid.
*
* @return string
*/
public static function areaCode()
{
return static::numerify(
str_pad(static::randomElement(static::$areaCodes), 4, '#'),
);
}
/**
* Generate a fixed line number.
*
* Numbers can be generated with or without the international code prefix.
* Numbers can be generated with or without spaces between their parts.
* Numbers in Athens use a 3-digit area code, and can be formatted as 21# ### ####.
* Numbers in other areas use a 4-digit area code, and can be formatted as 2### ### ###.
*
* @example A number in Athens: '2101234567'
* @example A number in Thessaloniki: '2310123456'
* @example A number with spaces in Athens: '210 123 4567'
* @example A number with spaces in Thessaloniki: '2310 123 456'
* @example A number with international code prefix: '+302101234567'
* @example A number with international code prefix and spaces: '+30 2310 123 456'
*
* @return string
*/
public function fixedLineNumber()
{
return ltrim(static::numerify($this->generator->parse(
static::randomElement(static::$fixedLineFormats),
)));
}
/**
* Generate a code for a mobile number.
*
* @internal Used to generate mobile numbers.
*
* @return string
*/
public static function mobileCode()
{
return static::randomElement(static::$mobileCodes);
}
/**
* Generate a mobile number.
*
* @example A mobile number: '6901234567'
* @example A mobile number with spaces: '690 123 4567'
* @example A mobile number with international code prefix: '+306901234567'
* @example A mobile number with international code prefix and spaces: '+30 690 123 4567'
*
* @return string
*/
public function mobileNumber()
{
return ltrim(static::numerify($this->generator->parse(
static::randomElement(static::$mobileFormats),
)));
}
/**
* @deprecated Use PhoneNumber::mobileNumber() instead.
*/
public static function mobilePhoneNumber()
{
return static::numerify(
strtr(static::randomElement(static::$mobileFormats), [
'{{internationalCodePrefix}}' => static::internationalCodePrefix(),
'{{mobileCode}}' => static::mobileCode(),
]),
);
}
/**
* Generate a personal number.
*
* @example A personal number: '7012345678'
* @example A personal number with spaces: '70 1234 5678'
* @example A personal number with international code prefix: '+307012345678'
* @example A personal number with international code prefix and spaces: '+30 70 1234 5678'
*
* @return string
*/
public function personalNumber()
{
return ltrim(static::numerify($this->generator->parse(
static::randomElement(static::$personalFormats),
)));
}
/**
* Generate a toll-free number.
*
* @example A toll-free number: '8001234567'
* @example A toll-free number with spaces: '800 123 4567'
* @example A toll-free number with international code prefix: '+308001234567'
* @example A toll-free number with international code prefix and spaces: '+30 800 123 4567'
*
* @return string
*/
public static function tollFreeNumber()
{
return ltrim(static::numerify(
strtr(static::randomElement(static::$tollFreeFormats), [
'{{internationalCodePrefix}}' => static::internationalCodePrefix(),
]),
));
}
/**
* Generate a code for a shared-cost number.
*
* @internal Used to generate shared-cost numbers.
*
* @return string
*/
public static function sharedCostCode()
{
return static::randomElement(static::$sharedCostCodes);
}
/**
* Generate a shared-cost number.
*
* @example A shared-cost number: '8011234567'
* @example A shared-cost number with spaces: '801 123 4567'
* @example A shared-cost number with international code prefix: '+308011234567'
* @example A shared-cost number with international code prefix and spaces: '+30 801 123 4567'
*
* @return string
*/
public function sharedCostNumber()
{
return ltrim(static::numerify($this->generator->parse(
static::randomElement(static::$sharedCostFormats),
)));
}
/**
* Generate a code for a premium-rate number.
*
* @internal Used to generate premium-rate numbers.
*
* @return string
*/
public static function premiumRateCode()
{
return static::randomElement(static::$premiumRateCodes);
}
/**
* Generate a premium-rate number.
*
* @example A premium-rate number: '9011234567'
* @example A premium-rate number with spaces: '901 123 4567'
* @example A premium-rate number with international code prefix: '+309011234567'
* @example A premium-rate number with international code prefix and spaces: '+30 901 123 4567'
*
* @return string
*/
public function premiumRateNumber()
{
return ltrim(static::numerify($this->generator->parse(
static::randomElement(static::$premiumRateFormats),
)));
}
}