Bolt\Provider\SessionServiceProvider::parseConnections PHP Method

parseConnections() protected method

protected parseConnections ( $options, $defaultHost, $defaultPort, $defaultScheme = 'tcp' )
    protected function parseConnections($options, $defaultHost, $defaultPort, $defaultScheme = 'tcp')
    {
        if (isset($options['host']) || isset($options['port'])) {
            $options['connections'][] = $options;
        } elseif ($options['connection']) {
            $options['connections'][] = $options['connection'];
        }
        /** @var ParameterBag[] $toParse */
        $toParse = [];
        if (isset($options['connections'])) {
            foreach ((array) $options['connections'] as $alias => $conn) {
                if (is_string($conn)) {
                    $conn = ['host' => $conn];
                }
                $conn += ['scheme' => $defaultScheme, 'host' => $defaultHost, 'port' => $defaultPort];
                $conn = new ParameterBag($conn);
                if ($conn->has('password')) {
                    $conn->set('pass', $conn->get('password'));
                    $conn->remove('password');
                }
                $conn->set('uri', Uri::fromParts($conn->all()));
                $toParse[] = $conn;
            }
        } else {
            $connections = isset($options['save_path']) ? (array) explode(',', $options['save_path']) : [];
            if (empty($connections)) {
                $connections[] = $defaultHost . ':' . $defaultPort;
            }
            foreach ($connections as $conn) {
                // Default scheme if not given so parse_url works correctly.
                if (!preg_match('~^\\w+://.+~', $conn)) {
                    $conn = $defaultScheme . '://' . $conn;
                }
                $uri = new Uri($conn);
                $connBag = new ParameterBag();
                $connBag->set('uri', $uri);
                $connBag->add(Psr7\parse_query($uri->getQuery()));
                $toParse[] = $connBag;
            }
        }
        $connections = [];
        foreach ($toParse as $conn) {
            /** @var Uri $uri */
            $uri = $conn->get('uri');
            $parts = explode(':', $uri->getUserInfo(), 2);
            $password = isset($parts[1]) ? $parts[1] : null;
            $connections[] = ['scheme' => $uri->getScheme(), 'host' => $uri->getHost(), 'port' => $uri->getPort(), 'path' => $uri->getPath(), 'alias' => $conn->get('alias'), 'prefix' => $conn->get('prefix'), 'password' => $password, 'database' => $conn->get('database'), 'persistent' => $conn->get('persistent'), 'weight' => $conn->get('weight'), 'timeout' => $conn->get('timeout')];
        }
        return $connections;
    }