3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
15 class Filter
extends Filter\StringFilter
17 const TYPE_EQUALS
= '=';
18 const TYPE_GREATER
= '>';
19 const TYPE_GREATEROREQUAL
= '>=';
20 const TYPE_LESS
= '<';
21 const TYPE_LESSOREQUAL
= '<=';
22 const TYPE_APPROX
= '~=';
25 * Creates an 'equals' filter.
29 * @param string $value
32 public static function equals($attr, $value)
34 return new static($attr, $value, self
::TYPE_EQUALS
, null, null);
38 * Creates a 'begins with' filter.
42 * @param string $value
45 public static function begins($attr, $value)
47 return new static($attr, $value, self
::TYPE_EQUALS
, null, '*');
51 * Creates an 'ends with' filter.
55 * @param string $value
58 public static function ends($attr, $value)
60 return new static($attr, $value, self
::TYPE_EQUALS
, '*', null);
64 * Creates a 'contains' filter.
68 * @param string $value
71 public static function contains($attr, $value)
73 return new static($attr, $value, self
::TYPE_EQUALS
, '*', '*');
77 * Creates a 'greater' filter.
81 * @param string $value
84 public static function greater($attr, $value)
86 return new static($attr, $value, self
::TYPE_GREATER
, null, null);
90 * Creates a 'greater or equal' filter.
94 * @param string $value
97 public static function greaterOrEqual($attr, $value)
99 return new static($attr, $value, self
::TYPE_GREATEROREQUAL
, null, null);
103 * Creates a 'less' filter.
106 * @param string $attr
107 * @param string $value
110 public static function less($attr, $value)
112 return new static($attr, $value, self
::TYPE_LESS
, null, null);
116 * Creates an 'less or equal' filter.
119 * @param string $attr
120 * @param string $value
123 public static function lessOrEqual($attr, $value)
125 return new static($attr, $value, self
::TYPE_LESSOREQUAL
, null, null);
129 * Creates an 'approx' filter.
132 * @param string $attr
133 * @param string $value
136 public static function approx($attr, $value)
138 return new static($attr, $value, self
::TYPE_APPROX
, null, null);
142 * Creates an 'any' filter.
145 * @param string $attr
148 public static function any($attr)
150 return new static($attr, '', self
::TYPE_EQUALS
, '*', null);
154 * Creates a simple custom string filter.
156 * @param string $filter
157 * @return Filter\StringFilter
159 public static function string($filter)
161 return new Filter\
StringFilter($filter);
165 * Creates a simple string filter to be used with a mask.
167 * @param string $mask
168 * @param string $value
169 * @return Filter\MaskFilter
171 public static function mask($mask, $value)
173 return new Filter\
MaskFilter($mask, $value);
177 * Creates an 'and' filter.
179 * @param Filter\AbstractFilter $filter,...
180 * @return Filter\AndFilter
182 public static function andFilter($filter)
184 return new Filter\
AndFilter(func_get_args());
188 * Creates an 'or' filter.
190 * @param Filter\AbstractFilter $filter,...
191 * @return Filter\OrFilter
193 public static function orFilter($filter)
195 return new Filter\
OrFilter(func_get_args());
199 * Create a filter string.
201 * @param string $attr
202 * @param string $value
203 * @param string $filtertype
204 * @param string $prepend
205 * @param string $append
208 private static function createFilterString($attr, $value, $filtertype, $prepend = null, $append = null)
210 $str = $attr . $filtertype;
211 if ($prepend !== null) {
214 $str .= static::escapeValue($value);
215 if ($append !== null) {
222 * Creates a new Zend\Ldap\Filter.
224 * @param string $attr
225 * @param string $value
226 * @param string $filtertype
227 * @param string $prepend
228 * @param string $append
230 public function __construct($attr, $value, $filtertype, $prepend = null, $append = null)
232 $filter = static::createFilterString($attr, $value, $filtertype, $prepend, $append);
233 parent
::__construct($filter);