private function initConnection($dbname)
 {
     $cfg = Config::getSingleton()->get($this->configKey);
     if (!$cfg) {
         throw new \Exception("No configuration found for '{$this->configKey}'");
     }
     $cfg = $cfg[$dbname];
     if (!$cfg) {
         throw new \Exception("No configuration found for connection '{$dbname}'");
     }
     switch ($cfg['driver']) {
         case 'pgsql':
         case 'mysql':
             if (!isset($cfg['additional_dsn'])) {
                 $cfg['additional_dsn'] = '';
             }
             $connstr = "{$cfg['driver']}:host={$cfg['host']} dbname={$cfg['database']} {$cfg['additional_dsn']}";
             if (isset($cfg['port'])) {
                 $connstr .= ' port=' . $cfg['port'];
             }
             break;
         case 'sqlite':
             $connstr = "sqlite:{$cfg['filename']}";
             break;
         default:
             throw new \Exception("Unsupported driver '{$cfg['driver']} given for connection '{$dbname}'.");
     }
     if (!isset($cfg['user'])) {
         $cfg['user'] = '';
     }
     if (!isset($cfg['password'])) {
         $cfg['password'] = '';
     }
     if (class_exists("Aura\\Sql\\ExtendedPdo")) {
         $conn = new ExtendedPdo($connstr, $cfg['user'], $cfg['password']);
         if (isset($cfg['profiling']) && $cfg['profiling'] == true) {
             $conn->setProfiler(new Profiler());
             $conn->getProfiler()->setActive(true);
         }
     } else {
         $conn = new PDO($connstr, $cfg['user'], $cfg['password']);
     }
     if ($conn) {
         $conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
     }
     $this->connections[$dbname] = $conn;
 }
 /**
  * Returns db for given repository.
  *
  * @param string    $repository_url Repository url.
  * @param ConsoleIO $io             Console IO.
  *
  * @return ExtendedPdoInterface
  */
 public function getDatabase($repository_url, ConsoleIO $io = null)
 {
     if (preg_match(Connector::URL_REGEXP, $repository_url, $regs)) {
         $sub_folder = $regs[2] . $regs[3] . $regs[4];
     } else {
         $sub_folder = 'misc';
     }
     $parent_path = $this->_workingDirectory . '/' . $sub_folder;
     if (!file_exists($parent_path)) {
         mkdir($parent_path, 0777, true);
     }
     $db = new ExtendedPdo('sqlite:' . $parent_path . '/log_' . crc32($repository_url) . '.sqlite');
     $profiler = clone $this->_statementProfiler;
     $profiler->setIO($io);
     $db->setProfiler($profiler);
     return $db;
 }