/** * Get database * * @param string $index * @return Db\Common\Adapter * @throws Exception */ public function db($index = self::DEFAULT_INDEX) { if (!isset($this->dbs[$index])) { $dbConfig = \Magelight\Config::getInstance()->getConfig('/global/db/' . $index, null); if (is_null($dbConfig)) { throw new \Magelight\Exception("Database `{$index}` configuration not found."); } $adapterClass = \Magelight\Db\Common\Adapter::getAdapterClassByType((string) $dbConfig->type); $db = call_user_func_array([$adapterClass, 'forge'], []); /* @var $db \Magelight\Db\Common\Adapter */ $db->init((array) $dbConfig); $this->dbs[$index] = $db; } return $this->dbs[$index]; }