Class Horde_Ldap_Filter
Object representation of a part of a LDAP filter.
The purpose of this class is to easily build LDAP filters without having to
worry about correct escaping etc.
A filter is built using several independent filter objects which are
combined afterwards. This object works in two modes, depending how the
object is created.
If the object is created using the Horde_Ldap_Filter::create()
method, then this is a
leaf-object. If the object is created using the Horde_Ldap_Filter::combine()
method,
then this is a container object.
LDAP filters are defined in RFC 2254.
Package: Ldap
Category:
Horde
License:
LGPL-3.0
Author:
Benedikt Hallinger
beni@php.net
Author:
Jan Schneider
jan@horde.org
See:
http://www.ietf.org/rfc/rfc2254.txt
A short example:
$filter0 = Horde_Ldap_Filter::create('stars'
, 'equals'
,
'***');
$filter_not0 = Horde_Ldap_Filter::combine('not'
, $filter0);
$filter1 = Horde_Ldap_Filter::create('gn'
, 'begins'
,
'bar');
$filter2 = Horde_Ldap_Filter::create('gn'
, 'ends'
,
'baz');
$filter_comp = Horde_Ldap_Filter::combine('or'
, array($filter_not0
, $filter1
, $filter2));
echo (string)$filter_comp;
// This will output: (|(!(stars=\0x5c0x2a\0x5c0x2a\0x5c0x2a))(gn=bar)(gn=baz))
// The stars in $filter0 are treaten as real stars unless you disable escaping.
Copyright 2009 Benedikt Hallinger
Copyright 2010-2012 Horde LLC (http://www.horde.org/)
Located at Horde/Ldap/Filter.php
Methods summary
public static
Horde_Ldap_Filter
|
#
create( string $attribute, string $match, string $value = '', boolean $escape = true )
Creates a new part of an LDAP filter.
Creates a new part of an LDAP filter.
The following matching rules exists:
- equals: One of the attributes values is exactly $value. Please note that case sensitiviness depends on the attributes syntax configured in the server.
- begins: One of the attributes values must begin with $value.
- ends: One of the attributes values must end with $value.
- contains: One of the attributes values must contain $value.
- present | any: The attribute can contain any value but must exist.
- greater: The attributes value is greater than $value.
- less: The attributes value is less than $value.
- greaterOrEqual: The attributes value is greater or equal than $value.
- lessOrEqual: The attributes value is less or equal than $value.
- approx: One of the attributes values is similar to $value.
If $escape is set to true then $value will be escaped. If set to false
then $value will be treaten as a raw filter value string. You should
then escape it yourself using Horde_Ldap_Util::escapeFilterValue() .
Examples:
$filter = Horde_Ldap_Filter::create('sn', 'ends', 'foobar');
$filter = Horde_Ldap_Filter::create('sn', 'any');
Parameters
- $attribute
- <p>Name of the attribute the filter should apply
to.</p>
- $match
- <p>Matching rule (equals, begins, ends, contains,
greater, less, greaterOrEqual, lessOrEqual,
approx, any).</p>
- $value
- If given, then this is used as a filter value.
- $escape
- Should $value be escaped?
Returns
Throws
|
public static
Horde_Ldap_Filter
|
#
combine( string $operator, array|Horde_Ldap_Filter |string $filters )
Combines two or more filter objects using a logical operator.
Combines two or more filter objects using a logical operator.
Example:
$filter = Horde_Ldap_Filter::combine('or', array($filter1, $filter2));
If the array contains filter strings instead of filter objects, they
will be parsed.
Parameters
- $operator
- <p>The logical operator, either "and", "or", "not" or the logical
equivalents "&", "|", "!".</p>
- $filters
- <p>Array with Horde_Ldap_Filter objects and/or strings or a single
filter when using the "not" operator.</p>
Returns
Throws
|
public static
Horde_Ldap_Filter
|
#
build( array $params, string $operator = 'and' )
Builds a filter (commonly for objectClass attributes) from different
configuration options.
Builds a filter (commonly for objectClass attributes) from different
configuration options.
Parameters
- $params
- <p>Hash with configuration options that build the
search filter. Possible hash keys:
- 'filter': An LDAP filter string.
- 'objectclass' (string): An objectClass name.
- 'objectclass' (array): A list of objectClass
names.</p>
- $operator
- <p>How to combine mutliple 'objectclass' entries.
'and' or 'or'.</p>
Returns
Throws
|
public static
Horde_Ldap_Filter
|
#
parse( string $filter )
Parses a string into a Horde_Ldap_Filter object.
Parses a string into a Horde_Ldap_Filter object.
Parameters
- $filter
- An LDAP filter string.
Returns
Throws
|
public
string
|
#
__toString( )
Returns the string representation of this filter.
Returns the string representation of this filter.
This method runs through all filter objects and creates the string
representation of the filter.
Returns
string
|