PHP Class Horde_Ldap_Search, horde

Copyright 2009 Jan Wagner, Benedikt Hallinger Copyright 2010-2016 Horde LLC (http://www.horde.org/)
Author: Tarjej Huse ([email protected])
Author: Benedikt Hallinger ([email protected])
Author: Jan Schneider ([email protected])
Inheritance: implements Iterator
Mostrar archivo Open project: horde/horde Class Usage Examples

Protected Properties

Property Type Description
$_entry resource Result entry identifier.
$_entry_cache array This currently is only used by {@link pop_entry()}.
$_errorCode integer 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.
$_iteratorCache array Cache for all entries already fetched from iterator interface.
$_ldap Horde_Ldap A reference of the Horde_Ldap object for passing to Horde_Ldap_Entry.
$_link resource LDAP resource link.
$_search resource Search result identifier.
$_searchedAttrs array This variable gets set from the constructor and can be retrieved through {@link searchedAttributes()}.

Public Methods

Method Description
__construct ( resource $search, Horde_Ldap | resource $ldap, array $attributes = [] ) Constructor.
__destruct ( ) Destructor.
asArray ( ) : array Returns entries as array.
count ( ) : integer Returns the number of entries in the search result.
current ( ) : Horde_Ldap_Entry | false SPL Iterator interface: Returns the current element.
entries ( ) : array Returns all entries from the search result.
getErrorCode ( ) : integer Returns the errorcode from the search.
key ( ) : string | false SPL Iterator interface: Returns the identifying key (DN) of the current entry.
next ( ) SPL Iterator interface: Moves forward to next entry.
popEntry ( ) : Horde_Ldap_Entry | false Retrieve the next entry in the search result, but starting from last entry.
rewind ( ) SPL Iterator interface: Rewinds the Iterator to the first element.
setLink ( resource $link ) Sets the LDAP resource link.
setSearch ( resource $search ) Sets the search objects resource link
shiftEntry ( ) : Horde_Ldap_Entry | false Get the next entry from the search result.
sizeLimitExceeded ( ) : boolean Returns wheter this search exceeded a sizelimit.
sorted ( array $attrs = ['cn'], integer $order = SORT_ASC ) : array Returns entries sorted as objects.
sortedAsArray ( array $attrs = ['cn'], integer $order = SORT_ASC ) : array Return entries sorted as array.
valid ( ) : boolean SPL Iterator interface: Checks if there is a current element after calls to {@link rewind()} or {@link next()}.

Protected Methods

Method Description
searchedAttributes ( ) : array Returns the attribute names this search selected.

Method Details

__construct() public method

Constructor.
public __construct ( resource $search, Horde_Ldap | resource $ldap, array $attributes = [] )
$search resource Search result identifier.
$ldap Horde_Ldap | resource Horde_Ldap object or a LDAP link resource
$attributes array The searched attribute names, see {@link $_searchedAttrs}.

__destruct() public method

Destructor.
public __destruct ( )

asArray() public method

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')))
public asArray ( ) : array
return array Associative result array as described above.

count() public method

Returns the number of entries in the search result.
public count ( ) : integer
return integer Number of found entries.

current() public method

The SPL Iterator interface allows you to fetch entries inside a foreach() loop: foreach ($search as $dn => $entry) { ... Of course, you may call {@link current()}, {@link key()}, {@link next()}, {@link rewind()} and {@link 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.
public current ( ) : Horde_Ldap_Entry | false
return Horde_Ldap_Entry | false

entries() public method

Returns all entries from the search result.
public entries ( ) : array
return array All entries.

getErrorCode() public method

Returns the errorcode from the search.
public getErrorCode ( ) : integer
return integer The LDAP error number.

key() public method

SPL Iterator interface: Returns the identifying key (DN) of the current entry.
See also: current()
public key ( ) : string | false
return string | false DN of the current entry; false in case no entry is returned by current().

next() public method

After a call to {@link next()}, {@link current()} will return the next entry in the result set.
See also: current()
public next ( )

popEntry() public method

This is the opposite to {@link shiftEntry()} and is also very useful to be used inside a while loop.
public popEntry ( ) : Horde_Ldap_Entry | false
return Horde_Ldap_Entry | false

rewind() public method

After rewinding, {@link current()} will return the first entry in the result set.
See also: current()
public rewind ( )

searchedAttributes() protected method

Returns the attribute names this search selected.
protected searchedAttributes ( ) : array
return array

setSearch() public method

Sets the search objects resource link
public setSearch ( resource $search )
$search resource Search result identifier.

shiftEntry() public method

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.
public shiftEntry ( ) : Horde_Ldap_Entry | false
return Horde_Ldap_Entry | false Reference to Horde_Ldap_Entry object or false if no more entries exist.

sizeLimitExceeded() public method

Returns wheter this search exceeded a sizelimit.
public sizeLimitExceeded ( ) : boolean
return boolean True if the size limit was exceeded.

sorted() public method

This returns a array with sorted Horde_Ldap_Entry objects. The sorting is actually done with {@link 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 {@link 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);
public sorted ( array $attrs = ['cn'], integer $order = SORT_ASC ) : array
$attrs array Attribute names as sort criteria.
$order integer Ordering direction, either constant SORT_ASC or SORT_DESC
return array Sorted entries.

sortedAsArray() public method

This returns a array with sorted entries and the values. Sorting is done with PHPs {@link array_multisort()}. This method relies on {@link 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);
public sortedAsArray ( array $attrs = ['cn'], integer $order = SORT_ASC ) : array
$attrs array Attribute names as sort criteria.
$order integer Ordering direction, either constant SORT_ASC or SORT_DESC
return array Sorted entries.

valid() public method

Used to check if we've iterated to the end of the collection.
See also: current()
public valid ( ) : boolean
return boolean False if there's nothing more to iterate over.

Property Details

$_entry protected_oe property

Result entry identifier.
protected resource $_entry
return resource

$_entry_cache protected_oe property

This currently is only used by {@link pop_entry()}.
protected array $_entry_cache
return array

$_errorCode protected_oe property

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.
protected int $_errorCode
return integer

$_iteratorCache protected_oe property

Cache for all entries already fetched from iterator interface.
protected array $_iteratorCache
return array

$_ldap protected_oe property

A reference of the Horde_Ldap object for passing to Horde_Ldap_Entry.
protected Horde_Ldap $_ldap
return Horde_Ldap

$_searchedAttrs protected_oe property

This variable gets set from the constructor and can be retrieved through {@link searchedAttributes()}.
protected array $_searchedAttrs
return array