Create a new clustered Predis connection.

@param  array  $config
@param  array  $clusterOptions
@param  array  $options
@return \Illuminate\Redis\Connections\PredisClusterConnection
517136
public function connectToCluster(array $config, array $clusterOptions, array $options)
    {
        $clusterSpecificOptions = Arr::pull($config, 'options', []);

        return new PredisClusterConnection(new Client(array_values($config), array_merge(
            $options, $clusterOptions, $clusterSpecificOptions
        )));
    }
902227
public function createConnector( array $config )
	{
		if ( !isset( $config['driver'] ) )
			throw new InvalidArgumentException( 'A driver must be specified.' );

		switch ( $config['driver'] )
		{
			case 'mysql':
				return new MySqlConnector;
			case 'pgsql':
				return new PostgresConnector;
			case 'sqlite':
				return new SQLiteConnector;
			case 'sqlsrv':
				return new SqlServerConnector;
		}

		throw new InvalidArgumentException( "Unsupported driver [{$config['driver']}]" );
	}
1074425
protected function createAggregateClient(array $servers, array $options = []) {
        $options = array(
        	'lazy_connect' => true,
	        'pconnect'     => false,
	        'timeout'      => 0,
	    );

        $cluster = array();
        foreach ($servers as $key => $server) {
        	if ($key === 'cluster') continue;

        	$host    = empty($server['host'])    ? '127.0.0.1' : $server['host'];
            $port    = empty($server['port'])    ? '6379'      : $server['port'];

            $serializer = Redis::SERIALIZER_NONE;
            if (!empty($server['serializer'])) {
            	if ($server['serializer'] === 'none') {
            		$serializer = Redis::SERIALIZER_PHP;
            	} else if ($server['serializer'] === 'igbinary') {
                    if (defined('Redis::SERIALIZER_IGBINARY')) {
                        $serializer = Redis::SERIALIZER_IGBINARY;
                    } else {
                        $serializer = Redis::SERIALIZER_PHP;
                    }
            	}
            }

            $cluster[$host.':'.$port] = array(
            	'prefix'     => empty($server['prefix'])   ? '' : $server['prefix'],
            	'database'   => empty($server['database']) ? 0  : $server['database'],
            	'serializer' => $serializer,
        	);

            if (isset($server['persistent'])) {
            	$options['pconnect'] = $options['pconnect'] && $server['persistent'];
            } else {
				$options['pconnect'] = false;
            }

            if (!empty($server['timeout'])) {
            	$options['timeout'] = max($options['timeout'], $server['timeout']);
            }
        }

        $ra = new RedisArray(array_keys($cluster), $options);

        foreach ($cluster as $host => $options) {
        	$redis = $ra->_instance($host);
        	$redis->setOption(Redis::OPT_PREFIX, $options['prefix']);
        	$redis->setOption(Redis::OPT_SERIALIZER, $options['serializer']);
        	$redis->select($options['database']);
        }

        return array('default' => $ra);
    }
69656
public function createConnection($dsn, array $config, array $options)
    {
        $username = Arr::get($config, 'username');
        $password = Arr::get($config, 'password');

        try {
            $pdo = new PDO($dsn, $username, $password, $options);
        } catch (Exception $e) {
            $pdo = $this->tryAgainIfCausedByLostConnection(
                $e, $dsn, $username, $password, $options
            );
        }

        return $pdo;
    }
566780
public static Cluster getCluster(Config config, Context context) {
    Cluster cluster = null;
    if (config != null && context != null) {
      String clusterName = context.getCluster();
      if (clusterName != null) {
        List<NamedCluster> clusters = config.getClusters();
        if (clusters != null) {
          for (NamedCluster namedCluster : clusters) {
            if (clusterName.equals(namedCluster.getName())) {
              cluster = namedCluster.getCluster();
            }
          }
        }
      }
    }
    return cluster;
  }
146169
public function createConnection($dsn, array $config, array $options)
    {
        $username = array_get($config, 'username');

        $password = array_get($config, 'password');

        return new PDO($dsn, $username, $password, $options);
    }
389400
protected function createConnection(AbstractConnector $connector, array $config = [])
    {
        // The connection driver is optional, but the connection is still required.
        // We return the generic connection when no connection driver is defined.
        if (isset($config['driver'])) {
            switch ($driver = $config['driver']) {
                default:
                    throw new InvalidArgumentException("Unsupported connection driver [{$driver}]");
            }
        }

        return new GenericConnection($connector, $config);
    }
1334112
public function loadArray(array $options, Config $config = null)
    {
        Assertion::notEmpty($options);

        if (is_null($config)) {
            $config = new Config();
        }

        $options = $this->doReplacements($options);

        $config->merge(
            new Config($options)
        );

        return $config;
    }
1130639
public function connect(array $config): Queue
    {
        if (false === array_key_exists('factory_class', $config)) {
            throw new \LogicException('The factory_class option is missing though it is required.');
        }

        $factoryClass = $config['factory_class'];
        if (false === class_exists($factoryClass) || false === (new \ReflectionClass($factoryClass))->implementsInterface(InteropAmqpConnectionFactory::class)) {
            throw new \LogicException(sprintf('The factory_class option has to be valid class that implements "%s"', InteropAmqpConnectionFactory::class));
        }

        /** @var AmqpConnectionFactory $factory */
        $factory = new $factoryClass([
            'dsn'            => $config['dsn'],
            'host'           => $config['host'],
            'port'           => $config['port'],
            'user'           => $config['login'],
            'pass'           => $config['password'],
            'vhost'          => $config['vhost'],
            'ssl_on'         => $config['ssl_params']['ssl_on'],
            'ssl_verify'     => $config['ssl_params']['verify_peer'],
            'ssl_cacert'     => $config['ssl_params']['cafile'],
            'ssl_cert'       => $config['ssl_params']['local_cert'],
            'ssl_key'        => $config['ssl_params']['local_key'],
            'ssl_passphrase' => $config['ssl_params']['passphrase'],
        ]);

        if ($factory instanceof DelayStrategyAware) {
            $factory->setDelayStrategy(new RabbitMqDlxDelayStrategy());
        }

        /** @var AmqpContext $context */
        $context = $factory->createContext();

        /** @var Dispatcher $dispatcher */
        $dispatcher = app(Dispatcher::class);
        $dispatcher->listen(WorkerStopping::class, function () use ($context) {
            $context->close();
        });

        return new RabbitMQQueue($context, $config);
    }
302578
protected function createSingleConnection(array $config)
    {
        $pdo = $this->createConnector($config)->connect($config);

        return $this->createConnection($config['driver'], $pdo, $config['database'], $config['prefix'], $config);
    }
449442
protected function createRedisClusterInstance(array $servers, array $options)
    {
        return new RedisCluster(
            null,
            array_values($servers),
            $options['timeout'] ?? 0,
            $options['read_timeout'] ?? 0,
            isset($options['persistent']) && $options['persistent']
        );
    }
367643
protected function getConnection(Configuration $config)
    {
        $connection = $this->getOption('connection');

        switch (true) {
            case is_array($connection):
                $connection = new Connection(
                    array_key_exists('server', $connection) ? $connection['server'] : null,
                    array_key_exists('options', $connection) ? $connection['options'] : [],
                    $config,
                    $this->getEventManager()
                );
                break;

            case $connection instanceof Connection:
                if ($connection->getEventManager() !== $this->getEventManager()) {
                    throw new \RuntimeException(
                        'Cannot use different EventManager instances for DocumentManager and Connection.'
                    );
                }
                break;

            default:
                throw new \InvalidArgumentException('Invalid argument: ' . $connection);
        }

        return $connection;
    }
1285342
public function connect(array $config)
    {
        $tns = ! empty($config['tns']) ? $config['tns'] : $this->getDsn($config);

        $options = $this->getOptions($config);

        if (array_get($options, 'session_mode') === OCI_CRED_EXT) {
            // External connections can only be used with user / and an empty password
            $config['username'] = '/';
            $config['password'] = null;
        }

        $connection = $this->createConnection($tns, $config, $options);

        return $connection;
    }
1207556
public function connect(array $config): PDO
    {
        if (isset($config['options']) === false) {
            $config['options'] = [];
        }

        return $this->doConnect($config);
    }
367073
public function createConnection(array $params, Configuration $config = null, EventManager $eventManager = null, array $mappingTypes = [])
    {
        if (isset($params['dbname'])) {
            $dbName = $this->getDbNameFromEnv($params['dbname']);
        } else {
            $dbName = $this->getDbNameFromEnv($params['master']['dbname']);
        }

        if ('pdo_sqlite' === $params['driver']) {
            if (isset($params['path'])) {
                $params['path'] = str_replace('__DBNAME__', $dbName, $params['path']);
            }

            if (isset($params['master']['path'])) {
                $params['master']['path'] = str_replace('__DBNAME__', $dbName, $params['master']['path']);
            }

            if (!empty($params['slaves'])) {
                foreach ($params['slaves'] as &$slave) {
                    $slave['path'] = str_replace('__DBNAME__', $dbName, $slave['path']);
                }
            }
        } else {
            $params['dbname'] = $dbName;
        }

        return parent::createConnection($params, $config, $eventManager, $mappingTypes);
    }
1247607
public function connect(array $config)
    {
        return new DatabaseQueue(
            $this->connections->connection(array_get($config, 'connection')),
            array_get($config, 'table', 'queues'),
            array_get($config, 'queue', null),
            array_get($config, 'expire', 60),
            array_get($config, 'lock_type', 60)
        );
    }
124522
private function createConnection(array $persisterConfig, $configName)
    {
        $options = isset($persisterConfig['parameters']['options']) && is_array($persisterConfig['parameters']['options']) ? $persisterConfig['parameters']['options'] : [];
        $definition = new Definition(
            'Doctrine\MongoDB\Connection',
            [$persisterConfig['parameters']['host'], $options, new Reference($configName)]
        );
        $definition->setPublic(false);
        return $definition;
    }