diff --git a/library/Icinga/Protocol/Ldap/Expression.php b/library/Icinga/Protocol/Ldap/Expression.php new file mode 100644 index 000000000..403e1fd04 --- /dev/null +++ b/library/Icinga/Protocol/Ldap/Expression.php @@ -0,0 +1,30 @@ +value = $value; + } + + public function setValue($value) + { + $this->value = $value; + return $this; + } + + public function getValue() + { + return $this->value; + } + + public function __toString() + { + return (string) $this->getValue(); + } +} diff --git a/library/Icinga/Protocol/Ldap/Query.php b/library/Icinga/Protocol/Ldap/Query.php index 897f12f4e..4e25fe9d4 100644 --- a/library/Icinga/Protocol/Ldap/Query.php +++ b/library/Icinga/Protocol/Ldap/Query.php @@ -306,6 +306,19 @@ class Query return $paginator; } + /** + * Add a filter expression to this query + * + * @param Expression $expression + * + * @return Query + */ + public function addFilter(Expression $expression) + { + $this->filters[] = $expression; + return $this; + } + /** * Returns the LDAP filter that will be applied * @@ -318,11 +331,15 @@ class Query throw new Exception('Object class is mandatory'); } foreach ($this->filters as $key => $value) { - $parts[] = sprintf( - '%s=%s', - LdapUtils::quoteForSearch($key), - LdapUtils::quoteForSearch($value, true) - ); + if ($value instanceof Expression) { + $parts[] = (string) $value; + } else { + $parts[] = sprintf( + '%s=%s', + LdapUtils::quoteForSearch($key), + LdapUtils::quoteForSearch($value, true) + ); + } } if (count($parts) > 1) { return '(&(' . implode(')(', $parts) . '))';