- $ldapConnection = $this->ldap->connect($server['host'], $server['port']);
-
- if (!$ldapConnection) {
- throw new LdapException(trans('errors.ldap_cannot_connect'));
- }
-
- // Set any required options
- if ($this->config['version']) {
- $this->ldap->setVersion($ldapConnection, $this->config['version']);
- }
-
- // Start and verify TLS if it's enabled
- if ($this->config['start_tls']) {
- try {
- $tlsStarted = $this->ldap->startTls($ldapConnection);
- } catch (ErrorException $exception) {
- $tlsStarted = false;
- }
-
- if (!$tlsStarted) {
- throw new LdapException('Could not start TLS connection');
- }
- }
-
- return $ldapConnection;