1 | <?php |
||
17 | class DiscoEnum |
||
|
|||
18 | { |
||
19 | private static $cache = []; |
||
20 | private static $discos = [ |
||
21 | 'ekedc' => ['code' => '01', 'name' => 'Eko Electric - EKEDC'], |
||
22 | 'ikedc' => ['code' => '02', 'name' => 'Ikeja Electric - IKEDC'], |
||
23 | 'aedc' => ['code' => '03', 'name' => 'Abuja Electric - AEDC'], |
||
24 | 'kedc' => ['code' => '04', 'name' => 'Kano Electric - KEDC'], |
||
25 | 'phedc' => ['code' => '05', 'name' => 'Porthacourt Electric - PHEDC'], |
||
26 | 'jedc' => ['code' => '06', 'name' => 'Jos Electric - JEDC'], |
||
27 | 'ibedc' => ['code' => '07', 'name' => 'Ibadan Electric - IBEDC'], |
||
28 | 'kaedc' => ['code' => '08', 'name' => 'Kaduna Elecdtric - KAEDC'], |
||
29 | 'eedc' => ['code' => '09', 'name' => 'Enugu Electric - EEDC'], |
||
30 | ]; |
||
31 | |||
32 | private $disco; |
||
33 | private $uid; |
||
34 | |||
35 | private function __construct(string $uid, array $disco) |
||
40 | |||
41 | public function getUID(): string |
||
45 | |||
46 | public function getCode(): string |
||
50 | |||
51 | public function getName(): string |
||
55 | |||
56 | public function toArray(): array |
||
64 | |||
65 | /** |
||
66 | * @param $uid |
||
67 | * @return DiscoEnum|null |
||
68 | * @throws ClubKonnectErrorException |
||
69 | */ |
||
70 | public static function getByUID($uid): ?DiscoEnum |
||
71 | { |
||
72 | $uid = trim("$uid"); |
||
73 | if (!key_exists($uid, self::$discos)) |
||
74 | throw new ClubKonnectErrorException("Not a valid ClubKonnect Disco", 999); |
||
75 | if (!key_exists($uid, self::$cache)) |
||
76 | self::$cache[$uid] = new DiscoEnum($uid, self::$discos[$uid]); |
||
77 | return self::$cache[$uid]; |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param $code |
||
82 | * @return DiscoEnum|null |
||
83 | * @throws ClubKonnectErrorException |
||
84 | */ |
||
85 | public static function getByCode($code): ?DiscoEnum |
||
86 | { |
||
87 | $code = trim($code); |
||
88 | if (!key_exists($code, self::$cache)) { |
||
89 | $found = false; |
||
90 | foreach (self::$discos as $idx => $disco) { |
||
91 | if ($disco['code'] == $code) { |
||
92 | self::$cache[$code] = new DiscoEnum($idx, $disco); |
||
93 | $found = true; |
||
94 | } |
||
95 | } |
||
96 | if (!$found) { |
||
97 | throw new ClubKonnectErrorException("Not a valid ClubKonnect Disco", 999); |
||
98 | } |
||
99 | } |
||
100 | return self::$cache[$code]; |
||
101 | } |
||
102 | |||
103 | public function __toString(): string |
||
107 | } |
||
108 |