Skip to content

Core\Ldap\Filter::any

Builds a filter that finds the directory entries that at least one of the given filters matches.

Use it when there is more than one right answer, such as a login that may be an account name or a mail address. Give it one filter or more. Combine it with Core\Ldap\Filter::all to say which conditions must always hold.

No filter at all throws a LogicError.

Good to know: filters can be put inside each other up to 100 levels deep. One more level throws a LogicError. A filter that a person writes never comes close to this.

Parameters

  • ...$filtersCore\Ldap\FiltervariadicOne filter or more.

Return value

Returns Core\Ldap\Filter. A Core\Ldap\Filter.

Errors

  • LogicErrorNo filter is given, or the new filter has more than 100 levels of all, any and not inside each other.

Examples

Account name or mail

<?nvs
// Shows how to find an account by a login that may be its name or its mail address.
string $login = 'anna@example.test';
var $filter = Core\Ldap\Filter::any(
Core\Ldap\Filter::equals('sAMAccountName', $login),
Core\Ldap\Filter::equals('mail', $login),
);
// This prints (|(sAMAccountName=anna@example.test)(mail=anna@example.test)).
echo $filter->toString(), "\n";
Output
(|(sAMAccountName=anna@example.test)(mail=anna@example.test))

Users or groups

<?nvs
// Shows how to find the users and the groups whose name starts with the same text.
var $filter = Core\Ldap\Filter::all(
Core\Ldap\Filter::any(
Core\Ldap\Filter::equals('objectClass', 'user'),
Core\Ldap\Filter::equals('objectClass', 'group'),
),
Core\Ldap\Filter::startsWith('cn', 'Sales'),
);
// This prints (&(|(objectClass=user)(objectClass=group))(cn=Sales*)).
echo $filter->toString(), "\n";
Output
(&(|(objectClass=user)(objectClass=group))(cn=Sales*))

One of many values

<?nvs
// Shows how to find the entries whose value is one of the values in a list.
array<string> $offices = ['Vienna', 'Graz', 'Linz'];
array<Core\Ldap\Filter> $parts = [];
foreach ($offices as string $office) {
$parts[] = Core\Ldap\Filter::equals('l', $office);
}
// `...` passes the array as separate filters.
// This prints (|(l=Vienna)(l=Graz)(l=Linz)).
echo Core\Ldap\Filter::any(...$parts)->toString(), "\n";
Output
(|(l=Vienna)(l=Graz)(l=Linz))