-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pls remove string type in parameter $group at Database::forge #1605
Comments
while I think it's a fine change to make, I'm curious why you're using just an array and not adding it as a group in the database config. What type of app are you making? Trying to develop a better picture of other people's use cases. |
@lonnieezell |
Gotcha. thanks for explaining. Another potential solution is use the .env file to set the database configs, but that would require a PHP/server restart after every change, I think, which isn't feasible if you're doing it all on one server. |
For now, I solved it by adding the public static function forge($group = null) {
if (is_array($group)) {
$config = $group;
$group = 'custom-' . md5(json_encode($config));
}
$config = new \Config\Database();
static::ensureFactory();
if (empty($group))
{
$group = ENVIRONMENT === 'testing' ? 'tests' : $config->defaultGroup;
}
if (is_string($group) && ! isset($config->$group) && strpos($group, 'custom-') !== 0)
{
throw new \InvalidArgumentException($group . ' is not a valid database connection group.');
}
if (! isset(static::$instances[$group]))
{
$db = static::connect($group);
}
else
{
$db = static::$instances[$group];
}
return static::$factory->loadForge($db);
} |
It is possible to provide a group array to Database::connect(). The same should be possible to Database::forge and Database::utils.
The text was updated successfully, but these errors were encountered: