44
55namespace ezsql ;
66
7+ use ezsql \Db ;
78use ezsql \DInjector ;
8- use function ezsql \functions \setInstance ;
99
1010class Database
1111{
@@ -15,7 +15,10 @@ class Database
1515 * @var float
1616 */
1717 private static $ _ts = null ;
18- private static $ factory = null ;
18+
19+ /**
20+ * @var ezQueryInterface[]
21+ */
1922 private static $ instances = [];
2023
2124 // @codeCoverageIgnoreStart
@@ -67,10 +70,10 @@ public function __wakeup()
6770 * @param string $tag Store the instance for later use
6871 * @return Database\ez_pdo|Database\ez_pgsql|Database\ez_sqlsrv|Database\ez_sqlite3|Database\ez_mysqli
6972 */
70- public static function initialize (?string $ vendor = null , ?array $ setting = null , ?string $ tag = null )
73+ public static function initialize (?string $ vendor = null , ?array $ setting = null , ?string $ tag = null ): ezQueryInterface
7174 {
7275 if (isset (self ::$ instances [$ vendor ]) && empty ($ setting ) && empty ($ tag ))
73- return setInstance ( self ::$ instances [$ vendor ]) ? self :: $ instances [ $ vendor ] : false ;
76+ return self ::$ instances [$ vendor ];
7477
7578 if (empty ($ vendor ) || empty ($ setting )) {
7679 throw new \Exception (\MISSING_CONFIGURATION );
@@ -79,7 +82,7 @@ public static function initialize(?string $vendor = null, ?array $setting = null
7982 $ key = $ vendor ;
8083 $ value = \VENDOR [$ key ];
8184
82- if (empty ( $ GLOBALS [ 'ez ' . $ key] ) || !empty ($ tag )) {
85+ if (!Db:: has ( 'ez ' . $ key ) || !empty ($ tag )) {
8386 $ di = new DInjector ();
8487 $ di ->set ($ key , $ value );
8588 $ di ->set ('ezsql\ConfigInterface ' , 'ezsql\Config ' );
@@ -90,8 +93,9 @@ public static function initialize(?string $vendor = null, ?array $setting = null
9093 }
9194 }
9295
93- setInstance ($ GLOBALS ['ez ' . $ key ]);
94- return $ GLOBALS ['ez ' . $ key ];
96+ $ db = Db::get ('ez ' . $ key );
97+ Db::set ('global ' , $ db );
98+ return $ db ;
9599 }
96100 }
97101
0 commit comments