commit | author | age
|
bcd661
|
1 |
<?php |
JK |
2 |
abstract class VehicleTypes { |
|
3 |
protected $typesByNumber = []; |
|
4 |
|
|
5 |
protected function __construct($data, $defaultLow=NULL) { |
|
6 |
$data = explode("\n", trim($data)); |
|
7 |
foreach($data as $line) { |
|
8 |
$line = explode("\t", trim($line)); |
|
9 |
for($i = (int)$line[0]; $i <= (int)$line[1]; $i++) { |
|
10 |
$this->typesByNumber[$i] = [ |
|
11 |
'num' => $line[2] . str_pad($i, 3, '0', STR_PAD_LEFT), |
|
12 |
'type' => $line[3], |
|
13 |
'low' => (int)(isset($line[4]) ? $line[4] : $defaultLow), |
|
14 |
]; |
|
15 |
} |
|
16 |
} |
|
17 |
} |
|
18 |
|
|
19 |
public function getByNumber($id) { |
|
20 |
return $this->typesByNumber[$id] ?? [ |
|
21 |
'num' => '??'.$id, |
|
22 |
'type' => '?', |
|
23 |
'low' => NULL, |
|
24 |
]; |
|
25 |
} |
|
26 |
} |