[ZF-10089] Zend_Log
[zend/radio.git] / library / Zend / Ldap / Filter.php
blob4f664dbb38ca49d83d75ea7f761b507eda773665
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
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$
23 /**
24 * @see Zend_Ldap_Filter_String
26 require_once 'Zend/Ldap/Filter/String.php';
28 /**
29 * Zend_Ldap_Filter.
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
37 class Zend_Ldap_Filter extends Zend_Ldap_Filter_String
39 const TYPE_EQUALS = '=';
40 const TYPE_GREATER = '>';
41 const TYPE_GREATEROREQUAL = '>=';
42 const TYPE_LESS = '<';
43 const TYPE_LESSOREQUAL = '<=';
44 const TYPE_APPROX = '~=';
46 /**
47 * Creates an 'equals' filter.
48 * (attr=value)
50 * @param string $attr
51 * @param string $value
52 * @return Zend_Ldap_Filter
54 public static function equals($attr, $value)
56 return new self($attr, $value, self::TYPE_EQUALS, null, null);
59 /**
60 * Creates a 'begins with' filter.
61 * (attr=value*)
63 * @param string $attr
64 * @param string $value
65 * @return Zend_Ldap_Filter
67 public static function begins($attr, $value)
69 return new self($attr, $value, self::TYPE_EQUALS, null, '*');
72 /**
73 * Creates an 'ends with' filter.
74 * (attr=*value)
76 * @param string $attr
77 * @param string $value
78 * @return Zend_Ldap_Filter
80 public static function ends($attr, $value)
82 return new self($attr, $value, self::TYPE_EQUALS, '*', null);
85 /**
86 * Creates a 'contains' filter.
87 * (attr=*value*)
89 * @param string $attr
90 * @param string $value
91 * @return Zend_Ldap_Filter
93 public static function contains($attr, $value)
95 return new self($attr, $value, self::TYPE_EQUALS, '*', '*');
98 /**
99 * Creates a 'greater' filter.
100 * (attr>value)
102 * @param string $attr
103 * @param string $value
104 * @return Zend_Ldap_Filter
106 public static function greater($attr, $value)
108 return new self($attr, $value, self::TYPE_GREATER, null, null);
112 * Creates a 'greater or equal' filter.
113 * (attr>=value)
115 * @param string $attr
116 * @param string $value
117 * @return Zend_Ldap_Filter
119 public static function greaterOrEqual($attr, $value)
121 return new self($attr, $value, self::TYPE_GREATEROREQUAL, null, null);
125 * Creates a 'less' filter.
126 * (attr<value)
128 * @param string $attr
129 * @param string $value
130 * @return Zend_Ldap_Filter
132 public static function less($attr, $value)
134 return new self($attr, $value, self::TYPE_LESS, null, null);
138 * Creates an 'less or equal' filter.
139 * (attr<=value)
141 * @param string $attr
142 * @param string $value
143 * @return Zend_Ldap_Filter
145 public static function lessOrEqual($attr, $value)
147 return new self($attr, $value, self::TYPE_LESSOREQUAL, null, null);
151 * Creates an 'approx' filter.
152 * (attr~=value)
154 * @param string $attr
155 * @param string $value
156 * @return Zend_Ldap_Filter
158 public static function approx($attr, $value)
160 return new self($attr, $value, self::TYPE_APPROX, null, null);
164 * Creates an 'any' filter.
165 * (attr=*)
167 * @param string $attr
168 * @return Zend_Ldap_Filter
170 public static function any($attr)
172 return new self($attr, '', self::TYPE_EQUALS, '*', null);
176 * Creates a simple custom string filter.
178 * @param string $filter
179 * @return Zend_Ldap_Filter_String
181 public static function string($filter)
183 return new Zend_Ldap_Filter_String($filter);
187 * Creates a simple string filter to be used with a mask.
189 * @param string $mask
190 * @param string $value
191 * @return Zend_Ldap_Filter_Mask
193 public static function mask($mask, $value)
196 * Zend_Ldap_Filter_Mask
198 require_once 'Zend/Ldap/Filter/Mask.php';
199 return new Zend_Ldap_Filter_Mask($mask, $value);
203 * Creates an 'and' filter.
205 * @param Zend_Ldap_Filter_Abstract $filter,...
206 * @return Zend_Ldap_Filter_And
208 public static function andFilter($filter)
211 * Zend_Ldap_Filter_And
213 require_once 'Zend/Ldap/Filter/And.php';
214 return new Zend_Ldap_Filter_And(func_get_args());
218 * Creates an 'or' filter.
220 * @param Zend_Ldap_Filter_Abstract $filter,...
221 * @return Zend_Ldap_Filter_Or
223 public static function orFilter($filter)
226 * Zend_Ldap_Filter_Or
228 require_once 'Zend/Ldap/Filter/Or.php';
229 return new Zend_Ldap_Filter_Or(func_get_args());
233 * Create a filter string.
235 * @param string $attr
236 * @param string $value
237 * @param string $filtertype
238 * @param string $prepend
239 * @param string $append
240 * @return string
242 private static function _createFilterString($attr, $value, $filtertype, $prepend = null, $append = null)
244 $str = $attr . $filtertype;
245 if (!is_null($prepend)) $str .= $prepend;
246 $str .= self::escapeValue($value);
247 if (!is_null($append)) $str .= $append;
248 return $str;
252 * Creates a new Zend_Ldap_Filter.
254 * @param string $attr
255 * @param string $value
256 * @param string $filtertype
257 * @param string $prepend
258 * @param string $append
260 public function __construct($attr, $value, $filtertype, $prepend = null, $append = null)
262 $filter = self::_createFilterString($attr, $value, $filtertype, $prepend, $append);
263 parent::__construct($filter);