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
  | <?php 
 |  abstract class VehicleTypes { 
 |      protected $typesByNumber = []; 
 |       
 |      protected function __construct($data, $defaultLow=NULL) { 
 |          $data = explode("\n", trim($data)); 
 |          foreach($data as $line) { 
 |              $line = explode("\t", trim($line)); 
 |              for($i = (int)$line[0]; $i <= (int)$line[1]; $i++) { 
 |                  $this->typesByNumber[$i] = [ 
 |                      'num' => $line[2] . str_pad($i, 3, '0', STR_PAD_LEFT), 
 |                      'type' => $line[3], 
 |                      'low' => (int)(isset($line[4]) ? $line[4] : $defaultLow), 
 |                  ]; 
 |              } 
 |          } 
 |      } 
 |       
 |      public function getByNumber($id) { 
 |          return $this->typesByNumber[$id] ?? [ 
 |              'num' => '??'.$id, 
 |              'type' => '?', 
 |              'low' => NULL, 
 |          ]; 
 |      } 
 |  } 
 |  
  |