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