8000 implement add and delete method by L0rD59 · Pull Request #1 · symfony/ldap · GitHub
[go: up one dir, main page]

Skip to content

implement add and delete method #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 46 additions & 15 deletions LdapClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function __construct($host = null, $port = 389, $version = 3, $useSsl = f
$this->useSsl = (bool) $useSsl;
$this->useStartTls = (bool) $useStartTls;
$this->optReferrals = (bool) $optReferrals;

$this->connect();
}

public function __destruct()
Expand All @@ -65,10 +67,6 @@ public function __destruct()
*/
public function bind($dn = null, $password = null)
{
if (!$this->connection) {
$this->connect();
}

if (false === @ldap_bind($this->connection, $dn, $password)) {
throw new ConnectionException(ldap_error($this->connection));
}
Expand Down Expand Up @@ -114,23 +112,56 @@ public function escape($subject, $ignore = '', $flags = 0)
return $value;
}

/**
* Add entry to the ldap.
*
* @param string $dn A LDAP dn
* @param array $entry key:value
*
* @throws \Exception.
*/
public function add($dn, $entry)
{
if(ldap_add($this->connection, $dn, $entry) === false)
{
throw new \Exception('Cannot add to ldap : '.ldap_error($this->connection));
}

return true;
}

/**
* Delete entry to the ldap.
*
* @param string $dn A LDAP dn
*
* @throws \Exception.
*/
public function delete($dn)
{
if(ldap_delete($this->connection, $dn) === false)
{
throw new \Exception('Cannot delete to ldap : '.ldap_error($this->connection));
}

return true;
}

private function connect()
{
if (!$this->connection) {
$host = $this->host;
$host = $this->host;

if ($this->useSsl) {
$host = 'ldaps://'.$host;
}
if ($this->useSsl) {
$host = 'ldaps://'.$host;
}

$this->connection = ldap_connect($host, $this->port);
$this->connection = ldap_connect($host, $this->port);

ldap_set_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $this->version);
ldap_set_option($this->connection, LDAP_OPT_REFERRALS, $this->optReferrals);
ldap_set_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $this->version);
ldap_set_option($this->connection, LDAP_OPT_REFERRALS, $this->optReferrals);

if ($this->useStartTls) {
ldap_start_tls($this->connection);
}
if ($this->useStartTls) {
ldap_start_tls($this->connection);
}
}

Expand Down
0