PHP Class Horde_Ldap_Filter, horde

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 {@link create()} method, then this is a leaf-object. If the object is created using the {@link combine()} method, then this is a container object. LDAP filters are defined in RFC 2254.
See also: 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-2016 Horde LLC (http://www.horde.org/)
Author: Benedikt Hallinger ([email protected])
Author: Jan Schneider ([email protected])
ファイルを表示 Open project: horde/horde Class Usage Examples

Protected Properties

Property Type Description
$_filter string If this is a leaf filter, the filter representation is store here.
$_filters array This variable holds a array of filter objects that should be combined by this filter object.
$_operator string Operator for sub-filters.

Public Methods

Method Description
__toString ( ) : string Returns the string representation of this filter.
build ( array $params, string $operator = 'and' ) : Horde_Ldap_Filter Builds a filter (commonly for objectClass attributes) from different configuration options.
combine ( string $operator, array | Horde_Ldap_Filter | string $filters ) : Horde_Ldap_Filter Combines two or more filter objects using a logical operator.
create ( string $attribute, string $match, string $value = '', boolean $escape = true ) : Horde_Ldap_Filter Creates a new part of an LDAP filter.
parse ( string $filter ) : Horde_Ldap_Filter Parses a string into a Horde_Ldap_Filter object.

Protected Methods

Method Description
__construct ( array $params ) Constructor.
_parseCombination ( string $filter ) : Horde_Ldap_Filter Parses combined subfilter strings.
_parseLeaf ( string $filter ) : Horde_Ldap_Filter Parses a single leaf component.

Method Details

__construct() protected method

Construction of Horde_Ldap_Filter objects should happen through either {@link create()} or {@link combine()} which give you more control. However, you may use the constructor if you already have generated filters.
protected __construct ( array $params )
$params array List of object parameters

__toString() public method

This method runs through all filter objects and creates the string representation of the filter.
public __toString ( ) : string
return string

_parseCombination() protected static method

Passes subfilters to parse() and combines the objects using the logical operator detected. Each subfilter could be an arbitary complex subfilter.
protected static _parseCombination ( string $filter ) : Horde_Ldap_Filter
$filter string An LDAP filter string.
return Horde_Ldap_Filter

_parseLeaf() protected static method

Parses a single leaf component.
protected static _parseLeaf ( string $filter ) : Horde_Ldap_Filter
$filter string An LDAP filter string.
return Horde_Ldap_Filter

build() public static method

Builds a filter (commonly for objectClass attributes) from different configuration options.
public static build ( array $params, string $operator = 'and' ) : Horde_Ldap_Filter
$params array 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.
$operator string How to combine mutliple 'objectclass' entries. 'and' or 'or'.
return Horde_Ldap_Filter A filter matching the specified criteria.

combine() public static method

Example: $filter = Horde_Ldap_Filter::combine('or', array($filter1, $filter2)); If the array contains filter strings instead of filter objects, they will be parsed.
public static combine ( string $operator, array | Horde_Ldap_Filter | string $filters ) : Horde_Ldap_Filter
$operator string The logical operator, either "and", "or", "not" or the logical equivalents "&", "|", "!".
$filters array | Horde_Ldap_Filter | string Array with Horde_Ldap_Filter objects and/or strings or a single filter when using the "not" operator.
return Horde_Ldap_Filter

create() public static method

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 {@link Horde_Ldap_Util::escapeFilterValue()}. Examples: This will find entries that contain an attribute "sn" that ends with "foobar": $filter = Horde_Ldap_Filter::create('sn', 'ends', 'foobar'); This will find entries that contain an attribute "sn" that has any value set: $filter = Horde_Ldap_Filter::create('sn', 'any');
public static create ( string $attribute, string $match, string $value = '', boolean $escape = true ) : Horde_Ldap_Filter
$attribute string Name of the attribute the filter should apply to.
$match string Matching rule (equals, begins, ends, contains, greater, less, greaterOrEqual, lessOrEqual, approx, any).
$value string If given, then this is used as a filter value.
$escape boolean Should $value be escaped?
return Horde_Ldap_Filter

parse() public static method

Parses a string into a Horde_Ldap_Filter object.
public static parse ( string $filter ) : Horde_Ldap_Filter
$filter string An LDAP filter string.
return Horde_Ldap_Filter

Property Details

$_filter protected_oe property

If this is a leaf filter, the filter representation is store here.
protected string $_filter
return string

$_filters protected_oe property

This variable holds a array of filter objects that should be combined by this filter object.
protected array $_filters
return array

$_operator protected_oe property

Operator for sub-filters.
protected string $_operator
return string