1616/**
1717 * Database Connection Factory
1818 *
19- * Creates and returns an instance of the appropriate DatabaseConnection
19+ * Creates and returns an instance of the appropriate Database Connection.
2020 */
2121class Database
2222{
@@ -32,8 +32,7 @@ class Database
3232 protected $ connections = [];
3333
3434 /**
35- * Parses the connection binds and returns an instance of the driver
36- * ready to go.
35+ * Parses the connection binds and creates a Database Connection instance.
3736 *
3837 * @return BaseConnection
3938 *
@@ -83,7 +82,7 @@ public function loadUtils(ConnectionInterface $db): BaseUtils
8382 }
8483
8584 /**
86- * Parse universal DSN string
85+ * Parses universal DSN string
8786 *
8887 * @throws InvalidArgumentException
8988 */
@@ -121,21 +120,20 @@ protected function parseDSN(array $params): array
121120 }
122121
123122 /**
124- * Initialize database driver .
123+ * Creates a database object .
125124 *
126125 * @param string $driver Driver name. FQCN can be used.
127- * @param array|object $argument
126+ * @param string $class 'Connection'|'Forge'|'Utils'
127+ * @param array|object $argument The constructor parameter.
128128 *
129129 * @return BaseConnection|BaseUtils|Forge
130130 */
131131 protected function initDriver (string $ driver , string $ class , $ argument ): object
132132 {
133- $ class = $ driver . '\\' . $ class ;
133+ $ classname = (strpos ($ driver , '\\' ) === false )
134+ ? "CodeIgniter \\Database \\{$ driver }\\{$ class }"
135+ : $ driver . '\\' . $ class ;
134136
135- if (strpos ($ driver , '\\' ) === false ) {
136- $ class = "CodeIgniter \\Database \\{$ class }" ;
137- }
138-
139- return new $ class ($ argument );
137+ return new $ classname ($ argument );
140138 }
141139}
0 commit comments