+ // Get port from server string if specified.
+ $ldapServer = explode(':', config('services.ldap.server'));
+ $ldapConnection = ldap_connect($ldapServer[0], count($ldapServer) > 1 ? $ldapServer[1] : 389);
+
+ if ($ldapConnection === false) {
+ throw new LdapException('Cannot connect to ldap server, Initial connection failed');
+ }
+
+ // Set any required options
+ ldap_set_option($ldapConnection, LDAP_OPT_PROTOCOL_VERSION, 3); // TODO - make configurable
+
+ $this->ldapConnection = $ldapConnection;
+ return $this->ldapConnection;
+ }