LicensePlate.php
18.9 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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
<?php
namespace Faker\Provider\pl_PL;
use Faker\Provider\Base;
/**
* Generator of Polish vehicle registration numbers.
* {@link} https://isap.sejm.gov.pl/isap.nsf/DocDetails.xsp?id=WDU20220001847
* {@link} https://pl.wikipedia.org/wiki/Tablice_rejestracyjne_w_Polsce#Tablice_standardowe
*/
class LicensePlate extends Base
{
/**
* @var array list of Polish voivodeships and respective vehicle registration number prefixes.
*/
protected static $voivodeships = [
'dolnośląskie' => ['D', 'V'],
'kujawsko-pomorskie' => ['C'],
'lubelskie' => ['L'],
'lubuskie' => ['F'],
'łódzkie' => ['E'],
'małopolskie' => ['K', 'J'],
'mazowieckie' => ['W', 'A'],
'opolskie' => ['O'],
'podkarpackie' => ['R', 'Y'],
'podlaskie' => ['B'],
'pomorskie' => ['G', 'X'],
'śląskie' => ['S', 'I'],
'świętokrzyskie' => ['T'],
'warmińsko-mazurskie' => ['N'],
'wielkopolskie' => ['P', 'M'],
'zachodniopomorskie' => ['Z'],
];
/**
* @var array list of special vehicle registration number prefixes.
*/
protected static $specials = [
'army' => ['U'],
'services' => ['H'],
];
/**
* @var array list of Polish counties and respective vehicle registration number prefixes.
*/
protected static $counties = [
'dolnośląskie' => [
'Jelenia Góra' => ['J'],
'Legnica' => ['L'],
'Wałbrzych' => ['B'],
'Wrocław' => ['W', 'X'],
'bolesławiecki' => ['BL'],
'dzierżoniowski' => ['DZ'],
'głogowski' => ['GL'],
'górowski' => ['GR'],
'jaworski' => ['JA'],
'jeleniogórski' => ['JE'],
'kamiennogórski' => ['KA'],
'kłodzki' => ['KL'],
'legnicki' => ['LE'],
'lubański' => ['LB'],
'lubiński' => ['LU'],
'lwówecki' => ['LW'],
'milicki' => ['MI'],
'oleśnicki' => ['OL'],
'oławski' => ['OA'],
'polkowicki' => ['PL'],
'strzeliński' => ['ST'],
'średzki' => ['SR'],
'świdnicki' => ['SW'],
'trzebnicki' => ['TR'],
'wałbrzyski' => ['BA'],
'wołowski' => ['WL'],
'wrocławski' => ['WR'],
'ząbkowicki' => ['ZA'],
'zgorzelecki' => ['ZG'],
'złotoryjski' => ['ZL'],
],
'kujawsko-pomorskie' => [
'Bydgoszcz' => ['B'],
'Grudziądz' => ['G'],
'Toruń' => ['T'],
'Włocławek' => ['W'],
'aleksandrowski' => ['AL'],
'brodnicki' => ['BR'],
'bydgoski' => ['BY'],
'chełmiński' => ['CH'],
'golubsko-dobrzyński' => ['GD'],
'grudziądzki' => ['GR'],
'inowrocławski' => ['IN'],
'lipnowski' => ['LI'],
'mogileński' => ['MG'],
'nakielski' => ['NA'],
'radziejowski' => ['RA'],
'rypiński' => ['RY'],
'sępoleński' => ['SE'],
'świecki' => ['SW'],
'toruński' => ['TR'],
'tucholski' => ['TU'],
'wąbrzeski' => ['WA'],
'włocławski' => ['WL'],
'żniński' => ['ZN'],
],
'lubelskie' => [
'Biała Podlaska' => ['B'],
'Chełm' => ['C'],
'Lublin' => ['U'],
'Zamość' => ['Z'],
'bialski' => ['BI'],
'biłgorajski' => ['BL'],
'chełmski' => ['CH'],
'hrubieszowski' => ['HR'],
'janowski' => ['JA'],
'krasnostawski' => ['KS'],
'kraśnicki' => ['KR'],
'lubartowski' => ['LB'],
'lubelski' => ['UB'],
'łęczyński' => ['LE'],
'łukowski' => ['LU'],
'opolski' => ['OP'],
'parczewski' => ['PA'],
'puławski' => ['PU'],
'radzyński' => ['RA'],
'rycki' => ['RY'],
'świdnicki' => ['SW'],
'tomaszowski' => ['TM'],
'włodawski' => ['WL'],
'zamojski' => ['ZA'],
],
'lubuskie' => [
'Gorzów Wielkopolski' => ['G'],
'Zielona Góra' => ['Z'],
'gorzowski' => ['GW'],
'krośnieński' => ['KR'],
'międzyrzecki' => ['MI'],
'nowosolski' => ['NW'],
'słubicki' => ['SL'],
'strzelecko-drezdenecki' => ['SD'],
'sulęciński' => ['SU'],
'świebodziński' => ['SW'],
'wschowski' => ['WS'],
'zielonogórski' => ['ZI'],
'żagański' => ['ZG'],
'żarski' => ['ZA'],
],
'łódzkie' => [
'Łódź' => ['L', 'D'],
'Piotrków Trybunalski' => ['P'],
'Skierniewice' => ['S'],
'brzeziński' => ['BR'],
'bełchatowski' => ['BE'],
'kutnowski' => ['KU'],
'łaski' => ['LA'],
'łęczycki' => ['LE'],
'łowicki' => ['LC'],
'łódzki wschodni' => ['LW'],
'opoczyński' => ['OP'],
'pabianicki' => ['PA'],
'pajęczański' => ['PJ'],
'piotrkowski' => ['PI'],
'poddębicki' => ['PD'],
'radomszczański' => ['RA'],
'rawski' => ['RW'],
'sieradzki' => ['SI'],
'skierniewicki' => ['SK'],
'tomaszowski' => ['TM'],
'wieluński' => ['WI'],
'wieruszowski' => ['WE'],
'zduńskowolski' => ['ZD'],
'zgierski' => ['ZG'],
],
'małopolskie' => [
'Kraków' => ['R', 'K'],
'Nowy Sącz' => ['N'],
'Tarnów' => ['T'],
'bocheński' => ['BA', 'BC'],
'brzeski' => ['BR'],
'chrzanowski' => ['CH'],
'dąbrowski' => ['DA'],
'gorlicki' => ['GR'],
'krakowski' => ['RA', 'RK'],
'limanowski' => ['LI'],
'miechowski' => ['MI'],
'myślenicki' => ['MY'],
'nowosądecki' => ['NS'],
'nowotarski' => ['NT'],
'olkuski' => ['OL'],
'oświęcimski' => ['OS'],
'proszowicki' => ['PR'],
'suski' => ['SU'],
'tarnowski' => ['TA'],
'tatrzański' => ['TT'],
'wadowicki' => ['WA'],
'wielicki' => ['WI'],
],
'mazowieckie' => [
'Ostrołęka' => ['O'],
'Płock' => ['P'],
'Radom' => ['R'],
'Siedlce' => ['S'],
'białobrzeski' => ['BR'],
'ciechanowski' => ['CI'],
'garwoliński' => ['G'],
'gostyniński' => ['GS'],
'grodziski' => ['GM'],
'grójecki' => ['GR'],
'kozienicki' => ['KZ'],
'legionowski' => ['L'],
'lipski' => ['LI'],
'łosicki' => ['LS'],
'makowski' => ['MA'],
'miński' => ['M'],
'mławski' => ['ML'],
'nowodworski' => ['ND'],
'ostrołęcki' => ['OS'],
'ostrowski' => ['OR'],
'otwocki' => ['OT'],
'piaseczyński' => ['PA', 'PI', 'PW', 'PX'],
'płocki' => ['PL'],
'płoński' => ['PN'],
'pruszkowski' => ['PP', 'PR', 'PS'],
'przasnyski' => ['PZ'],
'przysuski' => ['PY'],
'pułtuski' => ['PU'],
'radomski' => ['RA'],
'siedlecki' => ['SI'],
'sierpecki' => ['SE'],
'sochaczewski' => ['SC'],
'sokołowski' => ['SK'],
'szydłowiecki' => ['SZ'],
'warszawski' => ['A', 'B', 'D', 'E', 'F', 'H', 'I', 'J', 'K', 'N', 'T', 'U', 'W', 'X', 'Y'],
'warszawski zachodni' => ['Z'],
'węgrowski' => ['WE'],
'wołomiński' => ['WL', 'V'],
'wyszkowski' => ['WY'],
'zwoleński' => ['ZW'],
'żuromiński' => ['ZU'],
'żyrardowski' => ['ZY'],
],
'opolskie' => [
'Opole' => ['P'],
'brzeski' => ['B'],
'głubczycki' => ['GL'],
'kędzierzyńsko-kozielski' => ['K'],
'kluczborski' => ['KL'],
'krapkowicki' => ['KR'],
'namysłowski' => ['NA'],
'nyski' => ['NY'],
'oleski' => ['OL'],
'opolski' => ['PO'],
'prudnicki' => ['PR'],
'strzelecki' => ['ST'],
],
'podkarpackie' => [
'Krosno' => ['K'],
'Przemyśl' => ['P'],
'Rzeszów' => ['Z'],
'Tarnobrzeg' => ['T'],
'bieszczadzki' => ['BI'],
'brzozowski' => ['BR'],
'dębicki' => ['DE'],
'jarosławski' => ['JA'],
'jasielski' => ['JS'],
'kolbuszowski' => ['KL'],
'krośnieński' => ['KR'],
'leski' => ['LS'],
'leżajski' => ['LE'],
'lubaczowski' => ['LU'],
'łańcucki' => ['LA'],
'mielecki' => ['MI'],
'niżański' => ['NI'],
'przemyski' => ['PR'],
'przeworski' => ['PZ'],
'ropczycko-sędziszowski' => ['RS'],
'rzeszowski' => ['ZE', 'ZR', 'ZZ'],
'sanocki' => ['SA'],
'stalowowolski' => ['ST'],
'strzyżowski' => ['SR'],
'tarnobrzeski' => ['TA'],
],
'podlaskie' => [
'Białystok' => ['I'],
'Łomża' => ['L'],
'Suwałki' => ['S'],
'augustowski' => ['AU'],
'białostocki' => ['IA', 'IB'],
'bielski' => ['BI'],
'grajewski' => ['GR'],
'hajnowski' => ['HA'],
'kolneński' => ['KL'],
'łomżyński' => ['LM'],
'moniecki' => ['MN'],
'sejneński' => ['SE'],
'siemiatycki' => ['SI'],
'sokólski' => ['SK'],
'suwalski' => ['SU'],
'wysokomazowiecki' => ['WM'],
'zambrowski' => ['ZA'],
],
'pomorskie' => [
'Gdańsk' => ['D'],
'Gdynia' => ['A'],
'Słupsk' => ['S'],
'Sopot' => ['SP'],
'bytowski' => ['BY'],
'chojnicki' => ['CH'],
'człuchowski' => ['CZ'],
'gdański' => ['DA'],
'kartuski' => ['KA', 'KY', 'KZ'],
'kościerski' => ['KS'],
'kwidzyński' => ['KW'],
'lęborski' => ['LE'],
'malborski' => ['MB'],
'nowodworski' => ['ND'],
'pucki' => ['PU'],
'słupski' => ['SL'],
'starogardzki' => ['ST'],
'sztumski' => ['SZ'],
'tczewski' => ['TC'],
'wejherowski' => ['WE', 'WO'],
],
'śląskie' => [
'Bielsko-Biała' => ['B'],
'Bytom' => ['Y'],
'Chorzów' => ['H'],
'Częstochowa' => ['C'],
'Dąbrowa Górnicza' => ['D'],
'Gliwice' => ['G'],
'Jastrzębie-Zdrój' => ['JZ'],
'Jaworzno' => ['J'],
'Katowice' => ['K'],
'Mysłowice' => ['M'],
'Piekary Śląskie' => ['PI'],
'Ruda Śląska,' => ['L', 'RS'],
'Rybnik' => ['R'],
'Siemianowice Śląskie' => ['I'],
'Sosnowiec' => ['O'],
'Świętochłowice' => ['W'],
'Tychy' => ['T'],
'Zabrze' => ['Z'],
'Żory' => ['ZO'],
'będziński' => ['BE', 'BN', 'E'],
'bielski' => ['BI'],
'cieszyński' => ['CI', 'CN'],
'częstochowski' => ['CZ'],
'gliwicki' => ['GL'],
'kłobucki' => ['KL'],
'lubliniecki' => ['LU'],
'mikołowski' => ['MI'],
'myszkowski' => ['MY'],
'pszczyński' => ['PS'],
'raciborski' => ['RC'],
'rybnicki' => ['RB'],
'tarnogórski' => ['TA'],
'bieruńsko - lędziński' => ['BL'],
'wodzisławski' => ['WD', 'WZ'],
'zawierciański' => ['ZA'],
'żywiecki' => ['ZY'],
],
'świętokrzyskie' => [
'Kielce' => ['K'],
'buski' => ['BU'],
'jędrzejowski' => ['JE'],
'kazimierski' => ['KA'],
'kielecki' => ['KI'],
'konecki' => ['KN'],
'opatowski' => ['OP'],
'ostrowiecki' => ['OS'],
'pińczowski' => ['PI'],
'sandomierski' => ['SA'],
'skarżyski' => ['SK'],
'starachowicki' => ['ST'],
'staszowski' => ['SZ'],
'włoszczowski' => ['LW'],
],
'warmińsko-mazurskie' => [
'Elbląg' => ['E'],
'Olsztyn' => ['O'],
'bartoszycki' => ['BA'],
'braniewski' => ['BR'],
'działdowski' => ['DZ'],
'elbląski' => ['EB'],
'ełcki' => ['EL'],
'giżycki' => ['GI'],
'iławski' => ['IL'],
'kętrzyński' => ['KE'],
'lidzbarski' => ['LI'],
'mrągowski' => ['MR'],
'nidzicki' => ['NI'],
'nowomiejski' => ['NM'],
'olecki' => ['OE'],
'gołdapski' => ['GO'],
'olsztyński' => ['OL'],
'ostródzki' => ['OS'],
'piski' => ['PI'],
'szczycieński' => ['SZ'],
'węgorzewski' => ['WE'],
],
'wielkopolskie' => [
'Kalisz' => ['A', 'K'],
'Konin' => ['KO', 'N'],
'Leszno' => ['L'],
'Poznań' => ['O', 'Y'],
'chodzieski' => ['CH'],
'czarnkowsko-trzcianecki' => ['CT'],
'gnieźnieński' => ['GN'],
'gostyński' => ['GS'],
'grodziski' => ['GO'],
'jarociński' => ['JA'],
'kaliski' => ['KA'],
'kępiński' => ['KE'],
'kolski' => ['KL'],
'koniński' => ['KN'],
'kościański' => ['KS'],
'krotoszyński' => ['KR'],
'leszczyński' => ['LE'],
'międzychodzki' => ['MI'],
'nowotomyski' => ['NT'],
'obornicki' => ['OB'],
'ostrowski' => ['OS'],
'ostrzeszowski' => ['OT'],
'pilski' => ['P'],
'pleszewski' => ['PL'],
'poznański' => ['OZ', 'Z'],
'rawicki' => ['RA'],
'słupecki' => ['SL'],
'szamotulski' => ['SZ'],
'średzki' => ['SR'],
'śremski' => ['SE'],
'turecki' => ['TU'],
'wągrowiecki' => ['WA'],
'wolsztyński' => ['WL'],
'wrzesiński' => ['WR'],
'złotowski' => ['ZL'],
],
'zachodniopomorskie' => [
'Koszalin' => ['K'],
'Szczecin' => ['S', 'Z'],
'Świnoujście' => ['SW'],
'białogardzki' => ['BI'],
'choszczeński' => ['CH'],
'drawski' => ['DR'],
'goleniowski' => ['GL'],
'gryficki' => ['GY'],
'gryfiński' => ['GR'],
'kamieński' => ['KA'],
'kołobrzeski' => ['KL'],
'koszaliński' => ['KO'],
'łobeski' => ['LO'],
'myśliborski' => ['MY'],
'policki' => ['PL'],
'pyrzycki' => ['PY'],
'sławieński' => ['SL'],
'stargardzki' => ['ST'],
'szczecinecki' => ['SZ'],
'świdwiński' => ['SD'],
'wałecki' => ['WA'],
],
'army' => [
'Siły Zbrojne Rzeczypospolitej Polskiej' => ['A', 'B', 'C', 'D', 'E', 'G', 'I', 'J', 'K', 'L'],
],
'services' => [
'Centralne Biuro Antykorupcyjne' => ['A'],
'Służba Ochrony Państwa' => ['BA', 'BB', 'BE', 'BF', 'BG'],
'Służba Celno-Skarbowa' => ['CA', 'CB', 'CC', 'CD', 'CE', 'CF', 'CG', 'CH', 'CJ', 'CK', 'CL', 'CM', 'CN', 'CO', 'CP', 'CR'],
'Agencja Bezpieczeństwa Wewnętrznego' => ['K'],
'Agencja Wywiadu' => ['K'],
'Służba Kontrwywiadu Wojskowego' => ['M'],
'Służba Wywiadu Wojskowego' => ['M'],
'Policja' => ['PA', 'PB', 'PC', 'PD', 'PE', 'PF', 'PG', 'PH', 'PJ', 'PK', 'PL', 'PL', 'PL', 'PL', 'PL', 'PM', 'PN', 'PP', 'PS', 'PT', 'PU', 'PW', 'PZ'],
'Straż Graniczna' => ['WA', 'WK'],
],
];
/**
* @var array list of regex expressions matching Polish license plate suffixess when county code is 1 character long.
*/
protected static $plateSuffixesGroup1 = [
'\d{5}',
'\d{4}[A-PR-Z]',
'\d{3}[A-PR-Z]{2}',
'[1-9][A-PR-Z]\d{3}',
'[1-9][A-PR-Z]{2}\d{2}',
];
/**
* @var array list of regex expressions matching Polish license plate suffixess when county code is 2 characters long.
*/
protected static $plateSuffixesGroup2 = [
'[A-PR-Z]\d{3}',
'\d{2}[A-PR-Z]{2}',
'[1-9][A-PR-Z]\d{2}',
'\d{2}[A-PR-Z][1-9]',
'[1-9][A-PR-Z]{2}[1-9]',
'[A-PR-Z]{2}\d{2}',
'\d{5}',
'\d{4}[A-PR-Z]',
'\d{3}[A-PR-Z]{2}',
'[A-PR-Z]\d{2}[A-PR-Z]',
'[A-PR-Z][1-9][A-PR-Z]{2}',
];
/**
* Generates random license plate.
*
* @param bool $special whether special license plates should be included
* @param array|null $voivodeships list of voivodeships license plate should be generated from
* @param array|null $counties list of counties license plate should be generated from
*/
public static function licensePlate(
bool $special = false,
?array $voivodeships = null,
?array $counties = null
): string {
$voivodeshipsAvailable = static::$voivodeships + ($special ? static::$specials : []);
$voivodeshipSelected = static::selectRandomArea($voivodeshipsAvailable, $voivodeships);
$voivodeshipCode = static::randomElement($voivodeshipsAvailable[$voivodeshipSelected]);
$countiesAvailable = static::$counties[$voivodeshipSelected];
$countySelected = self::selectRandomArea($countiesAvailable, $counties);
$countyCode = static::randomElement(static::$counties[$voivodeshipSelected][$countySelected]);
$suffix = static::regexify(static::randomElement(strlen($countyCode) === 1 ? static::$plateSuffixesGroup1 : static::$plateSuffixesGroup2));
return "{$voivodeshipCode}{$countyCode} {$suffix}";
}
/**
* Selects random area from the list of available and requested.
*
* @return string
*/
protected static function selectRandomArea(array $available, ?array $requested)
{
$requested = array_intersect(array_keys($available), $requested ?? []);
if (empty($requested)) {
$requested = array_keys($available);
}
return static::randomElement($requested);
}
}