Esempio n. 1
0
 /**
  * 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));
 }
Esempio n. 2
0
 /**
  * Render a single filter expression
  *
  * @param FilterExpression $filter    the filter expression
  * @param bool             $keylookup whether to resolve alias names
  *
  * @return string
  */
 public function renderFilterExpression(FilterExpression $filter, $keylookup = true)
 {
     if ($keylookup) {
         $col = $this->available_columns[$filter->getColumn()];
     } else {
         $col = $filter->getColumn();
     }
     $isArray = array_key_exists($col, $this->arrayColumns);
     $sign = $filter->getSign();
     if ($isArray && $sign === '=') {
         $sign = '>=';
     }
     $expression = $filter->getExpression();
     if ($sign === '=' && strpos($expression, '*') !== false) {
         return $col . ' ~~ ' . $this->safeRegex($expression);
     } elseif ($sign === '!=' && strpos($expression, '*') !== false) {
         return $col . ' !~~ ' . $this->safeRegex($expression);
     } else {
         return $col . ' ' . $sign . ' ' . $expression;
     }
 }