protected function db($name, Config $config)
 {
     if (!($config = $config->get("databases.{$name}"))) {
         throw new \LogicException("No configuration for database '{$name}'");
     }
     if (is_array($config)) {
         $dsn = new DSN($config);
     } else {
         $dsn = DSN::fromString($config);
     }
     $db = parent::offsetGet('db')->add($name, $dsn);
     parent::offsetExists('profiler') && $db->setProfiler(parent::offsetGet('profiler'));
     return $db;
 }
 /**
  * Ensure we have a valid DSN instance.
  * @param  mixed $dsn a string, array or DSN instance
  * @return DSN
  */
 protected function validateDSN($dsn)
 {
     if ($dsn instanceof DSN) {
         return $dsn;
     } elseif (is_string($dsn)) {
         return DSN::fromString($dsn);
     } elseif (is_array($dsn)) {
         return new DSN($dsn);
     } else {
         throw new ConfigurationException('Invalid DSN: ' . $dsn);
     }
 }