1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-05 13:47:33 +02:00

DibiConnection: 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 e339eff00f
commit 9100f94b8f

View File

@@ -75,6 +75,12 @@ class DibiConnection extends DibiObject
$config['driver'] = dibi::$defaultDriver;
}
if ($config['driver'] instanceof IDibiDriver) {
$this->driver = $config['driver'];
$config['driver'] = get_class($this->driver);
} elseif (PHP_VERSION_ID >= 50307 && is_subclass_of($config['driver'], 'IDibiDriver')) {
$this->driver = new $config['driver'];
} else {
$class = preg_replace(array('#\W#', '#sql#'), array('_', 'Sql'), ucfirst(strtolower($config['driver'])));
$class = "Dibi{$class}Driver";
if (!class_exists($class)) {
@@ -84,10 +90,11 @@ class DibiConnection extends DibiObject
throw new DibiException("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 DibiTranslator($this);
// profiler