modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-05-16 12:21:18 +04:00
parent 612b946db6
commit 37ac992222
2 changed files with 8 additions and 7 deletions

View File

@ -5,10 +5,12 @@ use nur\b\UserException;
class LdapException extends UserException {
/** @param $r ?resource */
static function check(string $message, $r, $value) {
static function check(string $message, $r, $value, ?int $allow_errno=null) {
if ($value !== false) return $value;
if ($r !== null) {
throw new self($message, ldap_errno($r), null, ldap_error($r));
$errno = ldap_errno($r);
if ($allow_errno !== null && $errno === $allow_errno) return $value;
throw new self($message, $errno, null, ldap_error($r));
} else {
throw new self($message);
}

View File

@ -157,17 +157,16 @@ class LdapSearch extends Parametrable implements IteratorAggregate {
elseif ($scope == self::SCOPE_BASE) $rr = @ldap_read(...$args);
else throw ValueException::invalid_value($scope, "scope");
// pas trouvé
if ($rr === false && ldap_errno($conn) == 32) return;
$rr = LdapException::check("search", $conn, $rr);
$rr = LdapException::check("search", $conn, $rr, 32);
if ($rr === false) return; // pas trouvé
try {
$er = LdapException::check("first_entry", $conn, ldap_first_entry($conn, $rr));
$er = LdapException::check("first_entry", $conn, ldap_first_entry($conn, $rr), 32);
while ($er !== false) {
$dn = ldap_get_dn($conn, $er);
$entry = ldap_get_attributes($conn, $er);
yield $dn => $entry;
$er = LdapException::check("next_entry", $conn, ldap_next_entry($conn, $er));
$er = LdapException::check("next_entry", $conn, ldap_next_entry($conn, $er), 32);
}
} catch (StopException $e) {
} finally {