Example #1
0
 /**
  * Loads and returns an instance of the Forge for the specified
  * database group, and loads the group if it hasn't been loaded yet.
  *
  * @param string|null $group
  */
 public static function forge(string $group = null)
 {
     $config = new \Config\Database();
     self::ensureFactory();
     if (empty($group)) {
         $group = ENVIRONMENT == 'testing' ? 'tests' : $config->defaultGroup;
     }
     if (!isset($config->{$group})) {
         throw new \InvalidArgumentException($group . ' is not a valid database connection group.');
     }
     if (!isset(self::$instances[$group])) {
         $db = self::connect($group);
     } else {
         $db = self::$instances[$group];
     }
     return self::$factory->loadForge($db);
 }