Connect

@return null
490116
public function actionConnect()
    {
        $token = false;
        $success = false;
        $error = false;
        $errorMsg = false;

        // handle
        $providerHandle = craft()->httpSession->get('oauth.handle');

        if(!$providerHandle)
        {
            $providerHandle = craft()->request->getParam('provider');

            if($providerHandle)
            {
                craft()->httpSession->add('oauth.handle', $providerHandle);
            }
            else
            {
                throw new Exception("Couldn’t retrieve OAuth provider.");
            }
        }

        // session vars
        $scope = craft()->httpSession->get('oauth.scope');
        $authorizationOptions = craft()->httpSession->get('oauth.authorizationOptions');
        $referer = craft()->httpSession->get('oauth.referer');

        OauthPlugin::log('OAuth Connect - Connect with `'.$providerHandle.'` OAuth provider'."\r\n".

	        'Session Data: '.print_r([
		        'oauth.referer' => $referer,
		        'oauth.scope' => $scope,
		        'oauth.authorizationOptions' => $authorizationOptions
	        ], true)."\r\n"
	    , LogLevel::Info);


        try
        {
            // provider
            $provider = craft()->oauth->getProvider($providerHandle);

            // connect
            $tokenResponse = $provider->connect([
                'scope' => $scope,
                'authorizationOptions' => $authorizationOptions,
            ]);

            // token
            if($tokenResponse)
            {
                $token = OauthHelper::realTokenToArray($tokenResponse);
            }
            else
            {
                throw new Exception("Error with token");
            }

            $success = true;
        }
        catch(\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e)
        {
	        $error = true;

        	$errorMsg = $e->getMessage();

	        if($errorMsg == 'invalid_client')
	        {
		        $errorMsg = Craft::t("Invalid OAuth client ID or secret.");
	        }
        }
        catch(\Exception $e)
        {
            $error = true;
            $errorMsg = $e->getMessage();
        }


        // build up response

        $response = array(
            'error' => $error,
            'errorMsg' => $errorMsg,
            'success' => $success,
            'token' => $token,
        );

        OauthPlugin::log("OAuth Connect - Response\r\n".
	        'Session Data: '.print_r([
		        'oauth.response' => $response,
	        ], true)."\r\n"
	    , LogLevel::Info);

        craft()->httpSession->add('oauth.response', $response);

        // redirect
        $this->redirect($referer);
    }
1026155
protected function connect()
    {
        try {
            // Loop until we connect
            while (!$this->isConnected()) {
                // Assume we will connect, until we dont
                $this->setIsConnected(true);

                // Connect the socket
                $this->io->connect();

                $this->channels = array();
                // The connection object itself is treated as channel 0
                parent::__construct($this, 0);

                $this->input = new AMQPReader(null, $this->io);

                $this->write($this->amqp_protocol_header);
                $this->wait(array($this->waitHelper->get_wait('connection.start')),false,$this->connection_timeout);
                $this->x_start_ok(
                    $this->getLibraryProperties(),
                    $this->login_method,
                    $this->login_response,
                    $this->locale
                );

                $this->wait_tune_ok = true;
                while ($this->wait_tune_ok) {
                    $this->wait(array(
                        $this->waitHelper->get_wait('connection.secure'),
                        $this->waitHelper->get_wait('connection.tune')
                    ));
                }

                $host = $this->x_open($this->vhost, '', $this->insist);
                if (!$host) {
                    //Reconnected
                    $this->io->reenableHeartbeat();
                    return null; // we weren't redirected
                }

                $this->setIsConnected(false);
                $this->closeChannels();

                // we were redirected, close the socket, loop and try again
                $this->close_socket();
            }

        } catch (\Exception $e) {
            // Something went wrong, set the connection status
            $this->setIsConnected(false);
            $this->closeChannels();
            $this->close_input();
            $this->close_socket();
            throw $e; // Rethrow exception
        }
    }
734709
public static function connect()
    {   
        self::getEnv();
        return new PDO(self::$driver.':host='.self::$host.';dbname='.self::$dbname, self::$user, self::$pass);
    }
973569
public function connect() 
	{
		if($this->getResource()) {
			$this->close();
		}

		$resource = curl_init();

		curl_setopt($resource,CURLOPT_CONNECTTIMEOUT,$this->getTimeout());
	
		$this->setResource($resource);
		parent::connect();
		return $this;
	}
1281265
public function connect()
	{
		//Attempt to connect to host
		$link = ssh2_connect($this->_config['host'], $this->_config['port']);
		
		//If host connection fails, throw exception
		if(!$link)
		{
			throw new \Exception('Unable to connect to '.$host.' on port '.$port);
		}
		else
		{
			//Assign the connection link to the class property
			$this->_conn_link = $link;
			
			//If host fingerprint is not NULL, attempt to verify fingerprint
			if(!is_null($this->_config['host_fingerprint'])) 
			{
				$verify = $this->verify_host_fingerprint();
				
				//If the fingerprint is not verified, throw exception
				if(!$verify)
				{
					throw new \Exception('Unable to verify host fingerprint');
				}
			}
		}
		
		//Attempt to login user
		if($this->_config['authentication_method'] == 'KEY')
		{
			$this->_connected = $this->login_key();
		}
		else
		{
			$this->_connected = $this->login_password();
		}

		$this->_connected && $this->_sftp = ssh2_sftp($link);
	}
434509
public function connect()
    {
        $this->initialize();

        $riakClient = $this->riakClient;
        return $this->retry(function() use ($riakClient) {
            return $riakClient->connect();
        });
    }
444778
public function connect()
    {
        $this->conn = imap_open($this->server, $this->user, $this->pass);
    }
1246503
private function connect()
    {
        if (!$this->isConnected) {
            parent::__construct(
                $this->dsn,
                $this->server->getUsername(),
                $this->server->getPassword(),
                $this->driverOptions
            );
            parent::setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            parent::setAttribute(
                PDO::ATTR_STATEMENT_CLASS,
                [__NAMESPACE__ . '\\' . self::PDO_STATEMENT_CLASS, [$this]]
            );

            $this->isConnected = true;
        }
    }
199780
public function connect() {
        $readWriteTimeout = max($this->read_timeout, $this->write_timeout); //?
        try {
            $this->connection = new AMQPStreamConnection(
                $this->host,
                $this->port,
                $this->login,
                $this->password,
                $this->vhost,
                false,                      //insist
                'AMQPLAIN',                 //login method
                null,                       //login response
                'en_US',                    //locale
                $this->connect_timeout,     // connect_timeout
                $readWriteTimeout,          // read_write_timeout
                null,                       // context
                $this->keepalive,           // keepalive
                $this->heartbeat            // heartbeat configuration
            );

            //Several exception types might be thrown
        } catch (Exception $e){
            throw new AMQPConnectionException($e->getMessage(), $e->getCode(), $e->getPrevious());
        }
    }
605220
public function connect()
        {

            $connect = ftp_connect($this->getHost());
            $login = ftp_login($connect, $this->getUsername(), $this->getPassword());

            if(!$login || !$connect){
                return false;
            }else{
                $this->setConnect($connect);
                return $this;
            }

        }
677475
public function connect()
     {
        $oldErrorReporting = error_reporting(0);

        $mysqli = new mysqli(
            $this->getConfig()->host,
            $this->getConfig()->username,
            $this->getConfig()->password,
            $this->getConfig()->database,
            $this->getConfig()->port,
            $this->getConfig()->socket
        );

        error_reporting($oldErrorReporting);

        if (mysqli_connect_errno()) {
            throw new RuntimeException('Connect failed: (' . mysqli_connect_errno() . ') ' . mysqli_connect_error(), mysqli_connect_errno());
        }

        // If supported, request real datatypes from MySQL instead of returning everything as a string.
        if (defined('MYSQLI_OPT_INT_AND_FLOAT_NATIVE')) {
            $mysqli->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, true);
        }

        $this->_connection = $mysqli;
        $this->_connected  = true;

        return $this;
    }
123256
public function _connect()
    {
        if ($this->_connection) {
            return;
        }
        parent::_connect();

        $this->getConnection()->setAttribute(Zend_Db::ATTR_STRINGIFY_FETCHES, true);

        try {
            if ($this->_serverType === null) {
                $server = substr($this->getConnection()->getAttribute(PDO::ATTR_SERVER_INFO), 0, 3);

                switch ($server) {
                    case 'DB2':
                        $this->_serverType = new Zend_Db_Adapter_Pdo_Ibm_Db2($this);

                        // Add DB2-specific numeric types
                        $this->_numericDataTypes['DECFLOAT'] = Zend_Db::FLOAT_TYPE;
                        $this->_numericDataTypes['DOUBLE']   = Zend_Db::FLOAT_TYPE;
                        $this->_numericDataTypes['NUM']      = Zend_Db::FLOAT_TYPE;

                        break;
                    case 'IDS':
                        $this->_serverType = new Zend_Db_Adapter_Pdo_Ibm_Ids($this);

                        // Add IDS-specific numeric types
                        $this->_numericDataTypes['SERIAL']       = Zend_Db::INT_TYPE;
                        $this->_numericDataTypes['SERIAL8']      = Zend_Db::BIGINT_TYPE;
                        $this->_numericDataTypes['INT8']         = Zend_Db::BIGINT_TYPE;
                        $this->_numericDataTypes['SMALLFLOAT']   = Zend_Db::FLOAT_TYPE;
                        $this->_numericDataTypes['MONEY']        = Zend_Db::FLOAT_TYPE;

                        break;
                    }
            }
        } catch (PDOException $e) {
            /** @see Zend_Db_Adapter_Exception */
            // require_once 'Zend/Db/Adapter/Exception.php';
            $error = strpos($e->getMessage(), 'driver does not support that attribute');
            if ($error) {
                throw new Zend_Db_Adapter_Exception("PDO_IBM driver extension is downlevel.  Please use driver release version 1.2.1 or later", 0, $e);
            } else {
                throw new Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e);
            }
        }
    }
1125734
public function connect()
    {
        try {
            if (empty($this->connectioId)) {
                $this->addHeader();
                $connectionResult  = $this->getSoap()->Connect();
                $this->connectioId = $connectionResult->ConnectResult;
            }
            $result = true;
        } catch (\SoapFault $ex) {
            $result = false;
        }
        return $result;
    }
1029994
public function connect()
    {
        // Lookup Adapter-Specific Connection Properties
        $strServer = $this->Server;
        $strName = $this->Database;
        $strUsername = $this->Username;
        $strPassword = $this->Password;
        $strPort = $this->Port;

        // Connect to the Database Server
        $this->objPgSql = pg_connect(sprintf('host=%s dbname=%s user=%s password=%s port=%s', $strServer, $strName,
            $strUsername, $strPassword, $strPort));

        if (!$this->objPgSql) {
            throw new \Exception("Unable to connect to Database", -1, null);
        }

        // Update Connected Flag
        $this->blnConnectedFlag = true;
    }
777851
public function connect()
  {
    if($this->stream !== null) return;

    $host     = strval($this->config["host"]);
    $port     = strval($this->config["port"]);
    $timeout  = intval($this->config["timeout"]);
    $blocking = intval($this->config["blocking"]);

    if(empty($this->config["ssh"]))
    {
      $address = "tcp://" . (strstr($host, ":") !== FALSE ? "[" . $host . "]" : $host) . ":" . $port;
      $options = empty($this->config["tls"]) ? array() : array("ssl" => array("allow_self_signed" => TRUE, "verify_peer" => FALSE, "verify_peer_name" => FALSE));

      $this->stream = @stream_socket_client($address, $errno, $errstr, $this->config["timeout"], STREAM_CLIENT_CONNECT, stream_context_create($options));

      if($this->stream === FALSE)
      {
        throw new TeamSpeak3_Transport_Exception(TeamSpeak3_Helper_String::factory($errstr)->toUtf8()->toString(), $errno);
      }

      if(!empty($this->config["tls"]))
      {
        stream_socket_enable_crypto($this->stream, TRUE, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
      }
    }
    else
    {
      $this->session = @ssh2_connect($host, $port);

      if($this->session === FALSE)
      {
        throw new TeamSpeak3_Transport_Exception("failed to establish secure shell connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "'");
      }

      if(!@ssh2_auth_password($this->session, $this->config["username"], $this->config["password"]))
      {
        throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid loginname or password", 0x208);
      }

      $this->stream = @ssh2_shell($this->session, "raw");

      if($this->stream === FALSE)
      {
        throw new TeamSpeak3_Transport_Exception("failed to open a secure shell on server '" . $this->config["host"] . ":" . $this->config["port"] . "'");
      }
    }

    @stream_set_timeout($this->stream, $timeout);
    @stream_set_blocking($this->stream, $blocking ? 1 : 0);
  }
336677
private function Connect()
    {
        $this->conn = parent::getConn();
        $this->delete = $this->conn->prepare($this->delete);
    }
296838
public static function connect()
  {
    try
    {
        /**
         * Check if the APP_ENV variable is set. If not found or it has a value of 'local'
         * then load variable values from app's .env file. Else load server server environment variables.
         */
        if (! getenv('APP_ENV') || getenv('APP_ENV')=="local") {
            $dotenv = new Dotenv($_SERVER['DOCUMENT_ROOT']);
            $dotenv->load();
        }

        $host = getenv('DB_HOST');
        $db = getenv('DB_NAME');
        $username = getenv('DB_USERNAME');
        $password = getenv('DB_PASSWORD');
        $driver = getenv('DB_DRIVER');

        return new PDO($driver.':host='.$host.';dbname='.$db, $username, $password);
    }
    catch (PDOException $e)
    {
        return $e->getMessage();
    }
  }