mirror of
https://github.com/dg/dibi.git
synced 2025-08-03 20:57:36 +02:00
Connection::__construct() parameter config should be array (BC break)
This commit is contained in:
@@ -40,18 +40,7 @@ try {
|
||||
echo "</p>\n";
|
||||
|
||||
|
||||
// connects to MySQL using DSN
|
||||
echo '<p>Connecting to MySQL: ';
|
||||
try {
|
||||
dibi::connect('driver=mysql&host=localhost&username=root&password=xxx&database=test&charset=cp1250');
|
||||
echo 'OK';
|
||||
} catch (Dibi\Exception $e) {
|
||||
echo get_class($e), ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
echo "</p>\n";
|
||||
|
||||
|
||||
// connects to MySQLi using array
|
||||
// connects to MySQLi
|
||||
echo '<p>Connecting to MySQLi: ';
|
||||
try {
|
||||
dibi::connect([
|
||||
|
@@ -56,9 +56,11 @@ class Connection implements IConnection
|
||||
public function __construct($config, string $name = null)
|
||||
{
|
||||
if (is_string($config)) {
|
||||
trigger_error(__METHOD__ . '() Configuration should be array.', E_USER_DEPRECATED);
|
||||
parse_str($config, $config);
|
||||
|
||||
} elseif ($config instanceof Traversable) {
|
||||
trigger_error(__METHOD__ . '() Configuration should be array.', E_USER_DEPRECATED);
|
||||
$tmp = [];
|
||||
foreach ($config as $key => $val) {
|
||||
$tmp[$key] = $val instanceof Traversable ? iterator_to_array($val) : $val;
|
||||
@@ -66,7 +68,7 @@ class Connection implements IConnection
|
||||
$config = $tmp;
|
||||
|
||||
} elseif (!is_array($config)) {
|
||||
throw new \InvalidArgumentException('Configuration must be array, string or object.');
|
||||
throw new \InvalidArgumentException('Configuration must be array.');
|
||||
}
|
||||
|
||||
Helpers::alias($config, 'username', 'user');
|
||||
|
@@ -30,8 +30,8 @@ test(function () use ($config) { // lazy
|
||||
});
|
||||
|
||||
|
||||
test(function () use ($config) { // query string
|
||||
$conn = new Connection(http_build_query($config, '', '&'));
|
||||
test(function () use ($config) {
|
||||
$conn = new Connection($config);
|
||||
Assert::true($conn->isConnected());
|
||||
|
||||
Assert::null($conn->getConfig('lazy'));
|
||||
|
Reference in New Issue
Block a user