Core\Ldap\Filter::all
Core\Ldap\Filter::all(Core\Ldap\Filter ...$filters): Core\Ldap\FilterCore\Ldap\Filter::all( Core\Ldap\Filter ...$filters, ): Core\Ldap\Filter
Builds a filter that finds only the directory entries that every one of the given filters matches.
This is how you combine conditions, such as "is a user account" and "has a mail address". Give it one filter or more. A filter you combine can itself be made with all, Core\Ldap\Filter::any or Core\Ldap\Filter::not, so you can build any condition. A filter is a value that does not change, so you can use the same one in several combinations.
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 ofall,anyandnotinside each other.
Examples
Two conditions
<?nvs// Shows how to find the entries that match two conditions at the same time.
var $filter = Core\Ldap\Filter::all( Core\Ldap\Filter::equals('objectClass', 'user'), Core\Ldap\Filter::equals('department', 'Sales'),);// This prints (&(objectClass=user)(department=Sales)).echo $filter->toString(), "\n";(&(objectClass=user)(department=Sales))Reuse a filter
<?nvs// Shows how to reuse one filter in several combinations.
var $people = Core\Ldap\Filter::all( Core\Ldap\Filter::equals('objectClass', 'user'), Core\Ldap\Filter::not(Core\Ldap\Filter::equals('objectClass', 'computer')),);// A filter does not change, so `$people` is the same in both lines below.echo Core\Ldap\Filter::all($people, Core\Ldap\Filter::present('mail'))->toString(), "\n";echo Core\Ldap\Filter::all($people, Core\Ldap\Filter::equals('department', 'Sales'))->toString(), "\n";(&(&(objectClass=user)(!(objectClass=computer)))(mail=*))(&(&(objectClass=user)(!(objectClass=computer)))(department=Sales))Conditions from a list
<?nvs// Shows how to build one filter from a list of conditions a program collected.
array<string> $wanted = ['department' => 'Sales', 'l' => 'Vienna', 'title' => 'Manager'];array<Core\Ldap\Filter> $parts = [];foreach ($wanted as string $attribute => string $value) { $parts[] = Core\Ldap\Filter::equals($attribute, $value);}// `...` passes the array as separate filters.// This prints (&(department=Sales)(l=Vienna)(title=Manager)).echo Core\Ldap\Filter::all(...$parts)->toString(), "\n";
try { // With no filter at all, `all` throws an error. array<Core\Ldap\Filter> $none = []; Core\Ldap\Filter::all(...$none);} catch (LogicError $error) { echo "No conditions.\n";}(&(department=Sales)(l=Vienna)(title=Manager))No conditions.