Overview

Packages

  • Ldap

Classes

  • Horde_Ldap
  • Horde_Ldap_Entry
  • Horde_Ldap_Exception
  • Horde_Ldap_Filter
  • Horde_Ldap_Ldif
  • Horde_Ldap_RootDse
  • Horde_Ldap_Schema
  • Horde_Ldap_Search
  • Horde_Ldap_Util
  • Overview
  • Package
  • Class
  • Tree

Class Horde_Ldap_Search

Result set of an LDAP search

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

Horde_Ldap_Search implements Iterator
Package: Ldap
Category: Horde
License: LGPL-3.0
Author: Tarjej Huse tarjei@bergfald.no
Author: Benedikt Hallinger beni@php.net
Author: Jan Schneider jan@horde.org
Located at Horde/Ldap/Search.php
Methods summary
public
# __construct( resource $search, Horde_Ldap|resource $ldap, array $attributes = array() )

Constructor.

Constructor.

Parameters

$search
Search result identifier.
$ldap
<p>Horde_Ldap object or a LDAP link resource</p>
$attributes
<p>The searched attribute names, see $_searchedAttrs.</p>
public
# __destruct( )

Destructor.

Destructor.

public array
# entries( )

Returns all entries from the search result.

Returns all entries from the search result.

Returns

array
All entries.

Throws

Horde_Ldap_Exception
public Horde_Ldap_Entry|false
# shiftEntry( )

Get the next entry from the search result.

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.

Returns

Horde_Ldap_Entry|false

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

Throws

Horde_Ldap_Exception
public Horde_Ldap_Entry|false
# popEntry( )

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

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

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

Returns

Horde_Ldap_Entry|false

Throws

Horde_Ldap_Exception
public array
# sortedAsArray( array $attrs = array('cn'), integer $order = SORT_ASC )

Return entries sorted as 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 Horde_Ldap_Search::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

$attrs
Attribute names as sort criteria.
$order
<p>Ordering direction, either constant SORT_ASC or SORT_DESC</p>

Returns

array
Sorted entries.

Throws

Horde_Ldap_Exception
public array
# sorted( array $attrs = array('cn'), integer $order = SORT_ASC )

Returns entries sorted as objects.

Returns entries sorted as objects.

This returns a array with sorted Horde_Ldap_Entry objects. The sorting is actually done with Horde_Ldap_Search::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

$attrs
Attribute names as sort criteria.
$order
<p>Ordering direction, either constant SORT_ASC or SORT_DESC</p>

Returns

array
Sorted entries.

Throws

Horde_Ldap_Exception
public array
# asArray( )

Returns entries as 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')))

Returns

array
Associative result array as described above.

Throws

Horde_Ldap_Exception
public
# setSearch( resource $search )

Sets the search objects resource link

Sets the search objects resource link

Parameters

$search
Search result identifier.
public
# setLink( resource $link )

Sets the LDAP resource link.

Sets the LDAP resource link.

Parameters

$link
LDAP link identifier.
public integer
# count( )

Returns the number of entries in the search result.

Returns the number of entries in the search result.

Returns

integer
Number of found entries.
public integer
# getErrorCode( )

Returns the errorcode from the search.

Returns the errorcode from the search.

Returns

integer
The LDAP error number.
public boolean
# sizeLimitExceeded( )

Returns wheter this search exceeded a sizelimit.

Returns wheter this search exceeded a sizelimit.

Returns

boolean
True if the size limit was exceeded.
public Horde_Ldap_Entry|false
# current( )

SPL Iterator interface: Returns the current element.

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 Horde_Ldap_Search::current(), Horde_Ldap_Search::key(), Horde_Ldap_Search::next(), Horde_Ldap_Search::rewind() and Horde_Ldap_Search::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.

Returns

Horde_Ldap_Entry|false

Throws

Horde_Ldap_Exception

Implementation of

Iterator::current()
public string|false
# key( )

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

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().

See

Horde_Ldap_Search::current()

Implementation of

Iterator::key()
public
# next( )

SPL Iterator interface: Moves forward to next entry.

SPL Iterator interface: Moves forward to next entry.

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

Throws

Horde_Ldap_Exception

See

Horde_Ldap_Search::current()

Implementation of

Iterator::next()
public boolean
# valid( )

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

SPL Iterator interface: Checks if there is a current element after calls to Horde_Ldap_Search::rewind() or Horde_Ldap_Search::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.

See

Horde_Ldap_Search::current()

Implementation of

Iterator::valid()
public
# rewind( )

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

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

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

See

Horde_Ldap_Search::current()

Implementation of

Iterator::rewind()
API documentation generated by ApiGen