Get SSH connection

@return Connection
@throws \Exception
195405
public function getSshConnection($multiplex=null)
    {
        $jumpHost = $this->getJumpHost();
        return new Connection(
            $this->getDefaultUsername(),
            $jumpHost ? $this->getPrivateIpAddress() : $this->getConnectionIp(),
            $this->getPrivateKey(),
            $jumpHost,
            !is_null($multiplex) ? $multiplex : $this->multiplexSshConnection
        );
    }
1072417
public function getConnection()
    {
        if ($this->conn === false) {
            $this->conn = null;
            if ($this->url) {
                $buf = "Using database settings:\n"
                    . " URL: " . $this->url . "\n"
                    . ($this->userId ? " user: " . $this->userId . "\n" : "")
                . ($this->password ? " password: " . $this->password . "\n" : "");

                $this->log($buf, Project::MSG_VERBOSE);

                // Set user + password to null if they are empty strings
                if (!$this->userId) {
                    $this->userId = null;
                }
                if (!$this->password) {
                    $this->password = null;
                }
                try {
                    $this->conn = new PDO($this->url, $this->userId, $this->password);
                    $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                } catch (PDOException $x) {
                    $this->log("Unable to create a PDO connection: " . $x->getMessage(), Project::MSG_WARN);
                }
            }
        }

        return $this->conn;
    }
18588
public function getConnection() {
		try {
			$pdo = null;

			switch($this->driver){
				case "pdo_mysql": // MySQL Database
					$pdo = new PDO("mysql:host=".$this->host.";dbname=".$this->database.";charset=utf8", $this->user, $this->password);
					break;
				case "pdo_sqlserver": // SQL Server Database
					$pdo = new PDO("sqlsrv:Server=".$this->host.";Database=".$this->database, $this->user, $this->password);
					break;
				case "pdo_sqlite": // SQLite Database
				    $pdo = new PDO("sqlite:{$this->database}");
					break;
				case "pdo_pgsql": // PostgreSQL Database
				    $pdo = new PDO("pgsql:dbname={$this->database};host={$this->host}", $this->user, $this->password);
				    break;
				case "pdo_oci": // Oracle Database
					$tns = "oci:dbname=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (Host = {$this->host}) (Port = {$this->port}))) (CONNECT_DATA = (SERVICE_NAME = {$this->database})))";
					$pdo = new PDO($tns, $this->user, $this->password);
					break;
				default:
					throw new  Exception("Database driver not defined");
				}

				if (count($this->attributes) > 0) {
					foreach ($this->attributes as $key => $value) {
						$pdo->setAttribute($key, $value);
					}
				}

				$this->pdo = $pdo;

				return $pdo;

		} catch (PDOException $e) {
			throw new PDOException('Unable to connect to database, errorMessage = '.$e->getMessage());
		} catch (Exception $e) {
			throw new Exception('Internal error, errorMessage = '.$e->getMessage());
		}
	}
511831
protected SshConnection getConnection() throws IOException {
        return SshConnectionFactory.getConnection(gerritHostName, gerritSshPort, gerritProxy,
                authentication, connectionTimeout);
    }
162908
private function getConnection()
    {
        if (!isset($this->connections[$this->getDriver()])) {
            $this->connections[$this->getDriver()] = DriverManager::getConnection(
                array(
                    'driver' => $this->getDriver(),
                    'host' => str_replace('pdo_', '', $this->getDriver()),
                    'dbname' => 'list',
                    'user' => 'list',
                    'password' => 'list',
                    // 'unix_socket' => '/tmp/mysql.sock',
                )
            );
        }

        return $this->connections[$this->getDriver()];
    }
1330997
protected function getClient()
    {
        if ($this->client instanceof ClientInterface) {
            return $this->client;
        }

        if (empty($this->apiKey)) {
            throw new Exception('Use of connector not possible without API key', Exception::INVALID_API_KEY);
        }

        $this->client = new Client([
            'connect_timeout' => 10,
            'base_uri' => $this->serviceUrl,
            'headers' => array_merge($this->extraHeaders, [
                'User-Agent' => 'Connector-PHP/2',
                'X-Api-Key' => $this->apiKey,
            ])
        ]);

        return $this->client;
    }
1337263
public function getConnection()
    {
        // Initiate connection if not exist
        if ($this->connection === null) {
            $this->connection = DriverManager::getConnection($this->dsn);
        }

        return $this->connection;
    }
1320933
public function getConnection()
    {
        if (! $this->connection) {
            list($dns, $username, $password) = $this->connectionString();

            $this->setConnection(new \PDO($dns, $username, $password));
        }

        return $this->connection;
    }
1129735
protected function getTransport()
    {
        $ssh = 'ssh';

        // Get port
        if ($port = $this->getOption('port', true)) {
            $ssh .= ' -p '.$port;
        }

        // Get key
        $key = $this->credentials->getServerCredentials();
        $key = Arr::get($key, 'key');
        if ($key) {
            $ssh .= ' -i "'.$key.'"';
        }

        return $ssh;
    }
1241851
protected function getClient()
	{
		$this->client->timeout       = $this->timeout;
		$this->client->sslVerifyPeer = $this->sslVerifyPeer;

		return $this->client;
	}
600305
protected static function getConnection() {
        if (self::$db === null) {
            try {
                self::$db = new PDO(self::$dsn, self::$user, self::$password);
                self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            } catch (PDOException $e) {
                throw new Exception("DJJob couldn't connect to the database. PDO said [{$e->getMessage()}]");
            }
        }
        return self::$db;
    }
591446
private SshConnection connect() {
        if (sshConnection != null && sshConnection.isConnected()) {
            return sshConnection;
        }
        while (!shutdownInProgress) {
            SshConnection ssh = null;
            try {
                logger.debug("Connecting...");
                ssh = SshConnectionFactory.getConnection(gerritHostName, gerritSshPort, gerritProxy,
                        authentication, authenticationUpdater);
                gerritVersion  = formatVersion(ssh.executeCommand("gerrit version"));
                logger.debug("connection seems ok, returning it.");
                return ssh;
            } catch (SshConnectException sshConEx) {
                logger.error("Could not connect to Gerrit server! "
                        + "Host: {} Port: {}", gerritHostName, gerritSshPort);
                logger.error(" Proxy: {}", gerritProxy);
                logger.error(" User: {} KeyFile: {}", authentication.getUsername(), authentication.getPrivateKeyFile());
                logger.error("ConnectionException: ", sshConEx);
            } catch (SshAuthenticationException sshAuthEx) {
                logger.error("Could not authenticate to Gerrit server!"
                        + "\n\tUsername: {}\n\tKeyFile: {}\n\tPassword: {}",
                        new Object[]{authentication.getUsername(),
                                authentication.getPrivateKeyFile(),
                                authentication.getPrivateKeyFilePassword(), });
                logger.error("AuthenticationException: ", sshAuthEx);
            } catch (IOException ex) {
                logger.error("Could not connect to Gerrit server! "
                        + "Host: {} Port: {}", gerritHostName, gerritSshPort);
                logger.error(" Proxy: {}", gerritProxy);
                logger.error(" User: {} KeyFile: {}", authentication.getUsername(), authentication.getPrivateKeyFile());
                logger.error("IOException: ", ex);
            }

            if (ssh != null) {
                logger.trace("Disconnecting bad connection.");
                try {
                    //The ssh lib used is starting at least one thread for each connection.
                    //The thread isn't shutdown properly when the connection goes down,
                    //so we need to close it "manually"
                    ssh.disconnect();
                } catch (Exception ex) {
                    logger.warn("Error when disconnecting bad connection.", ex);
                } finally {
                    ssh = null;
                }
            }

            if (!shutdownInProgress) {
                //If we end up here, sleep for a while and then go back up in the loop.
                logger.trace("Sleeping for a bit.");
                try {
                    Thread.sleep(CONNECT_SLEEP);
                } catch (InterruptedException ex) {
                    logger.warn("Got interrupted while sleeping.", ex);
                }
            }
        }
        return null;
    }
1324127
public static function connect() {
		if (self::$memcached === null) {
			$config = \Skeleton\Object\Config::$cache_handler_config;
			self::$memcached = new \Memcached();
			self::$memcached->setOption(\Memcached::OPT_SERIALIZER, \Memcached::SERIALIZER_IGBINARY);
			self::$memcached->setOption(\Memcached::OPT_BINARY_PROTOCOL, true);
			self::$memcached->setOption(\Memcached::OPT_NO_BLOCK, true);
			self::$memcached->setOption(\Memcached::OPT_TCP_NODELAY, true);
			self::$memcached->addServers([
				[$config['hostname'], $config['port']]
			]);
		}

		return self::$memcached;
	}
902577
public function getConnection()
    {
        if (!$this->connection) {
            $this->connFac->setConfig($this->config);
            try {
                $this->connection = $this->connFac->create();
            } catch (PDOException $e) {
                throw new ClientException(
                    'Failed to create a MySQL connection.',
                    null,
                    $e
                );
            }
        }
        return $this->connection;
    }
588885
protected function getConnection()
    {
        $generatorConfig = $this->getGeneratorConfig();
        $database = $generatorConfig->getConfigProperty('reverse.connection');

        if (null === $database) {
            throw new BuildException('No configured connection. Please add a connection to your configuration file
            or pass a `connection` option to your command line.');
        }

        return $generatorConfig->getConnection($database);
    }
476830
protected function getConnection()
    {
        $hosts = $this->getHostList();

        while ($host = array_shift($hosts)) {
            try {
                return $this->connectSocket($host);
            } catch (ConnectionException $connectionException) {
                if (empty($hosts)) {
                    throw new ConnectionException("Could not connect to a broker", [], $connectionException);
                }
            }
        }
    }
655383
public function getConnection()
    {
        if (null === $this->connection) {
            $this->setConnection(\Doctrine_Manager::getInstance()->getCurrentConnection());
        }

        return $this->connection;
    }