1 | <?php |
||
13 | class Factory |
||
14 | { |
||
15 | /** |
||
16 | * @param $connectionString |
||
17 | * @param $schemesAlternative |
||
18 | * @return \ByJG\AnyDataset\DbDriverInterface |
||
19 | */ |
||
20 | 28 | public static function getDbRelationalInstance($connectionString, $schemesAlternative = null) |
|
21 | { |
||
22 | 28 | $prefix = '\\ByJG\\AnyDataset\\Store\\'; |
|
23 | |||
24 | 28 | $instance = self::getInstance( |
|
25 | 28 | $connectionString, |
|
26 | 28 | array_merge( |
|
27 | [ |
||
28 | 28 | "oci8" => $prefix . "DbOci8Driver", |
|
29 | 28 | "dblib" => $prefix . "PdoDblib", |
|
30 | 28 | "mysql" => $prefix . "PdoMysql", |
|
31 | 28 | "pgsql" => $prefix . "PdoPgsql", |
|
32 | 28 | "oci" => $prefix . "PdoOci", |
|
33 | 28 | "odbc" => $prefix . "PdoOdbc", |
|
34 | 28 | "sqlite" => $prefix . "PdoSqlite", |
|
35 | 28 | ], |
|
36 | (array)$schemesAlternative |
||
37 | 28 | ), |
|
38 | DbDriverInterface::class |
||
39 | 28 | ); |
|
40 | |||
41 | 28 | return $instance; |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * @param $connectionString |
||
46 | * @param $schemesAlternative |
||
47 | * @return NoSqlInterface |
||
48 | */ |
||
49 | public static function getNoSqlInstance($connectionString, $schemesAlternative = null) |
||
66 | |||
67 | /** |
||
68 | * @param string $connectionString |
||
69 | * @param array $schemesAlternative |
||
70 | * @return KeyValueInterface |
||
71 | */ |
||
72 | public static function getKeyValueInstance($connectionString, $schemesAlternative = null) |
||
89 | |||
90 | 28 | protected static function getInstance($connectionString, $validSchemes, $typeOf) |
|
91 | { |
||
92 | 28 | $connectionUri = new Uri($connectionString); |
|
93 | |||
94 | 28 | $scheme = $connectionUri->getScheme(); |
|
95 | |||
96 | 28 | $class = isset($validSchemes[$scheme]) ? $validSchemes[$scheme] : PdoLiteral::class; |
|
97 | |||
98 | 28 | $instance = new $class($connectionUri); |
|
99 | |||
100 | 28 | if (!is_a($instance, $typeOf)) { |
|
101 | throw new \InvalidArgumentException( |
||
102 | "The class '$typeOf' is not a instance of DbDriverInterface" |
||
103 | ); |
||
104 | } |
||
105 | |||
106 | 28 | return $instance; |
|
107 | } |
||
108 | |||
109 | /** |
||
110 | * Get a IDbFunctions class to execute Database specific operations. |
||
111 | * |
||
112 | * @param \ByJG\Util\Uri $connectionUri |
||
113 | * @return \ByJG\AnyDataset\DbFunctionsInterface |
||
114 | */ |
||
115 | 5 | public static function getDbFunctions(Uri $connectionUri) |
|
122 | } |
||
123 |