Jacek Kowalski
2023-11-17 1e5643c19c32a84234a3e8fa00c3ca50511d54cc
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) {
729413 20         $id = intval($id, 10);
bcd661 21         return $this->typesByNumber[$id] ?? [
729413 22             'num' => '??' . str_pad($id, 3, '0', STR_PAD_LEFT),
bcd661 23             'type' => '?',
JK 24             'low' => NULL,
25         ];
26     }
27 }