Net_LDAP2
[ class tree: Net_LDAP2 ] [ index: Net_LDAP2 ] [ all elements ]

Class: Net_LDAP2_Search

Source Location: /Net_LDAP2-2.1.0/Net/LDAP2/Search.php

Class Overview

PEAR
   |
   --Net_LDAP2_Search

Result set of an LDAP search


Author(s):

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 33]
Result set of an LDAP search


[ Top ]


Class Variables

$_count_cache =  null

[line 123]

Cache variable for count()

Type:   int


[ Top ]

$_entry =  null

[line 67]

Result entry identifier
  • Access: protected

Type:   resource


[ Top ]

$_entry_cache =  false

[line 114]

Cache variable for storing entries fetched internally

This currently is not used by all functions and need consolidation.

  • Access: protected

Type:   array


[ Top ]

$_errorCode =  0

[line 81]

The errorcode the search got

Some errorcodes might be of interest, but might not be best handled as errors. examples: 4 - LDAP_SIZELIMIT_EXCEEDED - indicates a huge search. Incomplete results are returned. If you just want to check if there's anything in the search. than this is a point to handle. 32 - no such object - search here returns a count of 0.

  • Access: protected

Type:   int


[ Top ]

$_iteratorCache = array()

[line 89]

Cache for all entries already fetched from iterator interface
  • Access: protected

Type:   array


[ Top ]

$_ldap =

[line 59]

Net_LDAP2 object

A reference of the Net_LDAP2 object for passing to Net_LDAP2_Entry

  • Access: protected

Type:   object Net_LDAP2


[ Top ]

$_link =

[line 49]

LDAP resource link
  • Access: protected

Type:   resource


[ Top ]

$_search =

[line 41]

Search result identifier
  • Access: protected

Type:   resource


[ Top ]

$_searchedAttrs = array()

[line 104]

What attributes we searched for

The $attributes array contains the names of the searched attributes and gets passed from $Net_LDAP2->search() so the Net_LDAP2_Search object can tell what attributes was searched for (searchedAttrs())searchedAttrs()

  • Access: protected

Type:   array


[ Top ]



Method Detail

__construct (Constructor)   [line 134]

Net_LDAP2_Search __construct( resource &$search, Net_LDAP2|resource &$ldap, [array $attributes = array()])

Constructor
  • Access: public

Parameters:

resource   &$search     Search result identifier
Net_LDAP2|resource   &$ldap     Net_LDAP2 object or just a LDAP-Link resource
array   $attributes     (optional) Array with searched attribute names. (see $_searchedAttrs)

[ Top ]

_Net_LDAP2_Search (Destructor)   [line 499]

void _Net_LDAP2_Search( )

Destructor
  • Access: public

[ Top ]

as_struct   [line 419]

array as_struct( )

Return entries as array

This method returns the entries and the selected attributes values 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:

  1.  $return = array(
  2.            'cn=foo,dc=example,dc=com' => array(
  3.                                                 'sn'       => array('foo'),
  4.                                                 'multival' => array('val1''val2''valN')
  5.                                              )
  6.            'cn=bar,dc=example,dc=com' => array(
  7.                                                 'sn'       => array('bar'),
  8.                                                 'multival' => array('val1''valN')
  9.                                              )
  10.            )

  • Return: associative result array as described above
  • Access: public

[ Top ]

count   [line 469]

int count( )

Returns the number of entries in the searchresult
  • Return: Number of entries in search.
  • Access: public

[ Top ]

current   [line 558]

Net_LDAP2_Entry|false current( )

SPL Iterator interface: Return the current element.

The SPL Iterator interface allows you to fetch entries inside a foreach() loop:

  1. 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.

  • Access: public

[ Top ]

done   [line 509]

void done( )

Closes search result
  • Access: public

[ Top ]

entries   [line 159]

array entries( )

Returns an array of entry objects.
  • Return: Array of entry objects.
  • Access: public

[ Top ]

getErrorCode   [line 489]

int getErrorCode( )

Get the errorcode the object got in its search.
  • Return: The ldap error number.
  • Access: public

[ Top ]

key   [line 574]

string|false key( )

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

[ Top ]

next   [line 589]

void next( )

SPL Iterator interface: Move forward to next entry.

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


[ Top ]

popEntry   [line 223]

Net_LDAP2_Entry|false popEntry( )

Retrieve the next entry in the searchresult, but starting from last entry

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

  • Access: public

[ Top ]

pop_entry   [line 240]

Net_LDAP2_Entry|false pop_entry( )

Alias function of popEntry() for perl-ldap interface

[ Top ]

rewind   [line 625]

void rewind( )

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

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


[ Top ]

searchedAttrs   [line 521]

array searchedAttrs( )

Return the attribute names this search selected

[ Top ]

setLink   [line 459]

void setLink( resource &$link)

Set the ldap ressource link
  • Access: public

Parameters:

resource   &$link     Link identifier

[ Top ]

setSearch   [line 446]

void setSearch( resource &$search)

Set the search objects resource link
  • Access: public

Parameters:

resource   &$search     Search result identifier

[ Top ]

shiftEntry   [line 183]

Net_LDAP2_Entry|false &shiftEntry( )

Get the next entry in the searchresult from LDAP server.

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

  • Return: Reference to Net_LDAP2_Entry object or false
  • Access: public

[ Top ]

shift_entry   [line 209]

Net_LDAP2_Entry|false shift_entry( )

Alias function of shiftEntry() for perl-ldap interface

[ Top ]

sizeLimitExceeded   [line 531]

boolean sizeLimitExceeded( )

Tells if this search exceeds a sizelimit
  • Access: public

[ Top ]

sorted   [line 374]

array|Net_LDAP2_Error sorted( [array $attrs = array('cn')], [int $order = SORT_ASC])

Return entries sorted as objects

This returns a array with sorted Net_LDAP2_Entry objects. The sorting is actually done with sorted_as_struct().

Please note that attribute names are case sensitive! Also note, that it is (depending on server capabilitys) 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:

  1.    // to sort entries first by location, then by surename, but descending:
  2.    $entries $search->sorted(array('locality','sn')SORT_DESC);

  • Return: Array with sorted Net_LDAP2_Entries or error
  • Todo: Entry object construction could be faster. Maybe we could use one of the factorys instead of fetching the entry again
  • Access: public

Parameters:

array   $attrs     Array of sort attributes to sort; order from left to right.
int   $order     Ordering direction, either constant SORT_ASC or SORT_DESC

[ Top ]

sorted_as_struct   [line 267]

array|Net_LDAP2_Error sorted_as_struct( [array $attrs = array('cn')], [int $order = SORT_ASC])

Return entries sorted as array

This returns a array with sorted entries and the values. Sorting is done with PHPs http://www.php.net/array_multisort. This method relies on as_struct() to fetch the raw data of the entries.

Please note that attribute names are case sensitive!

Usage example:

  1.    // to sort entries first by location, then by surename, but descending:
  2.    $entries $search->sorted_as_struct(array('locality','sn')SORT_DESC);

  • Return: Array with sorted entries or error
  • Todo: what about server side sorting as specified in http://www.ietf.org/rfc/rfc2891.txt?
  • Access: public

Parameters:

array   $attrs     Array of attribute names to sort; order from left to right.
int   $order     Ordering direction, either constant SORT_ASC or SORT_DESC

[ Top ]

valid   [line 612]

boolean valid( )

SPL Iterator interface: Check if there is a current element after calls to http://www.php.net/rewind or http://www.php.net/next.

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


[ Top ]


Documentation generated on Mon, 09 Dec 2013 10:30:09 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.