/** * Render and return a valid LDAP filter expression of the given filter * * @param FilterExpression $filter * * @return string */ protected function renderFilterExpression(FilterExpression $filter) { $column = $filter->getColumn(); $sign = $filter->getSign(); $expression = $filter->getExpression(); $format = '%1$s%2$s%3$s'; if ($expression === null || $expression === true) { $expression = '*'; } elseif (is_array($expression)) { $seqFormat = '|(%s)'; if ($sign === '!=') { $seqFormat = '!(' . $seqFormat . ')'; $sign = '='; } $seqParts = array(); foreach ($expression as $expressionValue) { $seqParts[] = sprintf($format, LdapUtils::quoteForSearch($column), $sign, LdapUtils::quoteForSearch($expressionValue, true)); } return sprintf($seqFormat, implode(')(', $seqParts)); } if ($sign === '!=') { $format = '!(%1$s=%3$s)'; } return sprintf($format, LdapUtils::quoteForSearch($column), $sign, LdapUtils::quoteForSearch($expression, true)); }
/** * Return the LDAP filter to be applied on this query * * @return string * * @throws LdapException In case the objectClass filter does not exist */ protected function renderFilter() { if (!isset($this->filters['objectClass'])) { throw new LdapException('Object class is mandatory'); } $parts = array(); 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 { return '(' . $parts[0] . ')'; } }