Skip to content

Commit dda5a01

Browse files
authored
Merge pull request #7553 from kenjis/refactor-Database-initDriver
refactor: Database::initDriver()
2 parents e936bb3 + 07f3274 commit dda5a01

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

system/Database/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Config extends BaseConfig
3737
protected static $factory;
3838

3939
/**
40-
* Creates the default
40+
* Returns the database connection
4141
*
4242
* @param array|BaseConnection|string|null $group The name of the connection group to use,
4343
* or an array of configuration settings.

system/Database/Database.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
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
*/
2121
class 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

Comments
 (0)