\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 \create() method, then this is a leaf-object. If the object is created using the \combine() method, then this is a container object.

LDAP filters are defined in RFC 2254.

Summary

Methods
Properties
Constants
create()
combine()
build()
parse()
__toString()
No public properties found
No constants found
__construct()
_parseCombination()
_parseLeaf()
$_filters
$_operator
$_filter
N/A
No private methods found
No private properties found
N/A

Properties

$_filters

$_filters : array

Storage for combination of filters.

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

Type

array

$_operator

$_operator : string

Operator for sub-filters.

Type

string

$_filter

$_filter : string

Single filter.

If this is a leaf filter, the filter representation is store here.

Type

string

Methods

create()

create(string  $attribute, string  $match, string  $value = '', boolean  $escape = true) : \Horde_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 {@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');

Parameters

string $attribute

Name of the attribute the filter should apply to.

string $match

Matching rule (equals, begins, ends, contains, greater, less, greaterOrEqual, lessOrEqual, approx, any).

string $value

If given, then this is used as a filter value.

boolean $escape

Should $value be escaped?

Throws

\Horde_Ldap_Exception

Returns

\Horde_Ldap_Filter

combine()

combine(string  $operator, array|\Horde_Ldap_Filter|string  $filters) : \Horde_Ldap_Filter

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

string $operator

The logical operator, either "and", "or", "not" or the logical equivalents "&", "|", "!".

array|\Horde_Ldap_Filter|string $filters

Array with Horde_Ldap_Filter objects and/or strings or a single filter when using the "not" operator.

Throws

\Horde_Ldap_Exception

Returns

\Horde_Ldap_Filter

build()

build(array  $params, string  $operator = 'and') : \Horde_Ldap_Filter

Builds a filter (commonly for objectClass attributes) from different configuration options.

Parameters

array $params

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.
string $operator

How to combine mutliple 'objectclass' entries. 'and' or 'or'.

Throws

\Horde_Ldap_Exception

Returns

\Horde_Ldap_Filter

A filter matching the specified criteria.

parse()

parse(string  $filter) : \Horde_Ldap_Filter

Parses a string into a Horde_Ldap_Filter object.

Parameters

string $filter

An LDAP filter string.

Throws

\Horde_Ldap_Exception

Returns

\Horde_Ldap_Filter

__toString()

__toString() : string

Returns the string representation of this filter.

This method runs through all filter objects and creates the string representation of the filter.

Returns

string

__construct()

__construct(array  $params) 

Constructor.

Construction of Horde_Ldap_Filter objects should happen through either \create() or \combine() which give you more control. However, you may use the constructor if you already have generated filters.

Parameters

array $params

List of object parameters

_parseCombination()

_parseCombination(string  $filter) : \Horde_Ldap_Filter

Parses combined subfilter strings.

Passes subfilters to parse() and combines the objects using the logical operator detected. Each subfilter could be an arbitary complex subfilter.

Parameters

string $filter

An LDAP filter string.

Throws

\Horde_Ldap_Exception

Returns

\Horde_Ldap_Filter

_parseLeaf()

_parseLeaf(string  $filter) : \Horde_Ldap_Filter

Parses a single leaf component.

Parameters

string $filter

An LDAP filter string.

Throws

\Horde_Ldap_Exception

Returns

\Horde_Ldap_Filter