1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PBurggraf\LicensePlate\Detector; |
4
|
|
|
|
5
|
|
|
use PBurggraf\LicensePlate\Response\LicensePlateResponse; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @author Philip Burggraf <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
class NetherlandsDetector extends AbstractDetector |
11
|
|
|
{ |
12
|
|
|
const PLATE_SIDECODE_1 = 1; |
13
|
|
|
const PLATE_SIDECODE_2 = 2; |
14
|
|
|
const PLATE_SIDECODE_3 = 3; |
15
|
|
|
const PLATE_SIDECODE_4 = 4; |
16
|
|
|
const PLATE_SIDECODE_5 = 5; |
17
|
|
|
const PLATE_SIDECODE_6 = 6; |
18
|
|
|
const PLATE_SIDECODE_7 = 7; |
19
|
|
|
const PLATE_SIDECODE_8 = 8; |
20
|
|
|
const PLATE_SIDECODE_9 = 9; |
21
|
|
|
const PLATE_SIDECODE_10 = 10; |
22
|
|
|
const PLATE_SIDECODE_11 = 11; |
23
|
|
|
const PLATE_SIDECODE_12 = 12; |
24
|
|
|
const PLATE_SIDECODE_13 = 13; |
25
|
|
|
const PLATE_SIDECODE_14 = 14; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return LicensePlateResponse |
29
|
|
|
*/ |
30
|
|
|
public function parse() |
31
|
|
|
{ |
32
|
|
|
$sidecodes = [ |
33
|
|
|
self::PLATE_SIDECODE_1 => '/^[A-Z]{2} \d{2} \d{2}$/', |
34
|
|
|
self::PLATE_SIDECODE_2 => '/^\d{2} \d{2} [A-Z]{2}$/', |
35
|
|
|
self::PLATE_SIDECODE_3 => '/^\d{2} [A-Z]{2} \d{2}$/', |
36
|
|
|
self::PLATE_SIDECODE_4 => '/^[A-Z]{2} \d{2} [A-Z]{2}$/', |
37
|
|
|
self::PLATE_SIDECODE_5 => '/^[A-Z]{2} [A-Z]{2} \d{2}$/', |
38
|
|
|
self::PLATE_SIDECODE_6 => '/^\d{2} [A-Z]{2} [A-Z]{2}$/', |
39
|
|
|
self::PLATE_SIDECODE_7 => '/^\d{2} [A-Z]{3} \d$/', |
40
|
|
|
self::PLATE_SIDECODE_8 => '/^\d [A-Z]{3} \d{2}$/', |
41
|
|
|
self::PLATE_SIDECODE_9 => '/^[A-Z]{2} \d{3} [A-Z]$/', |
42
|
|
|
self::PLATE_SIDECODE_10 => '/^[A-Z] \d{3} [A-Z]{2}$/', |
43
|
|
|
self::PLATE_SIDECODE_11 => '/^[A-Z]{3} \d{2} [A-Z]$/', |
44
|
|
|
self::PLATE_SIDECODE_12 => '/^[A-Z] \d{2} [A-Z]{3}$/', |
45
|
|
|
self::PLATE_SIDECODE_13 => '/^\d [A-Z]{2} \d{3}$/', |
46
|
|
|
self::PLATE_SIDECODE_14 => '/^\d{3} [A-Z]{2} \d$/', |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
foreach ($sidecodes as $sidecode => $regex) { |
50
|
|
|
$this->checkSidecode($regex, $sidecode); |
51
|
|
|
|
52
|
|
|
if ($this->response->isValid()) { |
53
|
|
|
return $this->response; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $this->response; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param $regex |
62
|
|
|
* @param $resultSidecode |
63
|
|
|
* |
64
|
|
|
* @return LicensePlateResponse |
65
|
|
|
*/ |
66
|
|
|
public function checkSidecode($regex, $resultSidecode) |
67
|
|
|
{ |
68
|
|
|
if (preg_match($regex, $this->normalizedLicensePlate) === 1) { |
69
|
|
|
$this->response->setValid(true); |
70
|
|
|
$this->response->setType($resultSidecode); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $this->response; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|