Horde_Ldap_Filter
in package
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 method, then this is a leaf-object. If the object is created using the method, then this is a container object.
LDAP filters are defined in RFC 2254.
Tags
Table of Contents
- $_filter : string
- Single filter.
- $_filters : array<string|int, mixed>
- Storage for combination of filters.
- $_operator : string
- Operator for sub-filters.
- __toString() : string
- Returns the string representation of this filter.
- build() : Horde_Ldap_Filter
- Builds a filter (commonly for objectClass attributes) from different configuration options.
- combine() : Horde_Ldap_Filter
- Combines two or more filter objects using a logical operator.
- create() : Horde_Ldap_Filter
- Creates a new part of an LDAP filter.
- parse() : Horde_Ldap_Filter
- Parses a string into a Horde_Ldap_Filter object.
- __construct() : mixed
- Constructor.
- _parseCombination() : Horde_Ldap_Filter
- Parses combined subfilter strings.
- _parseLeaf() : Horde_Ldap_Filter
- Parses a single leaf component.
Properties
$_filter
Single filter.
protected
string
$_filter
If this is a leaf filter, the filter representation is store here.
$_filters
Storage for combination of filters.
protected
array<string|int, mixed>
$_filters
= array()
This variable holds a array of filter objects that should be combined by this filter object.
$_operator
Operator for sub-filters.
protected
string
$_operator
Methods
__toString()
Returns the string representation of this filter.
public
__toString() : string
This method runs through all filter objects and creates the string representation of the filter.
Return values
string —build()
Builds a filter (commonly for objectClass attributes) from different configuration options.
public
static build(array<string|int, mixed> $params[, string $operator = 'and' ]) : Horde_Ldap_Filter
Parameters
- $params : array<string|int, mixed>
-
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 = 'and'
-
How to combine mutliple 'objectclass' entries. 'and' or 'or'.
Tags
Return values
Horde_Ldap_Filter —A filter matching the specified criteria.
combine()
Combines two or more filter objects using a logical operator.
public
static combine(string $operator, array<string|int, mixed>|Horde_Ldap_Filter|string $filters) : Horde_Ldap_Filter
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 : string
-
The logical operator, either "and", "or", "not" or the logical equivalents "&", "|", "!".
- $filters : array<string|int, mixed>|Horde_Ldap_Filter|string
-
Array with Horde_Ldap_Filter objects and/or strings or a single filter when using the "not" operator.
Tags
Return values
Horde_Ldap_Filter —create()
Creates a new part of an LDAP filter.
public
static create(string $attribute, string $match[, string $value = '' ][, bool $escape = true ]) : Horde_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 .
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
- $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 : bool = true
-
Should $value be escaped?
Tags
Return values
Horde_Ldap_Filter —parse()
Parses a string into a Horde_Ldap_Filter object.
public
static parse(string $filter) : Horde_Ldap_Filter
Parameters
- $filter : string
-
An LDAP filter string.
Tags
Return values
Horde_Ldap_Filter —__construct()
Constructor.
protected
__construct(array<string|int, mixed> $params) : mixed
Construction of Horde_Ldap_Filter objects should happen through either or which give you more control. However, you may use the constructor if you already have generated filters.
Parameters
- $params : array<string|int, mixed>
-
List of object parameters
Return values
mixed —_parseCombination()
Parses combined subfilter strings.
protected
static _parseCombination(string $filter) : Horde_Ldap_Filter
Passes subfilters to parse() and combines the objects using the logical operator detected. Each subfilter could be an arbitary complex subfilter.
Parameters
- $filter : string
-
An LDAP filter string.
Tags
Return values
Horde_Ldap_Filter —_parseLeaf()
Parses a single leaf component.
protected
static _parseLeaf(string $filter) : Horde_Ldap_Filter
Parameters
- $filter : string
-
An LDAP filter string.