File indexing completed on 2024-12-22 05:36:49
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Ldap 0017 * @subpackage Filter 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * @see Zend_Ldap_Filter_String 0025 */ 0026 // require_once 'Zend/Ldap/Filter/String.php'; 0027 0028 /** 0029 * Zend_Ldap_Filter. 0030 * 0031 * @category Zend 0032 * @package Zend_Ldap 0033 * @subpackage Filter 0034 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0035 * @license http://framework.zend.com/license/new-bsd New BSD License 0036 */ 0037 class Zend_Ldap_Filter extends Zend_Ldap_Filter_String 0038 { 0039 const TYPE_EQUALS = '='; 0040 const TYPE_GREATER = '>'; 0041 const TYPE_GREATEROREQUAL = '>='; 0042 const TYPE_LESS = '<'; 0043 const TYPE_LESSOREQUAL = '<='; 0044 const TYPE_APPROX = '~='; 0045 0046 /** 0047 * Creates an 'equals' filter. 0048 * (attr=value) 0049 * 0050 * @param string $attr 0051 * @param string $value 0052 * @return Zend_Ldap_Filter 0053 */ 0054 public static function equals($attr, $value) 0055 { 0056 return new self($attr, $value, self::TYPE_EQUALS, null, null); 0057 } 0058 0059 /** 0060 * Creates a 'begins with' filter. 0061 * (attr=value*) 0062 * 0063 * @param string $attr 0064 * @param string $value 0065 * @return Zend_Ldap_Filter 0066 */ 0067 public static function begins($attr, $value) 0068 { 0069 return new self($attr, $value, self::TYPE_EQUALS, null, '*'); 0070 } 0071 0072 /** 0073 * Creates an 'ends with' filter. 0074 * (attr=*value) 0075 * 0076 * @param string $attr 0077 * @param string $value 0078 * @return Zend_Ldap_Filter 0079 */ 0080 public static function ends($attr, $value) 0081 { 0082 return new self($attr, $value, self::TYPE_EQUALS, '*', null); 0083 } 0084 0085 /** 0086 * Creates a 'contains' filter. 0087 * (attr=*value*) 0088 * 0089 * @param string $attr 0090 * @param string $value 0091 * @return Zend_Ldap_Filter 0092 */ 0093 public static function contains($attr, $value) 0094 { 0095 return new self($attr, $value, self::TYPE_EQUALS, '*', '*'); 0096 } 0097 0098 /** 0099 * Creates a 'greater' filter. 0100 * (attr>value) 0101 * 0102 * @param string $attr 0103 * @param string $value 0104 * @return Zend_Ldap_Filter 0105 */ 0106 public static function greater($attr, $value) 0107 { 0108 return new self($attr, $value, self::TYPE_GREATER, null, null); 0109 } 0110 0111 /** 0112 * Creates a 'greater or equal' filter. 0113 * (attr>=value) 0114 * 0115 * @param string $attr 0116 * @param string $value 0117 * @return Zend_Ldap_Filter 0118 */ 0119 public static function greaterOrEqual($attr, $value) 0120 { 0121 return new self($attr, $value, self::TYPE_GREATEROREQUAL, null, null); 0122 } 0123 0124 /** 0125 * Creates a 'less' filter. 0126 * (attr<value) 0127 * 0128 * @param string $attr 0129 * @param string $value 0130 * @return Zend_Ldap_Filter 0131 */ 0132 public static function less($attr, $value) 0133 { 0134 return new self($attr, $value, self::TYPE_LESS, null, null); 0135 } 0136 0137 /** 0138 * Creates an 'less or equal' filter. 0139 * (attr<=value) 0140 * 0141 * @param string $attr 0142 * @param string $value 0143 * @return Zend_Ldap_Filter 0144 */ 0145 public static function lessOrEqual($attr, $value) 0146 { 0147 return new self($attr, $value, self::TYPE_LESSOREQUAL, null, null); 0148 } 0149 0150 /** 0151 * Creates an 'approx' filter. 0152 * (attr~=value) 0153 * 0154 * @param string $attr 0155 * @param string $value 0156 * @return Zend_Ldap_Filter 0157 */ 0158 public static function approx($attr, $value) 0159 { 0160 return new self($attr, $value, self::TYPE_APPROX, null, null); 0161 } 0162 0163 /** 0164 * Creates an 'any' filter. 0165 * (attr=*) 0166 * 0167 * @param string $attr 0168 * @return Zend_Ldap_Filter 0169 */ 0170 public static function any($attr) 0171 { 0172 return new self($attr, '', self::TYPE_EQUALS, '*', null); 0173 } 0174 0175 /** 0176 * Creates a simple custom string filter. 0177 * 0178 * @param string $filter 0179 * @return Zend_Ldap_Filter_String 0180 */ 0181 public static function string($filter) 0182 { 0183 return new Zend_Ldap_Filter_String($filter); 0184 } 0185 0186 /** 0187 * Creates a simple string filter to be used with a mask. 0188 * 0189 * @param string $mask 0190 * @param string $value 0191 * @return Zend_Ldap_Filter_Mask 0192 */ 0193 public static function mask($mask, $value) 0194 { 0195 /** 0196 * Zend_Ldap_Filter_Mask 0197 */ 0198 // require_once 'Zend/Ldap/Filter/Mask.php'; 0199 return new Zend_Ldap_Filter_Mask($mask, $value); 0200 } 0201 0202 /** 0203 * Creates an 'and' filter. 0204 * 0205 * @param Zend_Ldap_Filter_Abstract $filter,... 0206 * @return Zend_Ldap_Filter_And 0207 */ 0208 public static function andFilter($filter) 0209 { 0210 /** 0211 * Zend_Ldap_Filter_And 0212 */ 0213 // require_once 'Zend/Ldap/Filter/And.php'; 0214 return new Zend_Ldap_Filter_And(func_get_args()); 0215 } 0216 0217 /** 0218 * Creates an 'or' filter. 0219 * 0220 * @param Zend_Ldap_Filter_Abstract $filter,... 0221 * @return Zend_Ldap_Filter_Or 0222 */ 0223 public static function orFilter($filter) 0224 { 0225 /** 0226 * Zend_Ldap_Filter_Or 0227 */ 0228 // require_once 'Zend/Ldap/Filter/Or.php'; 0229 return new Zend_Ldap_Filter_Or(func_get_args()); 0230 } 0231 0232 /** 0233 * Create a filter string. 0234 * 0235 * @param string $attr 0236 * @param string $value 0237 * @param string $filtertype 0238 * @param string $prepend 0239 * @param string $append 0240 * @return string 0241 */ 0242 private static function _createFilterString($attr, $value, $filtertype, $prepend = null, $append = null) 0243 { 0244 $str = $attr . $filtertype; 0245 if ($prepend !== null) $str .= $prepend; 0246 $str .= self::escapeValue($value); 0247 if ($append !== null) $str .= $append; 0248 return $str; 0249 } 0250 0251 /** 0252 * Creates a new Zend_Ldap_Filter. 0253 * 0254 * @param string $attr 0255 * @param string $value 0256 * @param string $filtertype 0257 * @param string $prepend 0258 * @param string $append 0259 */ 0260 public function __construct($attr, $value, $filtertype, $prepend = null, $append = null) 0261 { 0262 $filter = self::_createFilterString($attr, $value, $filtertype, $prepend, $append); 0263 parent::__construct($filter); 0264 } 0265 }