blob: 93671aff636dd11dad0de4bf6399db5ea39ff524 (
plain)
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
|
# Vehicle license library for mainland China
The library implements the [GA 36-2018], which helps you validate the vehicle
registration number issued in mainland China and extract the information
from the plate number.
## Install
The package can be installed through Composer and requires PHP 8.4+
```bash
composer require lizhineng/vehicle-license-china
```
## Usage
You can easily create an instance of a registration number with the `make`
factory method. All validation will be checked against the plate number
before initialization; otherwise, a _RegistrationNumberException_ will be
thrown.
```php
use Zhineng\VehicleLicenseChina\RegistrationNumber;
use Zhineng\VehicleLicenseChina\RegistrationNumberException;
try {
$registrationNumber = RegistrationNumber::make('粤E12345');
} catch (RegistrationNumberException $e) {
// The registration number is invalid.
}
```
The library supports all vehicle types defined in the standard: embassy,
consulate, police, coach, trailer, Hong Kong, Macau, test, and special
vehicles.
```php
$registrationNumber->isEmbassy();
$registrationNumber->isConsulate();
$registrationNumber->isPolice();
$registrationNumber->isCoach();
$registrationNumber->isTrailer();
$registrationNumber->isFromHongKong();
$registrationNumber->isFromMacau();
$registrationNumber->isTest();
$registrationNumber->isSpecial();
```
To differentiate clean energy vehicles, note that these plate numbers apply
only to those without any suffix.
```php
$registrationNumber->isCleanEnergy();
// Check if it's a small clean energy vehicle
$registrationNumber->isSmallCleanEnergy();
// Check if it's a large clean energy vehicle
$registrationNumber->isLargeCleanEnergy();
```
You can further specify if a clean energy vehicle is entirely powered by
electricity.
```php
$registrationNumber->isBatteryElectric();
```
## License
The library is released under [the MIT license].
[GA 36-2018]: https://std.samr.gov.cn/hb/search/stdHBDetailed?id=8B1827F150C5BB19E05397BE0A0AB44A
[the MIT license]: LICENSE.md
|