1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Db; |
4: | |
5: | use Salient\Core\AbstractReflectiveEnumeration; |
6: | use LogicException; |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | final class DbDriver extends AbstractReflectiveEnumeration |
14: | { |
15: | |
16: | |
17: | |
18: | public const DB2 = 0; |
19: | |
20: | |
21: | |
22: | |
23: | public const MSSQL = 1; |
24: | |
25: | |
26: | |
27: | |
28: | public const MYSQL = 2; |
29: | |
30: | |
31: | |
32: | |
33: | public const SQLITE = 3; |
34: | |
35: | |
36: | |
37: | |
38: | private static $AdodbDriverMap = [ |
39: | self::DB2 => 'db2', |
40: | self::MSSQL => 'mssqlnative', |
41: | self::MYSQL => 'mysqli', |
42: | self::SQLITE => 'sqlite3', |
43: | ]; |
44: | |
45: | |
46: | |
47: | |
48: | |
49: | |
50: | public static function toAdodbDriver(int $driver): string |
51: | { |
52: | if (($adodbDriver = self::$AdodbDriverMap[$driver] ?? null) === null) { |
53: | throw new LogicException( |
54: | sprintf('Argument #1 ($driver) is invalid: %d', $driver) |
55: | ); |
56: | } |
57: | |
58: | return $adodbDriver; |
59: | } |
60: | } |
61: | |