mirror of
https://github.com/dg/dibi.git
synced 2025-08-08 15:16:58 +02:00
compatibility with Nette::Config
This commit is contained in:
@@ -161,23 +161,18 @@ class dibi
|
|||||||
/**
|
/**
|
||||||
* Creates a new DibiConnection object and connects it to specified database.
|
* Creates a new DibiConnection object and connects it to specified database.
|
||||||
*
|
*
|
||||||
* @param array|string connection parameters
|
* @param array|string|Nette::Collections::IMap connection parameters
|
||||||
* @param string connection name
|
* @param string connection name
|
||||||
* @return DibiConnection
|
* @return DibiConnection
|
||||||
* @throws DibiException
|
* @throws DibiException
|
||||||
*/
|
*/
|
||||||
public static function connect($config = array(), $name = 0)
|
public static function connect($config = array(), $name = 0)
|
||||||
{
|
{
|
||||||
if (class_exists(/*Nette::*/'Debug', FALSE) && /*Nette::*/Debug::isEnabled()) {
|
if (class_exists(/*Nette::*/'Debug', FALSE)) {
|
||||||
/*Nette::*/Debug::addColophon(array(__CLASS__, 'getColophon'));
|
/*Nette::*/Debug::addColophon(array(__CLASS__, 'getColophon'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($config) || $config instanceof /*Nette::Collections::*/IMap) {
|
return self::$connection = self::$registry[$name] = new DibiConnection($config, $name);
|
||||||
$config['name'] = $name;
|
|
||||||
} else {
|
|
||||||
$config .= '&name=' . urlencode($name);
|
|
||||||
}
|
|
||||||
return self::$connection = self::$registry[$name] = new DibiConnection($config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -59,9 +59,10 @@ class DibiConnection extends /*Nette::*/Object
|
|||||||
* Creates object and (optionally) connects to a database.
|
* Creates object and (optionally) connects to a database.
|
||||||
*
|
*
|
||||||
* @param array|string|Nette::Collections::IMap connection parameters
|
* @param array|string|Nette::Collections::IMap connection parameters
|
||||||
|
* @param string connection name
|
||||||
* @throws DibiException
|
* @throws DibiException
|
||||||
*/
|
*/
|
||||||
public function __construct($config)
|
public function __construct($config, $name = NULL)
|
||||||
{
|
{
|
||||||
// DSN string
|
// DSN string
|
||||||
if (is_string($config)) {
|
if (is_string($config)) {
|
||||||
@@ -69,6 +70,9 @@ class DibiConnection extends /*Nette::*/Object
|
|||||||
|
|
||||||
} elseif ($config instanceof /*Nette::Collections::*/IMap) {
|
} elseif ($config instanceof /*Nette::Collections::*/IMap) {
|
||||||
$config = $config->toArray();
|
$config = $config->toArray();
|
||||||
|
|
||||||
|
} elseif (!is_array($config)) {
|
||||||
|
throw new InvalidArgumentException('Configuration must be array, string or Nette::Collections::IMap.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($config['driver'])) {
|
if (!isset($config['driver'])) {
|
||||||
@@ -85,6 +89,7 @@ class DibiConnection extends /*Nette::*/Object
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$config['name'] = $name;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->driver = new $class;
|
$this->driver = new $class;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user