diff --git a/composer.json b/composer.json index e8770fb..ea9f2b6 100644 --- a/composer.json +++ b/composer.json @@ -12,9 +12,16 @@ "role": "Developer" } ], + "require": { + "php": ">=5.4.0", + "ext-ldap": "*" + }, "autoload": { "psr-0": { "LDAPi\\": "src/" - } + }, + "files": [ + "src/global_functions.php" + ] } } diff --git a/license b/license new file mode 100644 index 0000000..360bbe1 --- /dev/null +++ b/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2013 Chris Wright + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/src/LDAPi/Directory.php b/src/LDAPi/Directory.php index 41d6703..5cc8f07 100644 --- a/src/LDAPi/Directory.php +++ b/src/LDAPi/Directory.php @@ -1,429 +1,384 @@ link) { - throw new UnavailableException('An active connection to the directory is not available'); - } + if (!$this->link) { + throw new UnavailableException('An active connection to the directory is not available'); } + } - private function checkBound() - { - if (!$this->bound) { - throw new UnavailableException('An active bound connection to the directory is not available'); - } + private function checkBound() + { + if (!$this->bound) { + throw new UnavailableException('An active bound connection to the directory is not available'); } + } - private function createResultSet($result) - { - return new ResultSet($this->link, $result); - } + private function createResultSet($result) + { + return new ResultSet($this->link, $result); + } - public function __destruct() - { - if ($this->bound) { - $this->unbind(); - } + public function __destruct() + { + if ($this->bound) { + $this->unbind(); } + } - /** - * @param string $dn - * @param array $entry - * @throws UnavailableException - * @throws WriteFailureException - */ - public function add($dn, array $entry) - { - $this->checkBound(); - - if (!@ldap_add($this->link, $dn, $entry)) { - throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); - } - } + /** + * @param string $dn + * @param array $entry + * @throws UnavailableException + * @throws WriteFailureException + */ + public function add($dn, array $entry) + { + $this->checkBound(); - /** - * @param string $dn - * @param string $password - * @throws UnavailableException - * @throws BindFailureException - */ - public function bind($dn = null, $password = null) - { - $this->checkConnected(); - - if (!@ldap_bind($this->link, $dn, $password)) { - throw new BindFailureException(ldap_error($this->link), ldap_errno($this->link)); - } - - $this->bound = true; + if (!ldap_add($this->link, $dn, $entry)) { + throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } - /** - * @param string $dn - * @param string $attribute - * @param mixed $value - * @return bool - * @throws UnavailableException - * @throws ReadFailureException - */ - public function compare($dn, $attribute, $value) - { - $this->checkBound(); - - if (-1 === $result = @ldap_compare($this->link, $dn, $entry)) { - throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); - } - - return $result; - } + /** + * @param string $dn + * @param string $password + * @throws UnavailableException + * @throws BindFailureException + */ + public function bind($dn = null, $password = null) + { + $this->checkConnected(); - /** - * @param string $host - * @param int $port - * @throws AlreadyAvailableException - * @throws ConnectFailureException - */ - public function connect($host, $port = 389) - { - if ($this->link) { - throw new AlreadyAvailableException('An active connection to the directory is already available'); - } - - if (!$this->link = @ldap_connect($host, $port)) { - throw new ConnectFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + if (!ldap_bind($this->link, $dn, $password)) { + throw new BindFailureException(ldap_error($this->link), ldap_errno($this->link)); } - /** - * @param int $pageSize - * @param bool $isCritical - * @param string $cookie - * @throws UnavailableException - * @throws PaginationFailureException - */ - public function controlPagedResult($pageSize, $isCritical = false, $cookie = '') - { - $this->checkBound(); - - if (!@ldap_control_paged_result($this->link, $pageSize, $isCritical, $cookie)) { - throw new PaginationFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + $this->bound = true; + } + + /** + * @param string $dn + * @param string $attribute + * @param mixed $value + * @return bool + * @throws UnavailableException + * @throws ReadFailureException + */ + public function compare($dn, $attribute, $value) + { + $this->checkBound(); + + if (-1 === $result = ldap_compare($this->link, $dn, $entry)) { + throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); } - /** - * @param string $dn - * @throws UnavailableException - * @throws WriteFailureException - */ - public function delete($dn) - { - $this->checkBound(); - - if (!@ldap_delete($this->link, $dn)) { - throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + return $result; + } + + /** + * @param string $host + * @param int $port + * @throws AlreadyAvailableException + * @throws ConnectFailureException + */ + public function connect($host, $port = 389) + { + if ($this->link) { + throw new AlreadyAvailableException('An active connection to the directory is already available'); } - /** - * @param int $opt - * @return mixed - * @throws UnavailableException - * @throws OptionFailureException - */ - public function getOption($opt) - { - $this->checkConnected(); - - if (!@ldap_get_option($this->link, $opt, $value)) { - throw new OptionFailureException(ldap_error($this->link), ldap_errno($this->link)); - } - - return $value; + if (!$this->link = ldap_connect($host, $port)) { + throw new ConnectFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } + + /** + * @param int $pageSize + * @param bool $isCritical + * @param string $cookie + * @throws UnavailableException + * @throws PaginationFailureException + */ + public function controlPagedResult($pageSize, $isCritical = false, $cookie = '') + { + $this->checkBound(); - /** - * @param string $dn - * @param string $filter - * @param array $attributes - * @param bool $attrsOnly - * @param int $sizeLimit - * @param int $timeLimit - * @param int $deRef - * @return ResultSet - * @throws UnavailableException - * @throws ReadFailureException - */ - public function listChildren($dn, $filter, array $attributes = null, $attrsOnly = false, $sizeLimit = 0, $timeLimit = 0, $deRef = LDAP_DEREF_NEVER) - { - $this->checkBound(); - - if (!$result = @ldap_list($this->link, $dn, $filter, $attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { - throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); - } - - return $this->createResultSet($result); + if (!ldap_control_paged_result($this->link, $pageSize, $isCritical, $cookie)) { + throw new PaginationFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } - /** - * @param string $dn - * @param array $entry - * @throws UnavailableException - * @throws WriteFailureException - */ - public function modAdd($dn, array $entry) - { - $this->checkBound(); - - if (!@ldap_mod_add($this->link, $dn, $entry)) { - throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + /** + * @param string $dn + * @throws UnavailableException + * @throws WriteFailureException + */ + public function delete($dn) + { + $this->checkBound(); + + if (!ldap_delete($this->link, $dn)) { + throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } - /** - * @param string $dn - * @param array $entry - * @throws UnavailableException - * @throws WriteFailureException - */ - public function modDel($dn, array $entry) - { - $this->checkBound(); - - if (!@ldap_mod_del($this->link, $dn, $entry)) { - throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + /** + * @param int $opt + * @return mixed + * @throws UnavailableException + * @throws OptionFailureException + */ + public function getOption($opt) + { + $this->checkConnected(); + + if (!ldap_get_option($this->link, $opt, $value)) { + throw new OptionFailureException(ldap_error($this->link), ldap_errno($this->link)); } - /** - * @param string $dn - * @param array $entry - * @throws UnavailableException - * @throws WriteFailureException - */ - public function modReplace($dn, array $entry) - { - $this->checkBound(); - - if (!@ldap_mod_replace($this->link, $dn, $entry)) { - throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + return $value; + } + + /** + * @param string $dn + * @param string $filter + * @param array $attributes + * @param bool $attrsOnly + * @param int $sizeLimit + * @param int $timeLimit + * @param int $deRef + * @return ResultSet + * @throws UnavailableException + * @throws ReadFailureException + */ + public function listChildren($dn, $filter, array $attributes = null, $attrsOnly = false, $sizeLimit = 0, $timeLimit = 0, $deRef = LDAP_DEREF_NEVER) + { + $this->checkBound(); + + if (!$result = ldap_list($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { + throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); } - /** - * @param string $dn - * @param array $entry - * @throws UnavailableException - * @throws WriteFailureException - */ - public function modify($dn, array $entry) - { - $this->checkBound(); - - if (!@ldap_modify($this->link, $dn, $entry)) { - throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + return $this->createResultSet($result); + } + + /** + * @param string $dn + * @param array $entry + * @throws UnavailableException + * @throws WriteFailureException + */ + public function modAdd($dn, array $entry) + { + $this->checkBound(); + + if (!ldap_mod_add($this->link, $dn, $entry)) { + throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } + + /** + * @param string $dn + * @param array $entry + * @throws UnavailableException + * @throws WriteFailureException + */ + public function modDel($dn, array $entry) + { + $this->checkBound(); - /** - * @param string $dn - * @param string $filter - * @param array $attributes - * @param bool $attrsOnly - * @param int $sizeLimit - * @param int $timeLimit - * @param int $deRef - * @return ResultSet - * @throws UnavailableException - * @throws ReadFailureException - */ - public function read($dn, $filter, array $attributes = null, $attrsOnly = false, $sizeLimit = 0, $timeLimit = 0, $deRef = LDAP_DEREF_NEVER) - { - $this->checkBound(); - - if (!$result = @ldap_read($this->link, $dn, $filter, $attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { - throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); - } - - return $this->createResultSet($result); + if (!ldap_mod_del($this->link, $dn, $entry)) { + throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } + + /** + * @param string $dn + * @param array $entry + * @throws UnavailableException + * @throws WriteFailureException + */ + public function modReplace($dn, array $entry) + { + $this->checkBound(); - /** - * @param string $dn - * @param string $newRDN - * @param string $newParent - * @param bool $deleteOldRDN - * @throws UnavailableException - * @throws WriteFailureException - */ - public function rename($dn, $newRDN, $newParent, $deleteOldRDN = true) - { - $this->checkBound(); - - if (!@ldap_rename($this->link, $dn, $newRDN, $newParent, $deleteOldRDN)) { - throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + if (!ldap_mod_replace($this->link, $dn, $entry)) { + throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } - /** - * @param string $dn - * @param string $password - * @param string $saslMech - * @param string $saslRealm - * @param string $saslAuthcId - * @param string $saslAuthzId - * @param string $props - * @throws UnavailableException - * @throws BindFailureException - */ - public function saslBind($dn = null, $password = null, $saslMech = null, $saslRealm = null, $saslAuthcId = null, $saslAuthzId = null, $props = null) - { - $this->checkConnected(); - - if (!@ldap_sasl_bind($this->link, $dn, $password, $saslMech, $saslRealm, $saslAuthcId, $saslAuthzId, $props)) { - throw new BindFailureException(ldap_error($this->link), ldap_errno($this->link)); - } - - $this->bound = true; + /** + * @param string $dn + * @param array $entry + * @throws UnavailableException + * @throws WriteFailureException + */ + public function modify($dn, array $entry) + { + $this->checkBound(); + + if (!ldap_modify($this->link, $dn, $entry)) { + throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } - /** - * @param string $dn - * @param string $filter - * @param array $attributes - * @param bool $attrsOnly - * @param int $sizeLimit - * @param int $timeLimit - * @param int $deRef - * @return ResultSet - * @throws UnavailableException - * @throws ReadFailureException - */ - public function search($dn, $filter, array $attributes = null, $attrsOnly = false, $sizeLimit = 0, $timeLimit = 0, $deRef = LDAP_DEREF_NEVER) - { - $this->checkBound(); - - if (!$result = @ldap_search($this->link, $dn, $filter, $attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { - throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); - } - - return $this->createResultSet($result); + /** + * @param string $dn + * @param string $filter + * @param array $attributes + * @param bool $attrsOnly + * @param int $sizeLimit + * @param int $timeLimit + * @param int $deRef + * @return ResultSet + * @throws UnavailableException + * @throws ReadFailureException + */ + public function read($dn, $filter, array $attributes = null, $attrsOnly = false, $sizeLimit = 0, $timeLimit = 0, $deRef = LDAP_DEREF_NEVER) + { + $this->checkBound(); + + if (!$result = ldap_read($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { + throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); } - /** - * @param int $opt - * @param mixed $value - * @throws UnavailableException - * @throws OptionFailureException - */ - public function setOption($opt, $value) - { - $this->checkConnected(); - - if (!@ldap_set_option($this->link, $opt, $value)) { - throw new OptionFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + return $this->createResultSet($result); + } + + /** + * @param string $dn + * @param string $newRDN + * @param string $newParent + * @param bool $deleteOldRDN + * @throws UnavailableException + * @throws WriteFailureException + */ + public function rename($dn, $newRDN, $newParent, $deleteOldRDN = true) + { + $this->checkBound(); + + if (!ldap_rename($this->link, $dn, $newRDN, $newParent, $deleteOldRDN)) { + throw new WriteFailureException(ldap_error($this->link), ldap_errno($this->link)); } + } - /** - * @param callable $callback - * @throws UnavailableException - * @throws OptionFailureException - */ - public function setRebindProc(callable $callback) - { - $this->checkConnected(); - - if (!@ldap_set_rebind_proc($this->link, $callback)) { - throw new OptionFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + /** + * @param string $dn + * @param string $password + * @param string $saslMech + * @param string $saslRealm + * @param string $saslAuthcId + * @param string $saslAuthzId + * @param string $props + * @throws UnavailableException + * @throws BindFailureException + */ + public function saslBind($dn = null, $password = null, $saslMech = null, $saslRealm = null, $saslAuthcId = null, $saslAuthzId = null, $props = null) + { + $this->checkConnected(); + + if (!ldap_sasl_bind($this->link, $dn, $password, $saslMech, $saslRealm, $saslAuthcId, $saslAuthzId, $props)) { + throw new BindFailureException(ldap_error($this->link), ldap_errno($this->link)); } - /** - * @throws UnavailableException - * @throws AlreadyAvailableException - * @throws EncryptionFailureException - */ - public function startTLS() - { - $this->checkConnected(); - if ($this->bound) { - throw new AlreadyAvailableException('An active bound connection to the directory is already available'); - } - - if (!@ldap_start_tls($this->link)) { - throw new EncryptionFailureException(ldap_error($this->link), ldap_errno($this->link)); - } + $this->bound = true; + } + + /** + * @param string $dn + * @param string $filter + * @param array $attributes + * @param bool $attrsOnly + * @param int $sizeLimit + * @param int $timeLimit + * @param int $deRef + * @return ResultSet + * @throws UnavailableException + * @throws ReadFailureException + */ + public function search($dn, $filter, array $attributes = null, $attrsOnly = false, $sizeLimit = 0, $timeLimit = 0, $deRef = LDAP_DEREF_NEVER) + { + $this->checkBound(); + + if (!$result = ldap_search($this->link, $dn, $filter, (array)$attributes, (int)(bool)$attrsOnly, $sizeLimit, $timeLimit, $deRef)) { + throw new ReadFailureException(ldap_error($this->link), ldap_errno($this->link)); } - /** - * @throws UnavailableException - */ - public function unbind() - { - $this->checkBound(); + return $this->createResultSet($result); + } - @ldap_unbind($this->link); + /** + * @param int $opt + * @param mixed $value + * @throws UnavailableException + * @throws OptionFailureException + */ + public function setOption($opt, $value) + { + $this->checkConnected(); - $this->link = null; - $this->bound = false; + if (!ldap_set_option($this->link, $opt, $value)) { + throw new OptionFailureException(ldap_error($this->link), ldap_errno($this->link)); } } -} -namespace -{ - if (!function_exists('ldap_escape')) { - define('LDAP_ESCAPE_FILTER', 0x01); - define('LDAP_ESCAPE_DN', 0x02); - - /** - * @param string $subject - * @param string $ignore - * @param int $flags - * @return string - */ - function ldap_escape($subject, $ignore = '', $flags = 0) - { - $subject = (string) $subject; - if ($subject === '') { - return ''; - } - - $charList = array_fill(0, 256, false); - $haveCharList = false; - - if ($flags & LDAP_ESCAPE_FILTER) { - $charList = array_fill(0, 256, false); - $haveCharList = true; - - foreach (["\\", "*", "(", ")", "\x00"] as $char) { - $charList[ord($char)] = true; - } - } - - if ($flags & LDAP_ESCAPE_DN) { - if (!$haveCharList) { - $charList = array_fill(0, 256, false); - } - - foreach (["\\", ",", "=", "+", "<", ">", ";", "\"", "#"] as $char) { - $charList[ord($char)] = true; - } - } + /** + * @param callable $callback + * @throws UnavailableException + * @throws OptionFailureException + */ + public function setRebindProc(callable $callback) + { + $this->checkConnected(); + + if (!ldap_set_rebind_proc($this->link, $callback)) { + throw new OptionFailureException(ldap_error($this->link), ldap_errno($this->link)); + } + } + + /** + * @throws UnavailableException + * @throws AlreadyAvailableException + * @throws EncryptionFailureException + */ + public function startTLS() + { + $this->checkConnected(); + if ($this->bound) { + throw new AlreadyAvailableException('An active bound connection to the directory is already available'); + } + + if (!ldap_start_tls($this->link)) { + throw new EncryptionFailureException(ldap_error($this->link), ldap_errno($this->link)); } } + + /** + * @throws UnavailableException + */ + public function unbind() + { + $this->checkBound(); + + ldap_unbind($this->link); + + $this->link = null; + $this->bound = false; + } } diff --git a/src/LDAPi/ResultEntry.php b/src/LDAPi/Entry.php similarity index 79% rename from src/LDAPi/ResultEntry.php rename to src/LDAPi/Entry.php index b366b16..89336bd 100644 --- a/src/LDAPi/ResultEntry.php +++ b/src/LDAPi/Entry.php @@ -2,7 +2,7 @@ namespace LDAPi; -class ResultEntry +class Entry { /** * @var resource ext/ldap link resource @@ -25,12 +25,12 @@ public function __construct($link, $entry) } /** - * @return ResultEntry|null + * @return Entry|null * @throws EntryRetrievalFailureException */ public function nextEntry() { - if (!$entry = @ldap_next_entry($this->link, $this->entry)) { + if (!$entry = ldap_next_entry($this->link, $this->entry)) { if (0 !== $errNo = ldap_errno($this->link)) { throw new EntryRetrievalFailureException(ldap_error($this->link), $errNo); } @@ -38,7 +38,7 @@ public function nextEntry() return null; } - return new ResultEntry($this->link, $entry); + return new Entry($this->link, $entry); } /** @@ -47,7 +47,7 @@ public function nextEntry() */ public function getValues($attribute) { - if (!$values = @ldap_get_values($this->link, $this->entry, $attribute)) { + if (!$values = ldap_get_values($this->link, $this->entry, $attribute)) { throw new ValueRetrievalFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -60,7 +60,7 @@ public function getValues($attribute) */ public function getAttributes() { - if (!$attributes = @ldap_get_attributes($this->link, $this->entry)) { + if (!$attributes = ldap_get_attributes($this->link, $this->entry)) { throw new ValueRetrievalFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -73,7 +73,7 @@ public function getAttributes() */ public function getDN() { - if (!$dn = @ldap_get_dn($this->link, $this->entry)) { + if (!$dn = ldap_get_dn($this->link, $this->entry)) { throw new ValueRetrievalFailureException(ldap_error($this->link), ldap_errno($this->link)); } diff --git a/src/LDAPi/ResultReference.php b/src/LDAPi/Reference.php similarity index 77% rename from src/LDAPi/ResultReference.php rename to src/LDAPi/Reference.php index 67edf20..ee675d1 100644 --- a/src/LDAPi/ResultReference.php +++ b/src/LDAPi/Reference.php @@ -2,7 +2,7 @@ namespace LDAPi; -class ResultReference +class Reference { /** * @var resource ext/ldap link resource @@ -26,12 +26,12 @@ public function __construct($link, $reference) } /** - * @return ResultReference|null + * @return Reference|null * @throws ReferenceRetrievalFailureException */ public function nextReference() { - if (!$reference = @ldap_next_reference($this->link, $this->reference)) { + if (!$reference = ldap_next_reference($this->link, $this->reference)) { if (0 !== $errNo = ldap_errno($this->link)) { throw new ReferenceRetrievalFailureException(ldap_error($this->link), $errNo); } @@ -39,16 +39,16 @@ public function nextReference() return null; } - return new ResultReference($this->link, $reference); + return new Reference($this->link, $reference); } /** - * @return array + * @return string[] * @throws ValueRetrievalFailureException */ public function parse() { - if (!@ldap_parse_reference($this->link, $this->reference, $referrals)) { + if (!ldap_parse_reference($this->link, $this->reference, $referrals)) { throw new ValueRetrievalFailureException(ldap_error($this->link), ldap_errno($this->link)); } diff --git a/src/LDAPi/ResultSet.php b/src/LDAPi/ResultSet.php index e0b8065..0be1f23 100644 --- a/src/LDAPi/ResultSet.php +++ b/src/LDAPi/ResultSet.php @@ -26,7 +26,7 @@ public function __construct($link, $result) public function __destruct() { - @ldap_free_result($this->result); + ldap_free_result($this->result); } /** @@ -36,7 +36,7 @@ public function __destruct() */ public function controlPagedResult(&$estimated = null) { - if (!@ldap_control_paged_result_response($this->link, $this->result, $cookie, $estimated)) { + if (!ldap_control_paged_result_response($this->link, $this->result, $cookie, $estimated)) { throw new PaginationFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -49,7 +49,7 @@ public function controlPagedResult(&$estimated = null) */ public function entryCount() { - if (!$result = @ldap_count_entries($this->link, $this->result)) { + if (!$result = ldap_count_entries($this->link, $this->result)) { throw new EntryCountRetrievalFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -57,12 +57,12 @@ public function entryCount() } /** - * @return ResultEntry|null + * @return Entry|null * @throws EntryRetrievalFailureException */ public function firstEntry() { - if (!$entry = @ldap_first_entry($this->link, $this->result)) { + if (!$entry = ldap_first_entry($this->link, $this->result)) { if (0 !== $errNo = ldap_errno($this->link)) { throw new EntryRetrievalFailureException(ldap_error($this->link), $errNo); } @@ -70,16 +70,16 @@ public function firstEntry() return null; } - return new ResultEntry($this->link, $entry); + return new Entry($this->link, $entry); } /** - * @return ResultReference|null + * @return Reference|null * @throws ReferenceRetrievalFailureException */ public function firstReference() { - if (!$reference = @ldap_first_reference($this->link, $this->result)) { + if (!$reference = ldap_first_reference($this->link, $this->result)) { if (0 !== $errNo = ldap_errno($this->link)) { throw new ReferenceRetrievalFailureException(ldap_error($this->link), $errNo); } @@ -87,7 +87,7 @@ public function firstReference() return null; } - return new ResultReference($this->link, $reference); + return new Reference($this->link, $reference); } /** @@ -96,7 +96,7 @@ public function firstReference() */ public function parse() { - if (!@ldap_parse_result($this->link, $this->result, $errCode, $matchedDN, $errMsg, $referrals)) { + if (!ldap_parse_result($this->link, $this->result, $errCode, $matchedDN, $errMsg, $referrals)) { throw new InformationRetrievalFailureException(ldap_error($this->link), ldap_errno($this->link)); } @@ -114,7 +114,7 @@ public function parse() */ public function getEntries() { - if (!$entries = @ldap_get_entries($this->link, $this->result)) { + if (!$entries = ldap_get_entries($this->link, $this->result)) { throw new ValueRetrievalFailureException(ldap_error($this->link), ldap_errno($this->link)); } diff --git a/src/global_functions.php b/src/global_functions.php new file mode 100644 index 0000000..6cfdcd0 --- /dev/null +++ b/src/global_functions.php @@ -0,0 +1,49 @@ +", ";", "\"", "#"]); + } + if (!$charList) { + for ($i = 0; $i < 256; $i++) { + $charList[] = chr($i); + } + } + $charList = array_flip($charList); + + for ($i = 0; isset($ignore[$i]); $i++) { + unset($charList[$ignore[$i]]); + } + + foreach ($charList as $key => &$value) { + $value = sprintf('\%02x', ord($key)); + } + + return strtr($subject, $charList); + } +}