Creates a new database connection.

@param string $name Name to the database configuration in the resource file
@param string $adapter Name of the database adapter, e.g. "mysql"
@return MW_DB_Connection_Interface Database connection
324170
protected function _createConnection( $name, $adapter )
	{
		$host = $this->_config->get( 'resource/' . $name . '/host' );
		$port = $this->_config->get( 'resource/' . $name . '/port' );
		$user = $this->_config->get( 'resource/' . $name . '/username' );
		$pass = $this->_config->get( 'resource/' . $name . '/password' );
		$sock = $this->_config->get( 'resource/' . $name . '/socket' );
		$dbase = $this->_config->get( 'resource/' . $name . '/database' );

		$dsn = $adapter . ':dbname=' . $dbase;
		if( $sock == null )
		{
			$dsn .= isset( $host ) ? ';host=' . $host : '';
			$dsn .= isset( $port ) ? ';port=' . $port : '';
		}
		else
		{
			$dsn .= ';unix_socket=' . $sock;
		}

		$attr = array(
			PDO::ATTR_PERSISTENT => $this->_config->get( 'resource/' . $name . '/opt-persistent', false ),
		);

		$pdo = new PDO( $dsn, $user, $pass, $attr );
		$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
		$dbc = new MW_DB_Connection_PDO( $pdo );

		foreach( $this->_config->get( 'resource/' . $name . '/stmt', array() ) as $stmt ) {
			$dbc->create( $stmt )->execute()->finish();
		}

		return $dbc;
	}
477104
public function getAdapter(string $name): AdapterInterface
    {
        if (!$this->hasAdapter($name)) {
            throw new Exception\AdapterNotFound('auth adapter '.$name.' is not registered');
        }

        return $this->adapter[$name];
    }
1094823
private function isCredentialsValid($name, array $adapter, array $config)
    {
        /** @var \Gush\Application $application */
        $application = $this->getApplication();
        $factory = $application->getAdapterFactory();

        if ($adapter[AdapterFactory::SUPPORT_REPOSITORY_MANAGER]) {
            $adapter = $factory->createRepositoryManager($name, $config, $this->getConfig());
        } elseif ($adapter[AdapterFactory::SUPPORT_ISSUE_TRACKER]) {
            $adapter = $factory->createIssueTracker($name, $config, $this->getConfig());
        }

        $adapter->authenticate();

        return $adapter->isAuthenticated();
    }
174033
public function setAdapter($name, AdapterInterface $adapter)
    {
        $this->adapters[$name] = $adapter;
        $this->adapterClasses[$name] = get_class($adapter);
    }
954215
protected function configuration($name)
    {
        $name = $name ?: $this->getDefaultConnection();

        // To get the database connection configuration, we will just pull each of the
        // connection configurations and get the configurations for the given name.
        // If the configuration doesn't exist, we'll throw an exception and bail.

        $connections = config('database.connections');
        if (is_null($config = Nip_Helper_Arrays::get($connections, $name))) {
            throw new InvalidArgumentException("Database [$name] not configured.");
        }
        return $config;
    }
1063524
public function addConnection(Array $config, $name = 'default')
    {
        $connectors = array(
            'mysql' => 'Mysql',
            'pgsql' => 'Postgres',
            'sqlite' => 'SQLite'
        );

        if (!isset($config['driver']) || !array_key_exists($config['driver'], $connectors)) {
            throw new \OtherCode\Database\Exceptions\ConnectionException("The selected driver is not valid.");
        }

        $connector = "OtherCode\\Database\\Connectors\\" . $connectors[$config['driver']] . 'Connector';
        $connection = new $connector();

        $this->connections[$name] = $connection->connect($config);
        return $this;
    }
640232
public function setAdapter(AdapterInterface $adapter)
    {
        $adapter->setClient($this);

        $this->adapter = $adapter;

        return $this;
    }
1340216
public function getConnection($name)
    {
        if (!$this->connectionSettings->has($name)) {
            throw new BadArgumentException('Connection with name ":name" not defined in configuration file ":file"', [
                'name' => $name, 'file' => ServiceLocator::instance()->getConfiguration()->getIdentity(),
            ]);
        }
        
        if (!static::$connections->has($name)) {
            static::$connections->set($name, new Connection($this->connectionSettings->get($name)));
        }
        
        return static::$connections[$name];
    }
498316
public static function getAdapter($config = null) {
		if (is_string($config)) {
			$config = Yesf::app()->getConfig('connection.' . $config);
		}
		if (!isset($config['adapter'])) {
			throw new ConnectionException("Unknown adapter");
		}
		$type = $config['adapter'];
		// Get connection
		$connection = Pool::get($config);
		$hash = spl_object_hash($connection);
		if (!isset(self::$created_adapter[$hash])) {
			if (isset(self::$adapter[$type])) {
				$className = self::$adapter[$type];
			} else {
				throw new ConnectionException("Unknown adapter");
			}
			$instance = new $className($connection);
			self::$created_adapter[$hash] = $instance;
			return $instance;
		} else {
			return self::$created_adapter[$hash];
		}
	}
1286701
public function getWriteConnection(AdapterInterface $adapter = null)
    {
        if (null === $this->connection) {
            $this->connection = ConnectionFactory::create($this->configuration, $adapter);
            $this->connection->setName($this->getName());
        }

        return $this->connection;
    }
404564
public function getConnection($name = null)
    {
        $name = $name ?: $this->getDefaultConnectionName();

        if (!$this->connectionExists($name)) {
            throw new InvalidArgumentException(sprintf('Doctrine Connection named "%s" does not exist.', $name));
        }

        if (isset($this->connectionsMap[$name])) {
            return $this->connectionsMap[$name];
        }

        return $this->connectionsMap[$name] = $this->getService(
            $this->getConnectionBindingName($this->connections[$name])
        );
    }
587813
protected function createConnection($driver, $connection, $database, $prefix = '', $config = [])
    {
//        if ($resolver = Connection::getResolver($driver)) {
//            return $resolver($connection, $database, $prefix, $config);
//        }
        switch ($driver) {
            case 'mysql':
                return new MySqlConnection($connection, $database, $prefix, $config);
        }

        throw new InvalidArgumentException("Unsupported driver [$driver]");
    }
1149735
public function getConnection(string $name = null): Connection
    {
        if (is_null($name) and !is_null($this->defaultConnection)) {
            return $this->defaultConnection;
        }

        if (is_null($name) or !array_key_exists($name, $this->registry)) {
            throw new MongoDBConnectionNameNotFoundException($name);
        }

        return $this->registry[$name];
    }
346567
public function make($records, $adapter = null, $config = array())
    {
        $config = array_merge($this->getConfig(), $config);
        $this->setConfig($config);
        $configHelper = new ConfigHelper($this->getConfig());

        if ($adapter) {
            $this->setAdapter($adapter);
        }

        $recordSet = $this->generate($records,$configHelper);
        $infiniteScroll = new InfiniteScroll(new ViewLoader(), $configHelper);

        $linkCreator = new LinkCreator($configHelper, $infiniteScroll);
        $links = $linkCreator->createLinks($recordSet->total());
        $recordSet->setLinks($links);
        return $recordSet;
    }
508895
protected function connect( $name ) 
	{
		if ( $this->_connected ) 
		{
			return true; 
		}
		
		// check if the name is an array. This way we can
		// pass the configuration directly. We need this 
		// to create for example an handler without having
		// the configuration in the database conf file.
		if ( is_array( $name ) )
		{
			$config = $name;
		}
		else 
		{
			$config = \CCConfig::create( 'database' )->get( $name );
			
			// check for an alias. If you set a string 
			// in your config file we use the config 
			// with the passed key.
			if ( is_string( $config ) ) 
			{
				$config = \CCConfig::create( 'database' )->get( $config );
			}
		}

		// Setup the driver class. We simply use name 
		// from the confif file and make the first letter 
		// capital. example: Handler_Mysql, Handler_Sqlite etc.
		$driver_class = __NAMESPACE__."\\Handler_".ucfirst( $config['driver'] );
		
		if ( !class_exists( $driver_class ) )
		{
			throw new Exception( "DB\\Handler::connect - The driver (".$driver_class.") is invalid." );
		}
		
		$this->set_driver( $driver_class );
		
		// setup the builder the same way as the handler.
		$driver_class = __NAMESPACE__."\\Builder_".ucfirst( $config['driver'] );
		
		if ( !class_exists( $driver_class ) )
		{
			throw new Exception( "DB\\Handler::connect - The builder (".$driver_class.") is invalid." );
		}
		
		$this->set_builder( $driver_class );
		
		// finally try to connect the driver with the databse
		if ( $this->driver()->connect( $config ) ) 
		{
			return $this->_connected = true;
		}

		return $this->_connected = false;
	}
618613
private function createFilesystem(ContainerBuilder $container, $name, $adapter)
    {
        $adapterId = sprintf('oneup_flysystem.%s_adapter', $adapter);
        if (!$container->hasDefinition($adapterId)) {
            throw new InvalidConfigurationException("Unknown flysystem adapter $adapter");
        }

        $filesystemId = sprintf('ezpublish.core.io.flysystem.%s_filesystem', $name);
        $definition = $container->setDefinition(
            $filesystemId,
            new DefinitionDecorator('ezpublish.core.io.flysystem.base_filesystem')
        );
        $definition->setArguments(array(new Reference($adapterId)));

        return $filesystemId;
    }
307448
public function setAdapter(AdapterInterface $adapter)
    {
        $this->adapter = $adapter;
        $this->connection = new Connection($this->adapter);
    }