mirror of
https://github.com/dg/dibi.git
synced 2025-08-04 05:07:36 +02:00
Connection: option 'driver' can contain driver instance or class name [Closes #153]
This commit is contained in:
committed by
David Grudl
parent
b3696f9beb
commit
5fac432272
@@ -79,15 +79,22 @@ class Connection
|
|||||||
$config['driver'] = \dibi::$defaultDriver;
|
$config['driver'] = \dibi::$defaultDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
$class = $tmp = preg_replace(['#\W#', '#sql#'], ['_', 'Sql'], ucfirst(strtolower($config['driver'])));
|
if ($config['driver'] instanceof Driver) {
|
||||||
$class = "Dibi\\Drivers\\{$class}Driver";
|
$this->driver = $config['driver'];
|
||||||
if (!class_exists($class)) {
|
$config['driver'] = get_class($this->driver);
|
||||||
throw new Exception("Unable to create instance of dibi driver '$class'.");
|
} 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;
|
$config['name'] = $name;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->driver = new $class;
|
|
||||||
$this->translator = new Translator($this);
|
$this->translator = new Translator($this);
|
||||||
|
|
||||||
// profiler
|
// profiler
|
||||||
|
Reference in New Issue
Block a user