Zend Framework  1.12
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Zend_Ldap Class Reference

Public Member Functions

 __construct ($options=array())
 Constructor.
 
 __destruct ()
 Destructor.
 
 getResource ()
 
 getLastErrorCode ()
 Return the LDAP error number of the last LDAP command.
 
 getLastError (&$errorCode=null, array &$errorMessages=null)
 Return the LDAP error message of the last LDAP command.
 
 getBoundUser ()
 Get the currently bound user.
 
 setOptions ($options)
 Sets the options used in connecting, binding, etc.
 
 getOptions ()
 
 getBaseDn ()
 Gets the base DN under which objects of interest are located.
 
 getCanonicalAccountName ($acctname, $form=0)
 
 disconnect ()
 
 connect ($host=null, $port=null, $useSsl=null, $useStartTls=null)
 To connect using SSL it seems the client tries to verify the server certificate by default.
 
 bind ($username=null, $password=null)
 
 search ($filter, $basedn=null, $scope=self::SEARCH_SCOPE_SUB, array $attributes=array(), $sort=null, $collectionClass=null, $sizelimit=0, $timelimit=0)
 A global LDAP search routine for finding information.
 
 count ($filter, $basedn=null, $scope=self::SEARCH_SCOPE_SUB)
 Count items found by given filter.
 
 countChildren ($dn)
 Count children for a given DN.
 
 exists ($dn)
 Check if a given DN exists.
 
 searchEntries ($filter, $basedn=null, $scope=self::SEARCH_SCOPE_SUB, array $attributes=array(), $sort=null, $reverseSort=false, $sizelimit=0, $timelimit=0)
 Search LDAP registry for entries matching filter and optional attributes.
 
 getEntry ($dn, array $attributes=array(), $throwOnNotFound=false)
 Get LDAP entry by DN.
 
 add ($dn, array $entry)
 Add new information to the LDAP repository.
 
 update ($dn, array $entry)
 Update LDAP registry.
 
 save ($dn, array $entry)
 Save entry to LDAP registry.
 
 delete ($dn, $recursively=false)
 Delete an LDAP entry.
 
 moveToSubtree ($from, $to, $recursively=false, $alwaysEmulate=false)
 Moves a LDAP entry from one DN to another subtree.
 
 move ($from, $to, $recursively=false, $alwaysEmulate=false)
 Moves a LDAP entry from one DN to another DN.
 
 rename ($from, $to, $recursively=false, $alwaysEmulate=false)
 Renames a LDAP entry from one DN to another DN.
 
 copyToSubtree ($from, $to, $recursively=false)
 Copies a LDAP entry from one DN to another subtree.
 
 copy ($from, $to, $recursively=false)
 Copies a LDAP entry from one DN to another DN.
 
 getNode ($dn)
 Returns the specified DN as a Zend_Ldap_Node.
 
 getBaseNode ()
 Returns the base node as a Zend_Ldap_Node.
 
 getRootDse ()
 Returns the RootDSE.
 
 getSchema ()
 Returns the schema.
 

Static Public Member Functions

static filterEscape ($str)
 
static explodeDn ($dn, array &$keys=null, array &$vals=null)
 
static prepareLdapEntryArray (array &$entry)
 Prepares an ldap data entry array for insert/update operation.
 

Public Attributes

const SEARCH_SCOPE_SUB = 1
 
const SEARCH_SCOPE_ONE = 2
 
const SEARCH_SCOPE_BASE = 3
 
const ACCTNAME_FORM_DN = 1
 
const ACCTNAME_FORM_USERNAME = 2
 
const ACCTNAME_FORM_BACKSLASH = 3
 
const ACCTNAME_FORM_PRINCIPAL = 4
 

Protected Member Functions

 _getHost ()
 
 _getPort ()
 
 _getUseSsl ()
 
 _getUsername ()
 
 _getPassword ()
 
 _getBindRequiresDn ()
 
 _getAccountCanonicalForm ()
 
 _getAccountDomainName ()
 
 _getAccountDomainNameShort ()
 
 _getAccountFilterFormat ()
 
 _getAllowEmptyPassword ()
 
 _getUseStartTls ()
 
 _getOptReferrals ()
 
 _getTryUsernameSplit ()
 
 _getAccountFilter ($acctname)
 
 _splitName ($name, &$dname, &$aname)
 
 _getAccountDn ($acctname)
 
 _isPossibleAuthority ($dname)
 
 _getAccount ($acctname, array $attrs=null)
 
 _createCollection (Zend_Ldap_Collection_Iterator_Default $iterator, $collectionClass)
 Extension point for collection creation.
 
 _getChildrenDns ($parentDn)
 Retrieve the immediate children DNs of the given $parentDn.
 

Protected Attributes

 $_options = null
 
 $_resource = null
 
 $_boundUser = false
 
 $_rootDse = null
 
 $_schema = null
 

Constructor & Destructor Documentation

__construct (   $options = array())

Constructor.

Parameters
array | Zend_Config$optionsOptions used in connecting, binding, etc.
Returns
void
Exceptions
Zend_Ldap_Exceptionif ext/ldap is not installed
See Also
Zend_Ldap_Exception
__destruct ( )

Destructor.

Returns
void

Member Function Documentation

_createCollection ( Zend_Ldap_Collection_Iterator_Default  $iterator,
  $collectionClass 
)
protected

Extension point for collection creation.

Parameters
Zend_Ldap_Collection_Iterator_Default$iterator
string | null$collectionClass
Returns
Zend_Ldap_Collection
Exceptions
Zend_Ldap_Exception

Zend_Ldap_Collection

See Also
Zend_Ldap_Exception
Zend_Ldap_Exception
_getAccount (   $acctname,
array  $attrs = null 
)
protected
Parameters
array$attrsAn array of names of desired attributes
Returns
array An array of the attributes representing the account
Exceptions
Zend_Ldap_Exception
See Also
Zend_Ldap_Exception
Zend_Ldap_Exception
Zend_Ldap_Exception
Zend_Ldap_Exception
Zend_Ldap_Exception
_getAccountCanonicalForm ( )
protected
Returns
integer Either ACCTNAME_FORM_BACKSLASH, ACCTNAME_FORM_PRINCIPAL or ACCTNAME_FORM_USERNAME indicating the form usernames should be canonicalized to.
_getAccountDn (   $acctname)
protected
Parameters
string$acctnameThe name of the account
Returns
string The DN of the specified account
Exceptions
Zend_Ldap_Exception
See Also
Zend_Ldap_Dn
_getAccountDomainName ( )
protected
Returns
string The account domain name
_getAccountDomainNameShort ( )
protected
Returns
string The short account domain name
_getAccountFilter (   $acctname)
protected
Returns
string The LDAP search filter for matching directory accounts
See Also
Zend_Ldap_Filter_Abstract
_getAccountFilterFormat ( )
protected
Returns
string A format string for building an LDAP search filter to match an account
_getAllowEmptyPassword ( )
protected
Returns
boolean Allow empty passwords
_getBindRequiresDn ( )
protected
Returns
boolean Bind requires DN
_getChildrenDns (   $parentDn)
protected

Retrieve the immediate children DNs of the given $parentDn.

This method is used in recursive methods like {

See Also
delete()} or {
copy()}
Parameters
string | Zend_Ldap_Dn$parentDn
Returns
array of DNs
See Also
Zend_Ldap_Exception
_getHost ( )
protected
Returns
string The hostname of the LDAP server being used to authenticate accounts
_getOptReferrals ( )
protected
Returns
boolean Opt. Referrals
_getPassword ( )
protected
Returns
string The default password for binding
_getPort ( )
protected
Returns
int The port of the LDAP server or 0 to indicate that no port value is set
_getTryUsernameSplit ( )
protected
Returns
boolean Try splitting the username into username and domain
_getUsername ( )
protected
Returns
string The default acctname for binding
_getUseSsl ( )
protected
Returns
boolean The default SSL / TLS encrypted transport control
_getUseStartTls ( )
protected
Returns
boolean The default SSL / TLS encrypted transport control
_isPossibleAuthority (   $dname)
protected
Parameters
string$dnameThe domain name to check
Returns
boolean
_splitName (   $name,
$dname,
$aname 
)
protected
Parameters
string$nameThe name to split
string$dnameThe resulting domain name (this is an out parameter)
string$anameThe resulting account name (this is an out parameter)
Returns
void
add (   $dn,
array  $entry 
)

Add new information to the LDAP repository.

Parameters
string | Zend_Ldap_Dn$dn
array$entry
Returns
Zend_Ldap Provides a fluid interface
Exceptions
Zend_Ldap_Exception
See Also
Zend_Ldap_Exception
bind (   $username = null,
  $password = null 
)
Parameters
string$usernameThe username for authenticating the bind
string$passwordThe password for authenticating the bind
Returns
Zend_Ldap Provides a fluent interface
Exceptions
Zend_Ldap_Exception
See Also
Zend_Ldap_Dn
Zend_Ldap_Exception
Zend_Ldap_Exception
Zend_Ldap_Exception
connect (   $host = null,
  $port = null,
  $useSsl = null,
  $useStartTls = null 
)

To connect using SSL it seems the client tries to verify the server certificate by default.

One way to disable this behavior is to set 'TLS_REQCERT never' in OpenLDAP's ldap.conf and restarting Apache. Or, if you really care about the server's cert you can put a cert on the web server.

Parameters
string$hostThe hostname of the LDAP server to connect to
int$portThe port number of the LDAP server to connect to
boolean$useSslUse SSL
boolean$useStartTlsUse STARTTLS
Returns
Zend_Ldap Provides a fluent interface
Exceptions
Zend_Ldap_Exception
See Also
Zend_Ldap_Exception
Zend_Ldap_Exception
Zend_Ldap_Exception
copy (   $from,
  $to,
  $recursively = false 
)

Copies a LDAP entry from one DN to another DN.

Parameters
string | Zend_Ldap_Dn$from
string | Zend_Ldap_Dn$to
boolean$recursively
Returns
Zend_Ldap Provides a fluid interface
Exceptions
Zend_Ldap_Exception
copyToSubtree (   $from,
  $to,
  $recursively = false 
)

Copies a LDAP entry from one DN to another subtree.

Parameters
string | Zend_Ldap_Dn$from
string | Zend_Ldap_Dn$to
boolean$recursively
Returns
Zend_Ldap Provides a fluid interface
Exceptions
Zend_Ldap_Exception
count (   $filter,
  $basedn = null,
  $scope = self::SEARCH_SCOPE_SUB 
)

Count items found by given filter.

Parameters
string | Zend_Ldap_Filter_Abstract$filter
string | Zend_Ldap_Dn | null$basedn
integer$scope
Returns
integer
Exceptions
Zend_Ldap_Exception
countChildren (   $dn)

Count children for a given DN.

Parameters
string | Zend_Ldap_Dn$dn
Returns
integer
Exceptions
Zend_Ldap_Exception
delete (   $dn,
  $recursively = false 
)

Delete an LDAP entry.

Parameters
string | Zend_Ldap_Dn$dn
boolean$recursively
Returns
Zend_Ldap Provides a fluid interface
Exceptions
Zend_Ldap_Exception
See Also
Zend_Ldap_Exception
disconnect ( )
Returns
Zend_Ldap Provides a fluent interface
exists (   $dn)

Check if a given DN exists.

Parameters
string | Zend_Ldap_Dn$dn
Returns
boolean
Exceptions
Zend_Ldap_Exception
static explodeDn (   $dn,
array &  $keys = null,
array &  $vals = null 
)
static
Deprecated:
will be removed, use {
See Also
Zend_Ldap_Dn::checkDn()}
Parameters
string$dnThe DN to parse
array$keysAn optional array to receive DN keys (e.g. CN, OU, DC, ...)
array$valsAn optional array to receive DN values
Returns
boolean True if the DN was successfully parsed or false if the string is not a valid DN.
See Also
Zend_Ldap_Dn
static filterEscape (   $str)
static
Deprecated:
will be removed, use {
See Also
Zend_Ldap_Filter_Abstract::escapeValue()}
Parameters
string$strThe string to escape.
Returns
string The escaped string
See Also
Zend_Ldap_Filter_Abstract
getBaseDn ( )

Gets the base DN under which objects of interest are located.

Returns
string
getBaseNode ( )

Returns the base node as a Zend_Ldap_Node.

Returns
Zend_Ldap_Node
Exceptions
Zend_Ldap_Exception
getBoundUser ( )

Get the currently bound user.

FALSE if no user is bound to the LDAP resource NULL if there has been an anonymous bind username of the currently bound user

Returns
false|null|string
getCanonicalAccountName (   $acctname,
  $form = 0 
)
Parameters
string$acctnameThe name to canonicalize
int$typeThe desired form of canonicalization
Returns
string The canonicalized name in the desired form
Exceptions
Zend_Ldap_Exception
See Also
Zend_Ldap_Exception
Zend_Ldap_Exception
Zend_Ldap_Exception
Zend_Ldap_Exception
Zend_Ldap_Exception
getEntry (   $dn,
array  $attributes = array(),
  $throwOnNotFound = false 
)

Get LDAP entry by DN.

Parameters
string | Zend_Ldap_Dn$dn
array$attributes
boolean$throwOnNotFound
Returns
array
Exceptions
Zend_Ldap_Exception
getLastError ( $errorCode = null,
array &  $errorMessages = null 
)

Return the LDAP error message of the last LDAP command.

Parameters
int$errorCode
array$errorMessages
Returns
string
getLastErrorCode ( )

Return the LDAP error number of the last LDAP command.

Returns
int
See Also
Zend_Ldap_Exception
getNode (   $dn)

Returns the specified DN as a Zend_Ldap_Node.

Parameters
string | Zend_Ldap_Dn$dn
Returns
Zend_Ldap_Node|null
Exceptions
Zend_Ldap_Exception

Zend_Ldap_Node

getOptions ( )
Returns
array The current options.
getResource ( )
Returns
resource The raw LDAP extension resource.
getRootDse ( )

Returns the RootDSE.

Returns
Zend_Ldap_Node_RootDse
Exceptions
Zend_Ldap_Exception
See Also
Zend_Ldap_Node_Schema
getSchema ( )

Returns the schema.

Returns
Zend_Ldap_Node_Schema
Exceptions
Zend_Ldap_Exception
See Also
Zend_Ldap_Node_Schema
move (   $from,
  $to,
  $recursively = false,
  $alwaysEmulate = false 
)

Moves a LDAP entry from one DN to another DN.

This is an alias for rename()

Parameters
string | Zend_Ldap_Dn$from
string | Zend_Ldap_Dn$to
boolean$recursively
boolean$alwaysEmulate
Returns
Zend_Ldap Provides a fluid interface
Exceptions
Zend_Ldap_Exception
moveToSubtree (   $from,
  $to,
  $recursively = false,
  $alwaysEmulate = false 
)

Moves a LDAP entry from one DN to another subtree.

Parameters
string | Zend_Ldap_Dn$from
string | Zend_Ldap_Dn$to
boolean$recursively
boolean$alwaysEmulate
Returns
Zend_Ldap Provides a fluid interface
Exceptions
Zend_Ldap_Exception
static prepareLdapEntryArray ( array &  $entry)
static

Prepares an ldap data entry array for insert/update operation.

Parameters
array$entry
Returns
void
Exceptions
InvalidArgumentException
rename (   $from,
  $to,
  $recursively = false,
  $alwaysEmulate = false 
)

Renames a LDAP entry from one DN to another DN.

This method implicitely moves the entry to another location within the tree.

Parameters
string | Zend_Ldap_Dn$from
string | Zend_Ldap_Dn$to
boolean$recursively
boolean$alwaysEmulate
Returns
Zend_Ldap Provides a fluid interface
Exceptions
Zend_Ldap_Exception
See Also
Zend_Ldap_Exception
save (   $dn,
array  $entry 
)

Save entry to LDAP registry.

Internally decides if entry will be updated to added by calling exists().

Parameters
string | Zend_Ldap_Dn$dn
array$entry
Returns
Zend_Ldap Provides a fluid interface
Exceptions
Zend_Ldap_Exception
search (   $filter,
  $basedn = null,
  $scope = self::SEARCH_SCOPE_SUB,
array  $attributes = array(),
  $sort = null,
  $collectionClass = null,
  $sizelimit = 0,
  $timelimit = 0 
)

A global LDAP search routine for finding information.

Options can be either passed as single parameters according to the method signature or as an array with one or more of the following keys

  • filter
  • baseDn
  • scope
  • attributes
  • sort
  • collectionClass
  • sizelimit
  • timelimit
Parameters
string | Zend_Ldap_Filter_Abstract | array$filter
string | Zend_Ldap_Dn | null$basedn
integer$scope
array$attributes
string | null$sort
string | null$collectionClass
integer$sizelimit
integer$timelimit
Returns
Zend_Ldap_Collection
Exceptions
Zend_Ldap_Exception
See Also
Zend_Ldap_Exception
Zend_Ldap_Exception

Zend_Ldap_Collection_Iterator_Default

searchEntries (   $filter,
  $basedn = null,
  $scope = self::SEARCH_SCOPE_SUB,
array  $attributes = array(),
  $sort = null,
  $reverseSort = false,
  $sizelimit = 0,
  $timelimit = 0 
)

Search LDAP registry for entries matching filter and optional attributes.

Options can be either passed as single parameters according to the method signature or as an array with one or more of the following keys

  • filter
  • baseDn
  • scope
  • attributes
  • sort
  • reverseSort
  • sizelimit
  • timelimit
Parameters
string | Zend_Ldap_Filter_Abstract | array$filter
string | Zend_Ldap_Dn | null$basedn
integer$scope
array$attributes
string | null$sort
boolean$reverseSort
integer$sizelimit
integer$timelimit
Returns
array
Exceptions
Zend_Ldap_Exception
setOptions (   $options)

Sets the options used in connecting, binding, etc.

Valid option keys: host port useSsl username password bindRequiresDn baseDn accountCanonicalForm accountDomainName accountDomainNameShort accountFilterFormat allowEmptyPassword useStartTls optRefferals tryUsernameSplit

Parameters
array | Zend_Config$optionsOptions used in connecting, binding, etc.
Returns
Zend_Ldap Provides a fluent interface
Exceptions
Zend_Ldap_Exception
See Also
Zend_Ldap_Exception
update (   $dn,
array  $entry 
)

Update LDAP registry.

Parameters
string | Zend_Ldap_Dn$dn
array$entry
Returns
Zend_Ldap Provides a fluid interface
Exceptions
Zend_Ldap_Exception
See Also
Zend_Ldap_Exception

Member Data Documentation

$_boundUser = false
protected
$_options = null
protected
$_resource = null
protected
$_rootDse = null
protected
$_schema = null
protected
const ACCTNAME_FORM_BACKSLASH = 3
const ACCTNAME_FORM_DN = 1
const ACCTNAME_FORM_PRINCIPAL = 4
const ACCTNAME_FORM_USERNAME = 2
const SEARCH_SCOPE_BASE = 3
const SEARCH_SCOPE_ONE = 2
const SEARCH_SCOPE_SUB = 1