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:
parent
2cf09ebc48
commit
0758be4af1
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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) . '))';
|
||||
|
|
Loading…
Reference in New Issue