\Horde_Ldap_Search

Result set of an LDAP search

Copyright 2009 Jan Wagner, Benedikt Hallinger Copyright 2010-2017 Horde LLC (http://www.horde.org/)

Summary

Methods
Properties
Constants
__construct()
__destruct()
entries()
shiftEntry()
popEntry()
sortedAsArray()
sorted()
asArray()
setSearch()
setLink()
count()
getErrorCode()
sizeLimitExceeded()
current()
key()
next()
valid()
rewind()
No public properties found
No constants found
searchedAttributes()
$_search
$_link
$_ldap
$_entry
$_errorCode
$_iteratorCache
$_searchedAttrs
$_entry_cache
N/A
No private methods found
No private properties found
N/A

Properties

$_search

$_search : resource

Search result identifier.

Type

resource

$_link

$_link : resource

LDAP resource link.

Type

resource

$_ldap

$_ldap : \Horde_Ldap

Horde_Ldap object.

A reference of the Horde_Ldap object for passing to Horde_Ldap_Entry.

Type

\Horde_Ldap

$_entry

$_entry : resource

Result entry identifier.

Type

resource

$_errorCode

$_errorCode : integer

The errorcode from the search.

Some errorcodes might be of interest that should not be considered errors, for example:

  • 4: LDAP_SIZELIMIT_EXCEEDED - indicates a huge search. Incomplete results are returned. If you just want to check if there is anything returned by the search at all, this could be catched.
  • 32: no such object - search here returns a count of 0.

Type

integer

$_iteratorCache

$_iteratorCache : array

Cache for all entries already fetched from iterator interface.

Type

array

$_searchedAttrs

$_searchedAttrs : array

Attributes we searched for.

This variable gets set from the constructor and can be retrieved through \searchedAttributes().

Type

array

$_entry_cache

$_entry_cache : array

Cache variable for storing entries fetched internally.

This currently is only used by \pop_entry().

Type

array

Methods

__construct()

__construct(resource  $search, \Horde_Ldap|resource  $ldap, array  $attributes = array()) 

Constructor.

Parameters

resource $search

Search result identifier.

\Horde_Ldap|resource $ldap

Horde_Ldap object or a LDAP link resource

array $attributes

The searched attribute names, see {@link $_searchedAttrs}.

__destruct()

__destruct() 

Destructor.

entries()

entries() : array

Returns all entries from the search result.

Throws

\Horde_Ldap_Exception

Returns

array —

All entries.

shiftEntry()

shiftEntry() : \Horde_Ldap_Entry|false

Get the next entry from the search result.

This will return a valid Horde_Ldap_Entry object or false, so you can use this method to easily iterate over the entries inside a while loop.

Throws

\Horde_Ldap_Exception

Returns

\Horde_Ldap_Entry|false —

Reference to Horde_Ldap_Entry object or false if no more entries exist.

popEntry()

popEntry() : \Horde_Ldap_Entry|false

Retrieve the next entry in the search result, but starting from last entry.

This is the opposite to \shiftEntry() and is also very useful to be used inside a while loop.

Throws

\Horde_Ldap_Exception

Returns

\Horde_Ldap_Entry|false

sortedAsArray()

sortedAsArray(array  $attrs = array('cn'), integer  $order = SORT_ASC) : array

Return entries sorted as array.

This returns a array with sorted entries and the values. Sorting is done with PHPs \array_multisort().

This method relies on \asArray() to fetch the raw data of the entries.

Please note that attribute names are case sensitive!

Usage example: // To sort entries first by location, then by surname, but descending: $entries = $search->sortedAsArray(array('locality', 'sn'), SORT_DESC);

Parameters

array $attrs

Attribute names as sort criteria.

integer $order

Ordering direction, either constant SORT_ASC or SORT_DESC

Throws

\Horde_Ldap_Exception

Returns

array —

Sorted entries.

sorted()

sorted(array  $attrs = array('cn'), integer  $order = SORT_ASC) : array

Returns entries sorted as objects.

This returns a array with sorted Horde_Ldap_Entry objects. The sorting is actually done with \sortedAsArray().

Please note that attribute names are case sensitive!

Also note that it is (depending on server capabilities) possible to let the server sort your results. This happens through search controls and is described in detail at http://www.ietf.org/rfc/rfc2891.txt

Usage example: // To sort entries first by location, then by surname, but descending: $entries = $search->sorted(array('locality', 'sn'), SORT_DESC);

Parameters

array $attrs

Attribute names as sort criteria.

integer $order

Ordering direction, either constant SORT_ASC or SORT_DESC

Throws

\Horde_Ldap_Exception

Returns

array —

Sorted entries.

asArray()

asArray() : array

Returns entries as array.

The first array level contains all found entries where the keys are the DNs of the entries. The second level arrays contian the entries attributes such that the keys is the lowercased name of the attribute and the values are stored in another indexed array. Note that the attribute values are stored in an array even if there is no or just one value.

The array has the following structure: array( 'cn=foo,dc=example,dc=com' => array( 'sn' => array('foo'), 'multival' => array('val1', 'val2', 'valN')), 'cn=bar,dc=example,dc=com' => array( 'sn' => array('bar'), 'multival' => array('val1', 'valN')))

Throws

\Horde_Ldap_Exception

Returns

array —

Associative result array as described above.

setSearch()

setSearch(resource  $search) 

Sets the search objects resource link

Parameters

resource $search

Search result identifier.

setLink()

setLink(resource  $link) 

Sets the LDAP resource link.

Parameters

resource $link

LDAP link identifier.

count()

count() : integer

Returns the number of entries in the search result.

Returns

integer —

Number of found entries.

getErrorCode()

getErrorCode() : integer

Returns the errorcode from the search.

Returns

integer —

The LDAP error number.

sizeLimitExceeded()

sizeLimitExceeded() : boolean

Returns wheter this search exceeded a sizelimit.

Returns

boolean —

True if the size limit was exceeded.

current()

current() : \Horde_Ldap_Entry|false

SPL Iterator interface: Returns the current element.

The SPL Iterator interface allows you to fetch entries inside a foreach() loop: foreach ($search as $dn => $entry) { ...

Of course, you may call \current(), \key(), \next(), \rewind() and \valid() yourself.

If the search throwed an error, it returns false. False is also returned, if the end is reached.

In case no call to next() was made, we will issue one, thus returning the first entry.

Throws

\Horde_Ldap_Exception

Returns

\Horde_Ldap_Entry|false

key()

key() : string|false

SPL Iterator interface: Returns the identifying key (DN) of the current entry.

Returns

string|false —

DN of the current entry; false in case no entry is returned by current().

next()

next() 

SPL Iterator interface: Moves forward to next entry.

After a call to \next(), \current() will return the next entry in the result set.

Throws

\Horde_Ldap_Exception

valid()

valid() : boolean

SPL Iterator interface: Checks if there is a current element after calls to {@link rewind()} or {@link next()}.

Used to check if we've iterated to the end of the collection.

Returns

boolean —

False if there's nothing more to iterate over.

rewind()

rewind() 

SPL Iterator interface: Rewinds the Iterator to the first element.

After rewinding, \current() will return the first entry in the result set.

searchedAttributes()

searchedAttributes() : array

Returns the attribute names this search selected.

Returns

array