class SimpleLdapConnection in Simple LDAP 8
Hierarchy
- class \Drupal\simple_ldap\SimpleLdapConnection implements SimpleLdapConnectionInterface
Expanded class hierarchy of SimpleLdapConnection
1 file declares its use of SimpleLdapConnection
- SimpleLdap.php in src/
SimpleLdap.php
1 string reference to 'SimpleLdapConnection'
1 service uses SimpleLdapConnection
File
- src/
SimpleLdapConnection.php, line 9
Namespace
Drupal\simple_ldapView source
class SimpleLdapConnection implements SimpleLdapConnectionInterface {
/**
* Simple LDAP Server Configuration
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* @var string
*/
protected $connection_string;
/**
* The LDAP link identifier
*
* @var resource
*/
private $connection;
/**
* Constructs a SimpleLdapConnection.
*
* @param ConfigFactoryInterface $config_factory
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->config = $config_factory
->get('simple_ldap.server');
$connection_prefix = $this->config
->get('encryption') === 'ssl' ? 'ldaps://' : 'ldap://';
$this->connection_string = $connection_prefix . $this->config
->get('host') . ':' . $this->config
->get('port');
}
public function __destruct() {
$this
->disconnect();
}
/**
* Connect to the Simple LDAP server based on configuration settings.
*
* @throws \Drupal\simple_ldap\SimpleLdapException
*/
public function connect() {
if ($this->connection) {
return;
}
$this->connection = @ldap_connect($this->connection_string);
// Timeout after 10 seconds if connection is unsuccessful.
@ldap_set_option($this->connection, LDAP_OPT_NETWORK_TIMEOUT, 10);
if ($this->connection === FALSE) {
throw new SimpleLdapException('Could not connect to LDAP server: ', $this->connection);
}
if ($this->config
->get('encryption') === 'tls' && ldap_start_tls($this->connection) === FALSE) {
throw new SimpleLdapException('Could not start TLS connection: ', $this->connection);
}
@ldap_set_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, 3);
@ldap_set_option($this->connection, LDAP_OPT_REFERRALS, (int) $this->config
->get('opt_referrals'));
}
/**
* Disconnect from LDAP server.
*/
public function disconnect() {
if ($this->connection && is_resource($this->connection)) {
ldap_close($this->connection);
}
$this->connection = NULL;
}
/**
* Get the LDAP link identifier for this SimpleLdapConnection
*
* @return resource
*/
public function getResource() {
return $this->connection;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SimpleLdapConnection:: |
protected | property | Simple LDAP Server Configuration | |
SimpleLdapConnection:: |
private | property | The LDAP link identifier | |
SimpleLdapConnection:: |
protected | property | ||
SimpleLdapConnection:: |
public | function |
Connect to the Simple LDAP server based on configuration settings. Overrides SimpleLdapConnectionInterface:: |
|
SimpleLdapConnection:: |
public | function |
Disconnect from LDAP server. Overrides SimpleLdapConnectionInterface:: |
|
SimpleLdapConnection:: |
public | function |
Get the LDAP link identifier for this SimpleLdapConnection Overrides SimpleLdapConnectionInterface:: |
|
SimpleLdapConnection:: |
public | function | Constructs a SimpleLdapConnection. | |
SimpleLdapConnection:: |
public | function |