Scalr\Net\Ldap\LdapClient::getConnection PHP Method

getConnection() protected method

Gets LDAP connection link identifier
protected getConnection ( ) : resource
return resource Returns LDAP connection link edentifier
    protected function getConnection()
    {
        if (!$this->conn) {
            $this->conn = ldap_connect($this->config->host, $this->config->port);
            $this->log('LDAP Server is:%s port:%s - %s', $this->config->host, $this->config->port ? $this->config->port : 'default', $this->conn ? 'OK' : 'Failed');
            if ($this->conn == false) {
                throw new Exception\LdapException(sprintf("Could not establish LDAP connection to host '%s' port '%d'", $this->config->host, $this->config->port));
            }
            //Sets protocol version
            ldap_set_option($this->conn, LDAP_OPT_PROTOCOL_VERSION, 3);
            // We need this for doing an LDAP search.
            ldap_set_option($this->conn, LDAP_OPT_REFERRALS, 0);
        }
        return $this->conn;
    }