mirror of
https://github.com/dg/dibi.git
synced 2025-08-06 14:16:39 +02:00
DibiConnection: option 'driver' can contain driver instance or class name [Closes #153]
This commit is contained in:
committed by
David Grudl
parent
e339eff00f
commit
9100f94b8f
@@ -75,6 +75,12 @@ class DibiConnection extends DibiObject
|
|||||||
$config['driver'] = dibi::$defaultDriver;
|
$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 = preg_replace(array('#\W#', '#sql#'), array('_', 'Sql'), ucfirst(strtolower($config['driver'])));
|
||||||
$class = "Dibi{$class}Driver";
|
$class = "Dibi{$class}Driver";
|
||||||
if (!class_exists($class)) {
|
if (!class_exists($class)) {
|
||||||
@@ -84,10 +90,11 @@ class DibiConnection extends DibiObject
|
|||||||
throw new DibiException("Unable to create instance of dibi driver '$class'.");
|
throw new DibiException("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 DibiTranslator($this);
|
$this->translator = new DibiTranslator($this);
|
||||||
|
|
||||||
// profiler
|
// profiler
|
||||||
|
Reference in New Issue
Block a user