Get the stages of a connection.

@param string $connection

@return array
345781
public function getStages($connection)
    {
        $this->connections->setCurrentConnection($connection);

        $stage = $this->config->getContextually('stages.default');
        if ($this->hasCommand()) {
            $stage = $this->getOption('stage') ?: $stage;
        }

        // Return all stages if "all"
        if ($stage === 'all' || !$stage) {
            $stage = $this->connections->getAvailableStages();
        }

        // Sanitize and filter
        $stages = (array) $stage;
        $stages = array_filter($stages, [$this, 'isValidStage']);

        return $stages ?: [null];
    }
1027664
protected function parseConnection($connection)
    {
        $pos  = strpos($connection, '=');
        $name = substr($connection, 0, $pos);
        $dsn  = substr($connection, $pos + 1, strlen($connection));

        $pos  = strpos($dsn, ':');
        $adapter = substr($dsn, 0, $pos);

        $extras = [];
        foreach (explode(';', $dsn) as $element) {
            $parts = preg_split('/=/', $element);

            if (2 === count($parts)) {
                $extras[strtolower($parts[0])] = urldecode($parts[1]);
            }
        }
        $extras['adapter'] = $adapter;

        return [$name, $dsn, $extras];
    }
1256589
public function afterQuery(Event $event, $connection)
    {
        $profiler = $this->profiler;
        $profiler->stopProfile();
        $profile = $profiler->getLastProfile();
        $sql = $profile->getSQLStatement();
        $params = $profile->getSqlVariables();
        $params = json_encode($params, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        $executeTime = $profile->getTotalElapsedSeconds();
        $profiler->reset();
        $this->di->getLogger()->info("[$sql] [$params] [$executeTime]");
    }
40916
protected function checkSlave(Connection $connection)
    {
        $paused = 0;

        while (($lag = $this->getLag($connection)) > $this->options['max_lag']) {
            $this->paused = true;
            $for = $this->options['pause_lag'];

            $this->logger->notice('Chunk detected lag of {lag} on {database}, pausing for {for}', [
                'lag'      => $lag,
                'database' => sprintf('%s/%s', $connection->getHost(), $connection->getDatabase()),
                'for'      => $for
            ]);

            usleep($for);
            $paused += $for;

            if ($paused > $this->options['max_pause_lag']) {
                if ($this->options['continue_lag']) {
                    break;
                } else {
                    throw new RuntimeException('Slave lag did not recover after processing chunk. Aborting.');
                }
            }
        }
    }
669308
public static function getQueryBuilder(Connection $connection)
    {
        switch ($connection->getDriver()->getName()) {
            case 'pdo_mysql':
                $adapter = new Database\Mysql\Adapter($connection);
                break;

            case 'pdo_sqlite':
                $adapter = new Database\Sqlite\Adapter($connection);
                break;

            case 'pdo_pgsql':
                $adapter = new Database\Pgsql\Adapter($connection);
                break;

            default:
                throw new NotSupportedException('Unknown driver');
        }

        $lookupBuilder = new LookupBuilder();
        $lookupBuilder->addLookupCollection($adapter->getLookupCollection());

        return new QueryBuilder($connection, $adapter, $lookupBuilder);
    }
1266041
public function makePayload($load = true)
    {
        $request = Request::i();
        $response = Response::i();

        if ($load) {
            $request->load();
            $response->load();

            $stage = $this->getRequest()->getStage();

            if (is_array($stage)) {
                $request->setSoftStage($stage);
            }
        }

        return [
            'request' => $request,
            'response' => $response
        ];
    }
56681
public function getConnection($connection, $server = null)
    {
        $connectionKey = $this->credentials->sanitizeConnection($connection, $server);
        $handle = $connectionKey->toHandle();

        $connections = $this->getConnections();
        if (!$connections->has($handle)) {
            throw new ConnectionException('Invalid connection: '.$handle);
        }

        return $connections[$handle];
    }
1306659
public function connection($connection = null)
    {
        $type = $connection ?? $this->defaultConnection;

        if (!isset($this->connection[$type]))
        {
            $slice = $this->slice->getSlice($type);

            $key     = $slice->getRequired('adapter');
            $adapter = $this->adapters[$key];

            $this->adapterProviders[$type] = new $adapter();

            $this->adapterProviders[$type]->setHost($slice->getData('host'));
            $this->adapterProviders[$type]->setPort($slice->getData('port'));

            if (method_exists($this->adapterProviders[$type], 'setPath'))
            {
                $this->adapterProviders[$type]->setPath($slice->getData('path'));
            }

            $this->adapterProviders[$type]->setDbName($slice->getData('database'));

            $this->adapterProviders[$type]->setConnection($this);

            $this->adapterProviders[$type]->setPDOClass(Connection::class);

            $options = [
                Connection::ATTR_DEFAULT_FETCH_MODE => Connection::FETCH_ASSOC,
                //Connection::ATTR_EMULATE_PREPARES   => true,
                //Connection::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
                //Connection::ATTR_PERSISTENT         => false,
                //Connection::MYSQL_ATTR_INIT_COMMAND       => 'SET NAMES utf8mb4'
            ];

            if ($this->adapterProviders[$type]->name() !== 'sqlite')
            {
                $options[Connection::ATTR_ERRMODE] = Connection::ERRMODE_EXCEPTION;
            }

            $this->connection[$type] = $this->adapterProviders[$type]->connection(
                $slice->getData('username'),
                $slice->getData('password'),
                $slice->getData('options', $options)
            );
        }

        return $this->connection[$type];
    }
475651
protected function checkConnections($connection)
    {
        $connections = $connection->getConnectionManager()->count();

        if ($connections > $this->options['connections']) {
            $this->limit($connection, 'Max connections');
        }
    }
430824
protected function getSequenceName(Connection $connection, $tableName)
    {
        $PkColumns = $connection->query("SELECT a.attname, format_type(a.atttypid, a.atttypmod) AS data_type
            FROM   pg_index i
            JOIN   pg_attribute a ON a.attrelid = i.indrelid
                                 AND a.attnum = ANY(i.indkey)
            WHERE  i.indrelid = :table_name::regclass
            AND    i.indisprimary;", [':table_name' => $tableName])->fetchAll(\PDO::FETCH_ASSOC);
        $PkColumnsCount = count($PkColumns);
        if ($PkColumnsCount != 1) {
            return null;
        }

        return $connection->query('select pg_get_serial_sequence(:table_name, :column_name)', [':table_name' => $tableName, ':column_name' => $PkColumns[0]['attname']])->fetchScalar();
    }
216702
public function client($connection = null)
    {
        $connection = $connection ?: $this->setting('connection');
        return $this->git->connection($connection);
    }
857299
static function getConnections() {
		foreach (self::$parameters as $name => $params) {
			self::connect($name);
		}
		return self::$connections;
	}
588124
public function onGatewayClose($connection)
    {
        $addr = $connection->remoteAddress;
        unset($this->gatewayConnections[$addr], $this->_connectingGatewayAddresses[$addr]);
        if (isset($this->_gatewayAddresses[$addr]) && !isset($this->_waitingConnectGatewayAddresses[$addr])) {
            Timer::add(1, array($this, 'tryToConnectGateway'), array($addr), false);
            $this->_waitingConnectGatewayAddresses[$addr] = $addr;
        }
    }
704407
public function getConnection($connection = null)
    {
        if ($connection) {
            $this->connection = $connection;
        }

        return Redis::connection($this->connection);
    }
742615
def get_stages(self):
        '''
        
        '''
        sequence = self.get_sequence()
        return {
            'current': [e.dst.get_name() for e in sequence],
            'stages': {e.src.get_name(): [e.dst.get_name()] for e in sequence}
        }
178667
public function askSlotsMap(Client $connection = null)
    {
        $connection = $connection ?? $this->getRandomConnection();
        if (!$connection) {
            return [];
        }

        $response = $this->queryClusterNodeForSlotsMap($connection);

        $this->hosts = $this->slotsMap = [];
        foreach ($response as $slots) {
            // We only support master servers for now, so we ignore subsequent
            // elements in the $slots array identifying slaves.
            [$start, $end, $master] = $slots;

            if ($master[0] === '') {
                $this->setSlots($start, $end, (string) $connection);
            } else {
                $this->setSlots($start, $end, "{$master[0]}:{$master[1]}");
            }
        }

        return $this->slotsMap;
    }
447252
protected function _getBaseUrl(Connection $connection): string
    {
        // If url is set, url is taken. Otherwise port, host and path
        $url = $connection->hasConfig('url') ? $connection->getConfig('url') : '';

        if (!empty($url)) {
            $baseUri = $url;
        } else {
            $baseUri = (string) Uri::fromParts([
                'scheme' => $this->_scheme,
                'host' => $connection->getHost(),
                'port' => $connection->getPort(),
                'path' => \ltrim('/', $connection->getPath()),
            ]);
        }

        return \rtrim($baseUri, '/');
    }