app\models\forms\LdapLoginForm::getConn PHP Method

getConn() private static method

private static getConn ( )
    private static function getConn()
    {
        if (self::$_conn !== null) {
            return self::$_conn;
        }
        $host = isset(self::$_configs['host']) == false ? 'localhost' : self::$_configs['host'];
        $port = 389;
        if (isset(self::$_configs['port']) == true) {
            if (is_numeric(self::$_configs['port']) == false) {
                throw new \Exception(yii::t('walle', 'illegal service port', array('service' => 'Ldap', 'port' => self::$_configs['port'])));
            }
            $port = (int) self::$_configs['port'];
        }
        if (isset(self::$_configs['ssl']) == true && self::$_configs['ssl'] == true) {
            $host = 'ldaps://' . $host;
        }
        if (isset(self::$_configs['accountBase']) == false || empty(self::$_configs['accountBase']) == true) {
            throw new \Exception(yii::t('walle', 'account base dn could not defined'));
        }
        if (isset(self::$_configs['accountPattern']) == false || empty(self::$_configs['accountPattern']) == true) {
            throw new \Exception(yii::t('walle', 'account pattern could not defined'));
        }
        self::$_conn = ldap_connect($host, $port);
        unset($host);
        ldap_set_option(self::$_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
        ldap_set_option(self::$_conn, LDAP_OPT_REFERRALS, 0);
        return self::$_conn;
    }