1: <?php declare(strict_types=1);
2:
3: namespace Salient\Db;
4:
5: use Salient\Core\AbstractReflectiveEnumeration;
6: use LogicException;
7:
8: /**
9: * Database connection drivers
10: *
11: * @extends AbstractReflectiveEnumeration<int>
12: */
13: final class DbDriver extends AbstractReflectiveEnumeration
14: {
15: /**
16: * IBM Db2
17: */
18: public const DB2 = 0;
19:
20: /**
21: * Microsoft SQL Server
22: */
23: public const MSSQL = 1;
24:
25: /**
26: * MySQL or MariaDB
27: */
28: public const MYSQL = 2;
29:
30: /**
31: * SQLite
32: */
33: public const SQLITE = 3;
34:
35: /**
36: * @var array<DbDriver::*,string>
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: * @internal
47: *
48: * @param DbDriver::* $driver
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: