|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Ldap |
|
17 * @subpackage Filter |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: Filter.php 22662 2010-07-24 17:37:36Z mabe $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @see Zend_Ldap_Filter_String |
|
25 */ |
|
26 require_once 'Zend/Ldap/Filter/String.php'; |
|
27 |
|
28 /** |
|
29 * Zend_Ldap_Filter. |
|
30 * |
|
31 * @category Zend |
|
32 * @package Zend_Ldap |
|
33 * @subpackage Filter |
|
34 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
35 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
36 */ |
|
37 class Zend_Ldap_Filter extends Zend_Ldap_Filter_String |
|
38 { |
|
39 const TYPE_EQUALS = '='; |
|
40 const TYPE_GREATER = '>'; |
|
41 const TYPE_GREATEROREQUAL = '>='; |
|
42 const TYPE_LESS = '<'; |
|
43 const TYPE_LESSOREQUAL = '<='; |
|
44 const TYPE_APPROX = '~='; |
|
45 |
|
46 /** |
|
47 * Creates an 'equals' filter. |
|
48 * (attr=value) |
|
49 * |
|
50 * @param string $attr |
|
51 * @param string $value |
|
52 * @return Zend_Ldap_Filter |
|
53 */ |
|
54 public static function equals($attr, $value) |
|
55 { |
|
56 return new self($attr, $value, self::TYPE_EQUALS, null, null); |
|
57 } |
|
58 |
|
59 /** |
|
60 * Creates a 'begins with' filter. |
|
61 * (attr=value*) |
|
62 * |
|
63 * @param string $attr |
|
64 * @param string $value |
|
65 * @return Zend_Ldap_Filter |
|
66 */ |
|
67 public static function begins($attr, $value) |
|
68 { |
|
69 return new self($attr, $value, self::TYPE_EQUALS, null, '*'); |
|
70 } |
|
71 |
|
72 /** |
|
73 * Creates an 'ends with' filter. |
|
74 * (attr=*value) |
|
75 * |
|
76 * @param string $attr |
|
77 * @param string $value |
|
78 * @return Zend_Ldap_Filter |
|
79 */ |
|
80 public static function ends($attr, $value) |
|
81 { |
|
82 return new self($attr, $value, self::TYPE_EQUALS, '*', null); |
|
83 } |
|
84 |
|
85 /** |
|
86 * Creates a 'contains' filter. |
|
87 * (attr=*value*) |
|
88 * |
|
89 * @param string $attr |
|
90 * @param string $value |
|
91 * @return Zend_Ldap_Filter |
|
92 */ |
|
93 public static function contains($attr, $value) |
|
94 { |
|
95 return new self($attr, $value, self::TYPE_EQUALS, '*', '*'); |
|
96 } |
|
97 |
|
98 /** |
|
99 * Creates a 'greater' filter. |
|
100 * (attr>value) |
|
101 * |
|
102 * @param string $attr |
|
103 * @param string $value |
|
104 * @return Zend_Ldap_Filter |
|
105 */ |
|
106 public static function greater($attr, $value) |
|
107 { |
|
108 return new self($attr, $value, self::TYPE_GREATER, null, null); |
|
109 } |
|
110 |
|
111 /** |
|
112 * Creates a 'greater or equal' filter. |
|
113 * (attr>=value) |
|
114 * |
|
115 * @param string $attr |
|
116 * @param string $value |
|
117 * @return Zend_Ldap_Filter |
|
118 */ |
|
119 public static function greaterOrEqual($attr, $value) |
|
120 { |
|
121 return new self($attr, $value, self::TYPE_GREATEROREQUAL, null, null); |
|
122 } |
|
123 |
|
124 /** |
|
125 * Creates a 'less' filter. |
|
126 * (attr<value) |
|
127 * |
|
128 * @param string $attr |
|
129 * @param string $value |
|
130 * @return Zend_Ldap_Filter |
|
131 */ |
|
132 public static function less($attr, $value) |
|
133 { |
|
134 return new self($attr, $value, self::TYPE_LESS, null, null); |
|
135 } |
|
136 |
|
137 /** |
|
138 * Creates an 'less or equal' filter. |
|
139 * (attr<=value) |
|
140 * |
|
141 * @param string $attr |
|
142 * @param string $value |
|
143 * @return Zend_Ldap_Filter |
|
144 */ |
|
145 public static function lessOrEqual($attr, $value) |
|
146 { |
|
147 return new self($attr, $value, self::TYPE_LESSOREQUAL, null, null); |
|
148 } |
|
149 |
|
150 /** |
|
151 * Creates an 'approx' filter. |
|
152 * (attr~=value) |
|
153 * |
|
154 * @param string $attr |
|
155 * @param string $value |
|
156 * @return Zend_Ldap_Filter |
|
157 */ |
|
158 public static function approx($attr, $value) |
|
159 { |
|
160 return new self($attr, $value, self::TYPE_APPROX, null, null); |
|
161 } |
|
162 |
|
163 /** |
|
164 * Creates an 'any' filter. |
|
165 * (attr=*) |
|
166 * |
|
167 * @param string $attr |
|
168 * @return Zend_Ldap_Filter |
|
169 */ |
|
170 public static function any($attr) |
|
171 { |
|
172 return new self($attr, '', self::TYPE_EQUALS, '*', null); |
|
173 } |
|
174 |
|
175 /** |
|
176 * Creates a simple custom string filter. |
|
177 * |
|
178 * @param string $filter |
|
179 * @return Zend_Ldap_Filter_String |
|
180 */ |
|
181 public static function string($filter) |
|
182 { |
|
183 return new Zend_Ldap_Filter_String($filter); |
|
184 } |
|
185 |
|
186 /** |
|
187 * Creates a simple string filter to be used with a mask. |
|
188 * |
|
189 * @param string $mask |
|
190 * @param string $value |
|
191 * @return Zend_Ldap_Filter_Mask |
|
192 */ |
|
193 public static function mask($mask, $value) |
|
194 { |
|
195 /** |
|
196 * Zend_Ldap_Filter_Mask |
|
197 */ |
|
198 require_once 'Zend/Ldap/Filter/Mask.php'; |
|
199 return new Zend_Ldap_Filter_Mask($mask, $value); |
|
200 } |
|
201 |
|
202 /** |
|
203 * Creates an 'and' filter. |
|
204 * |
|
205 * @param Zend_Ldap_Filter_Abstract $filter,... |
|
206 * @return Zend_Ldap_Filter_And |
|
207 */ |
|
208 public static function andFilter($filter) |
|
209 { |
|
210 /** |
|
211 * Zend_Ldap_Filter_And |
|
212 */ |
|
213 require_once 'Zend/Ldap/Filter/And.php'; |
|
214 return new Zend_Ldap_Filter_And(func_get_args()); |
|
215 } |
|
216 |
|
217 /** |
|
218 * Creates an 'or' filter. |
|
219 * |
|
220 * @param Zend_Ldap_Filter_Abstract $filter,... |
|
221 * @return Zend_Ldap_Filter_Or |
|
222 */ |
|
223 public static function orFilter($filter) |
|
224 { |
|
225 /** |
|
226 * Zend_Ldap_Filter_Or |
|
227 */ |
|
228 require_once 'Zend/Ldap/Filter/Or.php'; |
|
229 return new Zend_Ldap_Filter_Or(func_get_args()); |
|
230 } |
|
231 |
|
232 /** |
|
233 * Create a filter string. |
|
234 * |
|
235 * @param string $attr |
|
236 * @param string $value |
|
237 * @param string $filtertype |
|
238 * @param string $prepend |
|
239 * @param string $append |
|
240 * @return string |
|
241 */ |
|
242 private static function _createFilterString($attr, $value, $filtertype, $prepend = null, $append = null) |
|
243 { |
|
244 $str = $attr . $filtertype; |
|
245 if ($prepend !== null) $str .= $prepend; |
|
246 $str .= self::escapeValue($value); |
|
247 if ($append !== null) $str .= $append; |
|
248 return $str; |
|
249 } |
|
250 |
|
251 /** |
|
252 * Creates a new Zend_Ldap_Filter. |
|
253 * |
|
254 * @param string $attr |
|
255 * @param string $value |
|
256 * @param string $filtertype |
|
257 * @param string $prepend |
|
258 * @param string $append |
|
259 */ |
|
260 public function __construct($attr, $value, $filtertype, $prepend = null, $append = null) |
|
261 { |
|
262 $filter = self::_createFilterString($attr, $value, $filtertype, $prepend, $append); |
|
263 parent::__construct($filter); |
|
264 } |
|
265 } |