1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-03 20:57:36 +02:00

Connection: option 'driver' can contain driver instance or class name [Closes #153]

This commit is contained in:
Pavel Zelezny
2015-10-26 16:11:42 +01:00
committed by David Grudl
parent b3696f9beb
commit 5fac432272

View File

@@ -79,15 +79,22 @@ class Connection
$config['driver'] = \dibi::$defaultDriver;
}
$class = $tmp = preg_replace(['#\W#', '#sql#'], ['_', 'Sql'], ucfirst(strtolower($config['driver'])));
$class = "Dibi\\Drivers\\{$class}Driver";
if (!class_exists($class)) {
throw new Exception("Unable to create instance of dibi driver '$class'.");
if ($config['driver'] instanceof Driver) {
$this->driver = $config['driver'];
$config['driver'] = get_class($this->driver);
} elseif (is_subclass_of($config['driver'], 'Dibi\Driver')) {
$this->driver = new $config['driver'];
} else {
$class = preg_replace(['#\W#', '#sql#'], ['_', 'Sql'], ucfirst(strtolower($config['driver'])));
$class = "Dibi\\Drivers\\{$class}Driver";
if (!class_exists($class)) {
throw new Exception("Unable to create instance of dibi driver '$class'.");
}
$this->driver = new $class;
}
$config['name'] = $name;
$this->config = $config;
$this->driver = new $class;
$this->translator = new Translator($this);
// profiler