From 0b6d2f4164b9d823fb2a49d9fb4e83242f695e09 Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Sun, 30 Jun 2019 21:59:01 +0000
Subject: [PATCH] Update README - include requirements and info on running composer
---
lib/VehicleTypes.php | 26 ++++++++++++++++++++++++++
1 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/lib/VehicleTypes.php b/lib/VehicleTypes.php
new file mode 100644
index 0000000..5d96326
--- /dev/null
+++ b/lib/VehicleTypes.php
@@ -0,0 +1,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,
+ ];
+ }
+}
--
Gitblit v1.9.1