Predis\Client::createConnection PHP Method

createConnection() protected method

Accepted types for connection parameters are: - Instance of Predis\Connection\ConnectionInterface. - Instance of Predis\Connection\ParametersInterface. - Array - String - Callable
protected createConnection ( mixed $parameters ) : Predis\Connection\ConnectionInterface
$parameters mixed Connection parameters or connection instance.
return Predis\Connection\ConnectionInterface
    protected function createConnection($parameters)
    {
        $options = $this->getOptions();
        if ($parameters instanceof ConnectionInterface) {
            return $parameters;
        }
        if ($parameters instanceof ParametersInterface || is_string($parameters)) {
            return $options->connections->create($parameters);
        }
        if (is_array($parameters)) {
            if (!isset($parameters[0])) {
                return $options->connections->create($parameters);
            }
            if ($options->defined('cluster')) {
                return $this->createAggregateConnection($parameters, 'cluster');
            } elseif ($options->defined('replication')) {
                return $this->createAggregateConnection($parameters, 'replication');
            } elseif ($options->defined('aggregate')) {
                return $this->createAggregateConnection($parameters, 'aggregate');
            } else {
                throw new \InvalidArgumentException('Array of connection parameters requires `cluster`, `replication` or `aggregate` client option');
            }
        }
        if (is_callable($parameters)) {
            $connection = call_user_func($parameters, $options);
            if (!$connection instanceof ConnectionInterface) {
                throw new \InvalidArgumentException('Callable parameters must return a valid connection');
            }
            return $connection;
        }
        throw new \InvalidArgumentException('Invalid type for connection parameters');
    }