Add support for dynamic ldap filter expressions

"Dynamic" is a more of a overstatement when describing this commit but
the current implementation is just the start. Once our ldap protocol stuff
supports our filter implementation this will be vastly improved.

refs #8365
This commit is contained in:
Johannes Meyer 2015-03-11 09:50:41 +01:00
parent 2cf09ebc48
commit 0758be4af1
2 changed files with 52 additions and 5 deletions

View File

@ -0,0 +1,30 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Protocol\Ldap;
class Expression
{
protected $value;
public function __construct($value)
{
$this->value = $value;
}
public function setValue($value)
{
$this->value = $value;
return $this;
}
public function getValue()
{
return $this->value;
}
public function __toString()
{
return (string) $this->getValue();
}
}

View File

@ -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,12 +331,16 @@ class Query
throw new Exception('Object class is mandatory');
}
foreach ($this->filters as $key => $value) {
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) . '))';
} else {