Skip to content

Commit

Permalink
Allow custom connections to be made when creating a database. Fixes #62
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnieezell committed May 1, 2016
1 parent bb24b5e commit 1178753
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions system/Database/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,45 @@ class Config extends BaseConfig
/**
* Creates the default
*
* @param string $group The name of the connection group to use.
* @param bool $getShared Whether to return a shared instance of the connection.
* @param string|array $group The name of the connection group to use,
* or an array of configuration settings.
* @param bool $getShared Whether to return a shared instance of the connection.
*
* @return mixed
*/
public static function connect(string $group = null, $getShared = true)
public static function connect($group = null, $getShared = true)
{
if (is_array($group))
{
$config = $group;
$group = 'custom';
}

if ($getShared && isset(self::$instances[$group]))
{
return self::$instances[$group];
}

self::ensureFactory();

$config = new \Config\Database();
$config = $config ?? new \Config\Database();

if (empty($group))
{
$group = ENVIRONMENT == 'testing' ? 'tests' : $config->defaultGroup;
}

if (! isset($config->$group))
if (is_string($group) && ! isset($config->$group) && $group != 'custom')
{
throw new \InvalidArgumentException($group.' is not a valid database connection group.');
}

$connection = self::$factory->load($config->$group, $group);
if (isset($config->$group))
{
$config = $config->$group;
}

$connection = self::$factory->load($config, $group);

self::$instances[$group] =& $connection;

Expand Down

0 comments on commit 1178753

Please sign in to comment.