Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Ldap / Filter / AbstractFilter.php
blobc64108263da1ab07bdd8837ce8caf38990cd9b67
1 <?php
2 /**
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
8 */
10 namespace Zend\Ldap\Filter;
12 use Zend\Ldap\Converter\Converter;
14 /**
15 * Zend\Ldap\Filter\AbstractFilter provides a base implementation for filters.
17 abstract class AbstractFilter
19 /**
20 * Returns a string representation of the filter.
22 * @return string
24 abstract public function toString();
26 /**
27 * Returns a string representation of the filter.
28 * @see toString()
30 * @return string
32 public function __toString()
34 return $this->toString();
37 /**
38 * Negates the filter.
40 * @return AbstractFilter
42 public function negate()
44 return new NotFilter($this);
47 /**
48 * Creates an 'and' filter.
50 * @param AbstractFilter $filter,...
51 * @return AndFilter
53 public function addAnd($filter)
55 $fa = func_get_args();
56 $args = array_merge(array($this), $fa);
57 return new AndFilter($args);
60 /**
61 * Creates an 'or' filter.
63 * @param AbstractFilter $filter,...
64 * @return OrFilter
66 public function addOr($filter)
68 $fa = func_get_args();
69 $args = array_merge(array($this), $fa);
70 return new OrFilter($args);
73 /**
74 * Escapes the given VALUES according to RFC 2254 so that they can be safely used in LDAP filters.
76 * Any control characters with an ACII code < 32 as well as the characters with special meaning in
77 * LDAP filters "*", "(", ")", and "\" (the backslash) are converted into the representation of a
78 * backslash followed by two hex digits representing the hexadecimal value of the character.
79 * @see Net_LDAP2_Util::escape_filter_value() from Benedikt Hallinger <beni@php.net>
80 * @link http://pear.php.net/package/Net_LDAP2
81 * @author Benedikt Hallinger <beni@php.net>
83 * @param string|array $values Array of values to escape
84 * @return array Array $values, but escaped
86 public static function escapeValue($values = array())
88 if (!is_array($values)) {
89 $values = array($values);
91 foreach ($values as $key => $val) {
92 // Escaping of filter meta characters
93 $val = str_replace(array('\\', '*', '(', ')'), array('\5c', '\2a', '\28', '\29'), $val);
94 // ASCII < 32 escaping
95 $val = Converter::ascToHex32($val);
96 if (null === $val) {
97 $val = '\0'; // apply escaped "null" if string is empty
99 $values[$key] = $val;
101 return (count($values) == 1) ? $values[0] : $values;
105 * Undoes the conversion done by {@link escapeValue()}.
107 * Converts any sequences of a backslash followed by two hex digits into the corresponding character.
108 * @see Net_LDAP2_Util::escape_filter_value() from Benedikt Hallinger <beni@php.net>
109 * @link http://pear.php.net/package/Net_LDAP2
110 * @author Benedikt Hallinger <beni@php.net>
112 * @param string|array $values Array of values to escape
113 * @return array Array $values, but unescaped
115 public static function unescapeValue($values = array())
117 if (!is_array($values)) {
118 $values = array($values);
120 foreach ($values as $key => $value) {
121 // Translate hex code into ascii
122 $values[$key] = Converter::hex32ToAsc($value);
124 return (count($values) == 1) ? $values[0] : $values;