From c8f4aa4e1d37475b523a14544fbf151bad860a4b Mon Sep 17 00:00:00 2001 From: Andreas Heigl Date: Sat, 18 Sep 2010 23:18:47 +0200 Subject: [PATCH] Moved from Exception-handling in zf1-style to ZF2-Style as proposed in http://framework.zend.com/wiki/display/ZFDEV2/Proposal+for+Exceptions+in+ZF2 Also adapted the test to handle the new Exceptions as well as the CamelCased package-name --- library/Zend/Ldap/Collection.php | 6 +- .../Zend/Ldap/Collection/DefaultIterator.php | 22 +-- library/Zend/Ldap/Dn.php | 46 ++--- library/Zend/Ldap/Exception.php | 146 +------------- .../Ldap/Exception/BadMethodCallException.php | 42 ++++ .../FilterException.php} | 14 +- .../Exception/InvalidArgumentException.php | 42 ++++ library/Zend/Ldap/Filter/LogicalFilter.php | 4 +- library/Zend/Ldap/Ldap.php | 140 +++++++------- library/Zend/Ldap/LdapException.php | 179 ++++++++++++++++++ library/Zend/Ldap/Node.php | 94 ++++----- library/Zend/Ldap/Node/AbstractNode.php | 30 +-- library/Zend/Ldap/Node/RootDse.php | 2 +- library/Zend/Ldap/Node/Schema.php | 2 +- library/Zend/Ldap/Node/Schema/Item.php | 14 +- tests/Zend/Ldap/FilterTest.php | 2 +- tests/Zend/Ldap/OfflineTest.php | 10 +- 17 files changed, 463 insertions(+), 332 deletions(-) create mode 100644 library/Zend/Ldap/Exception/BadMethodCallException.php rename library/Zend/Ldap/{Filter/Exception.php => Exception/FilterException.php} (78%) create mode 100644 library/Zend/Ldap/Exception/InvalidArgumentException.php create mode 100644 library/Zend/Ldap/LdapException.php diff --git a/library/Zend/Ldap/Collection.php b/library/Zend/Ldap/Collection.php index b640a9a526a..7e18e9c1902 100644 --- a/library/Zend/Ldap/Collection.php +++ b/library/Zend/Ldap/Collection.php @@ -137,7 +137,7 @@ public function count() * Implements Iterator * * @return array|null - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function current() { @@ -208,7 +208,7 @@ public function key() * Move forward to next result item * Implements Iterator * - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function next() { @@ -220,7 +220,7 @@ public function next() * Rewind the Iterator to the first result item * Implements Iterator * - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function rewind() { diff --git a/library/Zend/Ldap/Collection/DefaultIterator.php b/library/Zend/Ldap/Collection/DefaultIterator.php index 41597dce9dc..8d01c2fdcc1 100644 --- a/library/Zend/Ldap/Collection/DefaultIterator.php +++ b/library/Zend/Ldap/Collection/DefaultIterator.php @@ -31,7 +31,7 @@ * * @uses Countable * @uses Iterator - * @uses \Zend\Ldap\Exception + * @uses \Zend\Ldap\LdapException * @category Zend * @package Zend_Ldap * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) @@ -91,7 +91,7 @@ public function __construct(Ldap\Ldap $ldap, $resultId) $this->_resultId = $resultId; $this->_itemCount = @ldap_count_entries($ldap->getResource(), $resultId); if ($this->_itemCount === false) { - throw new Ldap\Exception($this->_ldap, 'counting entries'); + throw new Ldap\LdapException($this->_ldap, 'counting entries'); } } @@ -192,7 +192,7 @@ public function count() * Implements Iterator * * @return array|null - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function current() { @@ -247,7 +247,7 @@ public function key() if (is_resource($this->_current)) { $currentDn = @ldap_get_dn($this->_ldap->getResource(), $this->_current); if ($currentDn === false) { - throw new Ldap\Exception($this->_ldap, 'getting dn'); + throw new Ldap\LdapException($this->_ldap, 'getting dn'); } return $currentDn; } else { @@ -259,7 +259,7 @@ public function key() * Move forward to next result item * Implements Iterator * - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function next() { @@ -267,11 +267,11 @@ public function next() $this->_current = @ldap_next_entry($this->_ldap->getResource(), $this->_current); if ($this->_current === false) { $msg = $this->_ldap->getLastError($code); - if ($code === Ldap\Exception::LDAP_SIZELIMIT_EXCEEDED) { + if ($code === Ldap\LdapException::LDAP_SIZELIMIT_EXCEEDED) { // we have reached the size limit enforced by the server return; - } else if ($code > Ldap\Exception::LDAP_SUCCESS) { - throw new Ldap\Exception($this->_ldap, 'getting next entry (' . $msg . ')'); + } else if ($code > Ldap\LdapException::LDAP_SUCCESS) { + throw new Ldap\LdapException($this->_ldap, 'getting next entry (' . $msg . ')'); } } } @@ -281,15 +281,15 @@ public function next() * Rewind the Iterator to the first result item * Implements Iterator * - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function rewind() { if (is_resource($this->_resultId)) { $this->_current = @ldap_first_entry($this->_ldap->getResource(), $this->_resultId); if ($this->_current === false && - $this->_ldap->getLastErrorCode() > Ldap\Exception::LDAP_SUCCESS) { - throw new Ldap\Exception($this->_ldap, 'getting first entry'); + $this->_ldap->getLastErrorCode() > Ldap\LdapException::LDAP_SUCCESS) { + throw new Ldap\LdapException($this->_ldap, 'getting first entry'); } } } diff --git a/library/Zend/Ldap/Dn.php b/library/Zend/Ldap/Dn.php index 93ca9bf306a..c4e3e91e348 100644 --- a/library/Zend/Ldap/Dn.php +++ b/library/Zend/Ldap/Dn.php @@ -30,7 +30,7 @@ * @uses ArrayAccess * @uses \Zend\Ldap\Converter * @uses \Zend\Ldap\Dn - * @uses \Zend\Ldap\Exception + * @uses \Zend\Ldap\LdapException * @category Zend * @package Zend_Ldap * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) @@ -69,7 +69,7 @@ class Dn implements \ArrayAccess * @param string|array $dn * @param string|null $caseFold * @return \Zend\Ldap\Dn - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public static function factory($dn, $caseFold = null) { @@ -78,7 +78,7 @@ public static function factory($dn, $caseFold = null) } else if (is_string($dn)) { return self::fromString($dn, $caseFold); } else { - throw new Exception(null, 'Invalid argument type for $dn'); + throw new LdapException(null, 'Invalid argument type for $dn'); } } @@ -88,7 +88,7 @@ public static function factory($dn, $caseFold = null) * @param string $dn * @param string|null $caseFold * @return \Zend\Ldap\Dn - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public static function fromString($dn, $caseFold = null) { @@ -107,7 +107,7 @@ public static function fromString($dn, $caseFold = null) * @param array $dn * @param string|null $caseFold * @return \Zend\Ldap\Dn - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public static function fromArray(array $dn, $caseFold = null) { @@ -131,7 +131,7 @@ protected function __construct(array $dn, $caseFold) * * @param string $caseFold * @return array - * @throws \Zend\Ldap\Exception if DN has no RDN (empty array) + * @throws \Zend\Ldap\LdapException if DN has no RDN (empty array) */ public function getRdn($caseFold = null) { @@ -144,7 +144,7 @@ public function getRdn($caseFold = null) * * @param string $caseFold * @return string - * @throws \Zend\Ldap\Exception if DN has no RDN (empty array) + * @throws \Zend\Ldap\LdapException if DN has no RDN (empty array) */ public function getRdnString($caseFold = null) { @@ -162,7 +162,7 @@ public function getParentDn($levelUp = 1) { $levelUp = (int)$levelUp; if ($levelUp < 1 || $levelUp >= count($this->_dn)) { - throw new Exception(null, 'Cannot retrieve parent DN with given $levelUp'); + throw new LdapException(null, 'Cannot retrieve parent DN with given $levelUp'); } $newDn = array_slice($this->_dn, $levelUp); return new self($newDn, $this->_caseFold); @@ -175,7 +175,7 @@ public function getParentDn($levelUp = 1) * @param int $length * @param string $caseFold * @return array - * @throws \Zend\Ldap\Exception if index is illegal + * @throws \Zend\Ldap\LdapException if index is illegal */ public function get($index, $length = 1, $caseFold = null) { @@ -199,7 +199,7 @@ public function get($index, $length = 1, $caseFold = null) * @param int $index * @param array $value * @return \Zend\Ldap\Dn Provides a fluent interface - * @throws \Zend\Ldap\Exception if index is illegal + * @throws \Zend\Ldap\LdapException if index is illegal */ public function set($index, array $value) { @@ -215,7 +215,7 @@ public function set($index, array $value) * @param int $index * @param int $length * @return \Zend\Ldap\Dn Provides a fluent interface - * @throws \Zend\Ldap\Exception if index is illegal + * @throws \Zend\Ldap\LdapException if index is illegal */ public function remove($index, $length = 1) { @@ -260,7 +260,7 @@ public function prepend(array $value) * @param int $index * @param array $value * @return \Zend\Ldap\Dn Provides a fluent interface - * @throws \Zend\Ldap\Exception if index is illegal + * @throws \Zend\Ldap\LdapException if index is illegal */ public function insert($index, array $value) { @@ -277,15 +277,15 @@ public function insert($index, array $value) * * @param mixed $index * @return boolean - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ protected function _assertIndex($index) { if (!is_int($index)) { - throw new Exception(null, 'Parameter $index must be an integer'); + throw new LdapException(null, 'Parameter $index must be an integer'); } if ($index < 0 || $index >= count($this->_dn)) { - throw new Exception(null, 'Parameter $index out of bounds'); + throw new LdapException(null, 'Parameter $index out of bounds'); } return true; } @@ -295,17 +295,17 @@ protected function _assertIndex($index) * * @param array $value * @return boolean - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ protected static function _assertRdn(array $value) { if (count($value)<1) { - throw new Exception(null, 'RDN Array is malformed: it must have at least one item'); + throw new LdapException(null, 'RDN Array is malformed: it must have at least one item'); } foreach (array_keys($value) as $key) { if (!is_string($key)) { - throw new Exception(null, 'RDN Array is malformed: it must use string keys'); + throw new LdapException(null, 'RDN Array is malformed: it must use string keys'); } } } @@ -325,7 +325,7 @@ public function setCaseFold($caseFold) * * @param string $caseFold * @return string - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function toString($caseFold = null) { @@ -557,7 +557,7 @@ public static function unescapeValue($values = array()) * @param array $vals An optional array to receive DN values * @param string $caseFold * @return array - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public static function explodeDn($dn, array &$keys = null, array &$vals = null, $caseFold = self::ATTR_CASEFOLD_NONE) @@ -565,7 +565,7 @@ public static function explodeDn($dn, array &$keys = null, array &$vals = null, $k = array(); $v = array(); if (!self::checkDn($dn, $k, $v, $caseFold)) { - throw new Exception(null, 'DN is malformed'); + throw new LdapException(null, 'DN is malformed'); } $ret = array(); for ($i = 0; $i < count($k); $i++) { @@ -685,7 +685,7 @@ public static function checkDn($dn, array &$keys = null, array &$vals = null, * @param array $attribute * @param string $caseFold * @return string - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public static function implodeRdn(array $part, $caseFold = null) { @@ -717,7 +717,7 @@ public static function implodeRdn(array $part, $caseFold = null) * @param string $caseFold * @param string $separator * @return string - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public static function implodeDn(array $dnArray, $caseFold = null, $separator = ',') { diff --git a/library/Zend/Ldap/Exception.php b/library/Zend/Ldap/Exception.php index e5d70028c25..89083a5af28 100644 --- a/library/Zend/Ldap/Exception.php +++ b/library/Zend/Ldap/Exception.php @@ -1,5 +1,4 @@ getLastError($code, $errorMessages) . ': '; - if ($code === 0) { - $message = ''; - $code = $oldCode; - } - } - if (empty($message)) { - if ($code > 0) { - $message = '0x' . dechex($code) . ': '; - } - } - - if (!empty($str)) { - $message .= $str; - } else { - $message .= 'no exception message'; - } - - parent::__construct($message, $code); - } - - - /** - * @deprecated not necessary any more - will be removed - * @param \Zend\Ldap\Ldap $ldap A \Zend\Ldap\Ldap object - * @return int The current error code for the resource - */ - public static function getLDAPCode(LDAP $ldap = null) - { - if ($ldap !== null) { - return $ldap->getLastErrorCode(); - } - return 0; - } - - /** - * @deprecated will be removed - * @return int The current error code for this exception - */ - public function getErrorCode() - { - return $this->getCode(); - } -} +interface Exception +{} \ No newline at end of file diff --git a/library/Zend/Ldap/Exception/BadMethodCallException.php b/library/Zend/Ldap/Exception/BadMethodCallException.php new file mode 100644 index 00000000000..76a1f768bc7 --- /dev/null +++ b/library/Zend/Ldap/Exception/BadMethodCallException.php @@ -0,0 +1,42 @@ + $s) { if (is_string($s)) $subfilters[$key] = new StringFilter($s); else if (!($s instanceof AbstractFilter)) { - throw new Exception('Only strings or Zend\Ldap\Filter\AbstractFilter allowed.'); + throw new \Zend\Ldap\Exception\FilterException('Only strings or Zend\Ldap\Filter\AbstractFilter allowed.'); } } $this->_subfilters = $subfilters; diff --git a/library/Zend/Ldap/Ldap.php b/library/Zend/Ldap/Ldap.php index 180a8883495..ebbc6759789 100644 --- a/library/Zend/Ldap/Ldap.php +++ b/library/Zend/Ldap/Ldap.php @@ -28,7 +28,7 @@ * @uses \Zend\Ldap\Collection * @uses \Zend\Ldap\Collection\DefaultIterator * @uses \Zend\Ldap\Dn - * @uses \Zend\Ldap\Exception + * @uses \Zend\Ldap\LdapException * @uses \Zend\Ldap\Filter\AbstractFilter * @uses \Zend\Ldap\Node * @uses \Zend\Ldap\Node\RootDSE @@ -121,13 +121,13 @@ public static function explodeDn($dn, array &$keys = null, array &$vals = null) * * @param array|\Zend\Config\Config $options Options used in connecting, binding, etc. * @return void - * @throws \Zend\Ldap\Exception if ext/ldap is not installed + * @throws \Zend\Ldap\LdapException if ext/ldap is not installed */ public function __construct($options = array()) { if (!extension_loaded('ldap')) { - throw new Exception(null, 'LDAP extension not loaded', - Exception::LDAP_X_EXTENSION_NOT_LOADED); + throw new LdapException(null, 'LDAP extension not loaded', + LdapException::LDAP_X_EXTENSION_NOT_LOADED); } $this->setOptions($options); } @@ -166,7 +166,7 @@ public function getLastErrorCode() /* For some reason draft-ietf-ldapext-ldap-c-api-xx.txt error * codes in OpenLDAP are negative values from -1 to -17. */ - $err = Exception::LDAP_SERVER_DOWN + (-$err - 1); + $err = LdapException::LDAP_SERVER_DOWN + (-$err - 1); } return $err; } @@ -252,7 +252,7 @@ public function getBoundUser() * * @param array|\Zend\Config\Config $options Options used in connecting, binding, etc. * @return \Zend\Ldap\Ldap Provides a fluent interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function setOptions($options) { @@ -307,7 +307,7 @@ public function setOptions($options) } if (count($options) > 0) { $key = key($options); - throw new Exception(null, "Unknown Zend_Ldap option: $key"); + throw new LdapException(null, "Unknown Zend_Ldap option: $key"); } $this->_options = $permittedOptions; return $this; @@ -513,7 +513,7 @@ protected function _splitName($name, &$dname, &$aname) /** * @param string $acctname The name of the account * @return string The DN of the specified account - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ protected function _getAccountDn($acctname) { @@ -552,20 +552,20 @@ protected function _isPossibleAuthority($dname) * @param string $acctname The name to canonicalize * @param int $type The desired form of canonicalization * @return string The canonicalized name in the desired form - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function getCanonicalAccountName($acctname, $form = 0) { $this->_splitName($acctname, $dname, $uname); if (!$this->_isPossibleAuthority($dname)) { - throw new Exception(null, + throw new LdapException(null, "Binding domain is not an authority for user: $acctname", - Exception::LDAP_X_DOMAIN_MISMATCH); + LdapException::LDAP_X_DOMAIN_MISMATCH); } if (!$uname) { - throw new Exception(null, "Invalid account name syntax: $acctname"); + throw new LdapException(null, "Invalid account name syntax: $acctname"); } if (function_exists('mb_strtolower')) { @@ -586,35 +586,35 @@ public function getCanonicalAccountName($acctname, $form = 0) case self::ACCTNAME_FORM_BACKSLASH: $accountDomainNameShort = $this->_getAccountDomainNameShort(); if (!$accountDomainNameShort) { - throw new Exception(null, 'Option required: accountDomainNameShort'); + throw new LdapException(null, 'Option required: accountDomainNameShort'); } return "$accountDomainNameShort\\$uname"; case self::ACCTNAME_FORM_PRINCIPAL: $accountDomainName = $this->_getAccountDomainName(); if (!$accountDomainName) { - throw new Exception(null, 'Option required: accountDomainName'); + throw new LdapException(null, 'Option required: accountDomainName'); } return "$uname@$accountDomainName"; default: - throw new Exception(null, "Unknown canonical name form: $form"); + throw new LdapException(null, "Unknown canonical name form: $form"); } } /** * @param array $attrs An array of names of desired attributes * @return array An array of the attributes representing the account - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ protected function _getAccount($acctname, array $attrs = null) { $baseDn = $this->getBaseDn(); if (!$baseDn) { - throw new Exception(null, 'Base DN not set'); + throw new LdapException(null, 'Base DN not set'); } $accountFilter = $this->_getAccountFilter($acctname); if (!$accountFilter) { - throw new Exception(null, 'Invalid account filter'); + throw new LdapException(null, 'Invalid account filter'); } if (!is_resource($this->getResource())) { @@ -628,14 +628,14 @@ protected function _getAccount($acctname, array $attrs = null) $accounts->close(); return $acct; } else if ($count === 0) { - $code = Exception::LDAP_NO_SUCH_OBJECT; + $code = LdapException::LDAP_NO_SUCH_OBJECT; $str = "No object found for: $accountFilter"; } else { - $code = Exception::LDAP_OPERATIONS_ERROR; + $code = LdapException::LDAP_OPERATIONS_ERROR; $str = "Unexpected result count ($count) for: $accountFilter"; } $accounts->close(); - throw new Exception($this, $str, $code); + throw new LdapException($this, $str, $code); } /** @@ -663,7 +663,7 @@ public function disconnect() * @param boolean $useSsl Use SSL * @param boolean $useStartTls Use STARTTLS * @return \Zend\Ldap\Ldap Provides a fluent interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function connect($host = null, $port = null, $useSsl = null, $useStartTls = null) { @@ -687,7 +687,7 @@ public function connect($host = null, $port = null, $useSsl = null, $useStartTls } if (!$host) { - throw new Exception(null, 'A host parameter is required'); + throw new LdapException(null, 'A host parameter is required'); } $useUri = false; @@ -731,18 +731,18 @@ public function connect($host = null, $port = null, $useSsl = null, $useStartTls } } - $zle = new Exception($this, "$host:$port"); + $zle = new LdapException($this, "$host:$port"); $this->disconnect(); throw $zle; } - throw new Exception(null, "Failed to connect to LDAP server: $host:$port"); + throw new LdapException(null, "Failed to connect to LDAP server: $host:$port"); } /** * @param string $username The username for authenticating the bind * @param string $password The password for authenticating the bind * @return \Zend\Ldap\Ldap Provides a fluent interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function bind($username = null, $password = null) { @@ -770,20 +770,20 @@ public function bind($username = null, $password = null) if ($moreCreds) { try { $username = $this->_getAccountDn($username); - } catch (Exception $zle) { + } catch (LdapException $zle) { switch ($zle->getCode()) { - case Exception::LDAP_NO_SUCH_OBJECT: - case Exception::LDAP_X_DOMAIN_MISMATCH: - case Exception::LDAP_X_EXTENSION_NOT_LOADED: + case LdapException::LDAP_NO_SUCH_OBJECT: + case LdapException::LDAP_X_DOMAIN_MISMATCH: + case LdapException::LDAP_X_EXTENSION_NOT_LOADED: throw $zle; } - throw new Exception(null, + throw new LdapException(null, 'Failed to retrieve DN for account: ' . $username . ' [' . $zle->getMessage() . ']', - Exception::LDAP_OPERATIONS_ERROR); + LdapException::LDAP_OPERATIONS_ERROR); } } else { - throw new Exception(null, 'Binding requires username in DN form'); + throw new LdapException(null, 'Binding requires username in DN form'); } } else { $username = $this->getCanonicalAccountName($username, @@ -797,7 +797,7 @@ public function bind($username = null, $password = null) } if ($username !== null && $password === '' && $this->_getAllowEmptyPassword() !== true) { - $zle = new Exception(null, + $zle = new LdapException(null, 'Empty password not allowed - see allowEmptyPassword option.'); } else { if (@ldap_bind($this->_resource, $username, $password)) { @@ -807,14 +807,14 @@ public function bind($username = null, $password = null) $message = ($username === null) ? $this->_connectString : $username; switch ($this->getLastErrorCode()) { - case Exception::LDAP_SERVER_DOWN: + case LdapException::LDAP_SERVER_DOWN: /* If the error is related to establishing a connection rather than binding, * the connect string is more informative than the username. */ $message = $this->_connectString; } - $zle = new Exception($this, $message); + $zle = new LdapException($this, $message); } $this->disconnect(); throw $zle; @@ -839,7 +839,7 @@ public function bind($username = null, $password = null) * @param string|null $sort * @param string|null $collectionClass * @return \Zend\Ldap\Collection - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function search($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB, array $attributes = array(), $sort = null, $collectionClass = null) @@ -891,12 +891,12 @@ public function search($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB, } if($search === false) { - throw new Exception($this, 'searching: ' . $filter); + throw new LdapException($this, 'searching: ' . $filter); } if ($sort !== null && is_string($sort)) { $isSorted = @ldap_sort($this->getResource(), $search, $sort); if($isSorted === false) { - throw new Exception($this, 'sorting: ' . $sort); + throw new LdapException($this, 'sorting: ' . $sort); } } @@ -910,7 +910,7 @@ public function search($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB, * @param \Zend\Ldap\Collection\DefaultIterator $iterator * @param string|null $collectionClass * @return \Zend\Ldap\Collection - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ protected function _createCollection(Collection\DefaultIterator $iterator, $collectionClass) { @@ -919,11 +919,11 @@ protected function _createCollection(Collection\DefaultIterator $iterator, $coll } else { $collectionClass = (string)$collectionClass; if (!class_exists($collectionClass)) { - throw new Exception(null, + throw new LdapException(null, "Class '$collectionClass' can not be found"); } if (!is_subclass_of($collectionClass, 'Zend\Ldap\Collection')) { - throw new Exception(null, + throw new LdapException(null, "Class '$collectionClass' must subclass 'Zend\Ldap\Collection'"); } return new $collectionClass($iterator); @@ -937,14 +937,14 @@ protected function _createCollection(Collection\DefaultIterator $iterator, $coll * @param string|\Zend\Ldap\Dn|null $basedn * @param integer $scope * @return integer - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function count($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB) { try { $result = $this->search($filter, $basedn, $scope, array('dn'), null); - } catch (Exception $e) { - if ($e->getCode() === Exception::LDAP_NO_SUCH_OBJECT) return 0; + } catch (LdapException $e) { + if ($e->getCode() === LdapException::LDAP_NO_SUCH_OBJECT) return 0; else throw $e; } return $result->count(); @@ -955,7 +955,7 @@ public function count($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB) * * @param string|\Zend\Ldap\Dn $dn * @return integer - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function countChildren($dn) { @@ -967,7 +967,7 @@ public function countChildren($dn) * * @param string|\Zend\Ldap\Dn $dn * @return boolean - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function exists($dn) { @@ -993,7 +993,7 @@ public function exists($dn) * @param string|null $sort * @param boolean $reverseSort * @return array - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function searchEntries($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB, array $attributes = array(), $sort = null, $reverseSort = false) @@ -1023,7 +1023,7 @@ public function searchEntries($filter, $basedn = null, $scope = self::SEARCH_SCO * @param array $attributes * @param boolean $throwOnNotFound * @return array - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function getEntry($dn, array $attributes = array(), $throwOnNotFound = false) { @@ -1031,7 +1031,7 @@ public function getEntry($dn, array $attributes = array(), $throwOnNotFound = fa $result = $this->search("(objectClass=*)", $dn, self::SEARCH_SCOPE_BASE, $attributes, null); return $result->getFirst(); - } catch (Exception $e){ + } catch (LdapException $e){ if ($throwOnNotFound !== false) throw $e; } return null; @@ -1053,7 +1053,7 @@ public static function prepareLdapEntryArray(array &$entry) if ($v === null) { unset($value[$i]); } elseif (!is_scalar($v)) { - throw new \InvalidArgumentException('Only scalar values allowed in LDAP data'); + throw new Exception\InvalidArgumentException('Only scalar values allowed in LDAP data'); } else { $v = (string)$v; if (strlen($v) == 0) { @@ -1068,7 +1068,7 @@ public static function prepareLdapEntryArray(array &$entry) if ($value === null) { $entry[$key] = array(); } elseif (!is_scalar($value)) { - throw new \InvalidArgumentException('Only scalar values allowed in LDAP data'); + throw new Exception\InvalidArgumentException('Only scalar values allowed in LDAP data'); } else { $value = (string)$value; if (strlen($value) == 0) { @@ -1088,7 +1088,7 @@ public static function prepareLdapEntryArray(array &$entry) * @param string|\Zend\Ldap\Dn $dn * @param array $entry * @return \Zend\Ldap\Ldap Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function add($dn, array $entry) { @@ -1121,7 +1121,7 @@ public function add($dn, array $entry) $isAdded = @ldap_add($this->getResource(), $dn->toString(), $entry); if($isAdded === false) { - throw new Exception($this, 'adding: ' . $dn->toString()); + throw new LdapException($this, 'adding: ' . $dn->toString()); } return $this; } @@ -1132,7 +1132,7 @@ public function add($dn, array $entry) * @param string|\Zend\Ldap\Dn $dn * @param array $entry * @return \Zend\Ldap\Ldap Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function update($dn, array $entry) { @@ -1159,7 +1159,7 @@ public function update($dn, array $entry) if (count($entry) > 0) { $isModified = @ldap_modify($this->getResource(), $dn->toString(), $entry); if($isModified === false) { - throw new Exception($this, 'updating: ' . $dn->toString()); + throw new LdapException($this, 'updating: ' . $dn->toString()); } } return $this; @@ -1174,7 +1174,7 @@ public function update($dn, array $entry) * @param string|\Zend\Ldap\Dn $dn * @param array $entry * @return \Zend\Ldap\Ldap Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function save($dn, array $entry) { @@ -1192,7 +1192,7 @@ public function save($dn, array $entry) * @param string|\Zend\Ldap\Dn $dn * @param boolean $recursively * @return \Zend\Ldap\Ldap Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function delete($dn, $recursively = false) { @@ -1209,7 +1209,7 @@ public function delete($dn, $recursively = false) } $isDeleted = @ldap_delete($this->getResource(), $dn); if($isDeleted === false) { - throw new Exception($this, 'deleting: ' . $dn); + throw new LdapException($this, 'deleting: ' . $dn); } return $this; } @@ -1235,7 +1235,7 @@ protected function _getChildrenDns($parentDn) $entry = @ldap_next_entry($this->getResource(), $entry)) { $childDn = @ldap_get_dn($this->getResource(), $entry); if ($childDn === false) { - throw new Exception($this, 'getting dn'); + throw new LdapException($this, 'getting dn'); } $children[] = $childDn; } @@ -1251,7 +1251,7 @@ protected function _getChildrenDns($parentDn) * @param boolean $recursively * @param boolean $alwaysEmulate * @return \Zend\Ldap\Ldap Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function moveToSubtree($from, $to, $recursively = false, $alwaysEmulate = false) { @@ -1282,7 +1282,7 @@ public function moveToSubtree($from, $to, $recursively = false, $alwaysEmulate = * @param boolean $recursively * @param boolean $alwaysEmulate * @return \Zend\Ldap\Ldap Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function move($from, $to, $recursively = false, $alwaysEmulate = false) { @@ -1299,7 +1299,7 @@ public function move($from, $to, $recursively = false, $alwaysEmulate = false) * @param boolean $recursively * @param boolean $alwaysEmulate * @return \Zend\Ldap\Ldap Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function rename($from, $to, $recursively = false, $alwaysEmulate = false) { @@ -1322,7 +1322,7 @@ public function rename($from, $to, $recursively = false, $alwaysEmulate = false) $newParent = DN::implodeDn($newDnParts); $isOK = @ldap_rename($this->getResource(), $from, $newRdn, $newParent, true); if($isOK === false) { - throw new Exception($this, 'renaming ' . $from . ' to ' . $to); + throw new LdapException($this, 'renaming ' . $from . ' to ' . $to); } else if (!$this->exists($to)) $emulate = true; } @@ -1340,7 +1340,7 @@ public function rename($from, $to, $recursively = false, $alwaysEmulate = false) * @param string|\Zend\Ldap\Dn $to * @param boolean $recursively * @return \Zend\Ldap\Ldap Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function copyToSubtree($from, $to, $recursively = false) { @@ -1368,7 +1368,7 @@ public function copyToSubtree($from, $to, $recursively = false) * @param string|\Zend\Ldap\Dn $to * @param boolean $recursively * @return \Zend\Ldap\Ldap Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function copy($from, $to, $recursively = false) { @@ -1398,7 +1398,7 @@ public function copy($from, $to, $recursively = false) * * @param string|\Zend\Ldap\dN $dn * @return \Zend\Ldap\Node|null - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function getNode($dn) { @@ -1409,7 +1409,7 @@ public function getNode($dn) * Returns the base node as a Zend_Ldap_Node * * @return \Zend\Ldap\Node - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function getBaseNode() { @@ -1420,7 +1420,7 @@ public function getBaseNode() * Returns the RootDSE * * @return \Zend\Ldap\Node\RootDSE - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function getRootDse() { @@ -1434,7 +1434,7 @@ public function getRootDse() * Returns the schema * * @return \Zend\Ldap\Node\Schema - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function getSchema() { diff --git a/library/Zend/Ldap/LdapException.php b/library/Zend/Ldap/LdapException.php new file mode 100644 index 00000000000..e5ebf97cdc3 --- /dev/null +++ b/library/Zend/Ldap/LdapException.php @@ -0,0 +1,179 @@ +getLastError($code, $errorMessages) . ': '; + if ($code === 0) { + $message = ''; + $code = $oldCode; + } + } + if (empty($message)) { + if ($code > 0) { + $message = '0x' . dechex($code) . ': '; + } + } + + if (!empty($str)) { + $message .= $str; + } else { + $message .= 'no exception message'; + } + + parent::__construct($message, $code); + } + + + /** + * @deprecated not necessary any more - will be removed + * @param \Zend\Ldap\Ldap $ldap A \Zend\Ldap\Ldap object + * @return int The current error code for the resource + */ + public static function getLDAPCode(LDAP $ldap = null) + { + if ($ldap !== null) { + return $ldap->getLastErrorCode(); + } + return 0; + } + + /** + * @deprecated will be removed + * @return int The current error code for this exception + */ + public function getErrorCode() + { + return $this->getCode(); + } +} diff --git a/library/Zend/Ldap/Node.php b/library/Zend/Ldap/Node.php index 780e08be8ab..466a2b3ed5e 100644 --- a/library/Zend/Ldap/Node.php +++ b/library/Zend/Ldap/Node.php @@ -31,7 +31,7 @@ * @uses \Zend\Ldap\Ldap * @uses \Zend\Ldap\Attribute * @uses \Zend\Ldap\Dn - * @uses \Zend\Ldap\Exception + * @uses \Zend\Ldap\LdapException * @uses \Zend\Ldap\Ldif\Encoder * @uses \Zend\Ldap\Node\AbstractNode * @uses \Zend\Ldap\Node\ChildrenIterator @@ -98,7 +98,7 @@ class Node extends Node\AbstractNode implements \Iterator, \RecursiveIterator * @param array $data * @param boolean $fromDataSource * @param \Zend\Ldap\Ldap $ldap - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ protected function __construct(Dn $dn, array $data, $fromDataSource, Ldap $ldap = null) { @@ -136,12 +136,12 @@ public function __wakeup() * Gets the current LDAP connection. * * @return \Zend\Ldap\Ldap - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function getLdap() { if ($this->_ldap === null) { - throw new Exception(null, 'No LDAP connection specified.', Exception::LDAP_OTHER); + throw new LdapException(null, 'No LDAP connection specified.', LdapException::LDAP_OTHER); } else return $this->_ldap; } @@ -154,13 +154,13 @@ public function getLdap() * @uses \Zend\Ldap\Dn::isChildOf() * @param \Zend\Ldap\Ldap $ldap * @return \Zend\Ldap\Node Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function attachLdap(Ldap $ldap) { if (!Dn::isChildOf($this->_getDn(), $ldap->getBaseDn())) { - throw new Exception(null, 'LDAP connection is not responsible for given node.', - Exception::LDAP_OTHER); + throw new LdapException(null, 'LDAP connection is not responsible for given node.', + LdapException::LDAP_OTHER); } if ($ldap !== $this->_ldap) { @@ -207,7 +207,7 @@ public function isAttached() /** * @param array $data * @param boolean $fromDataSource - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ protected function _loadData(array $data, $fromDataSource) { @@ -228,7 +228,7 @@ protected function _loadData(array $data, $fromDataSource) * @param string|array|\Zend\Ldap\Dn $dn * @param array $objectClass * @return \Zend\Ldap\Node - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public static function create($dn, array $objectClass = array()) { @@ -237,7 +237,7 @@ public static function create($dn, array $objectClass = array()) } else if ($dn instanceof Dn) { $dn = clone $dn; } else { - throw new Exception(null, '$dn is of a wrong data type.'); + throw new LdapException(null, '$dn is of a wrong data type.'); } $new = new self($dn, array(), false, null); $new->_ensureRdnAttributeValues(); @@ -251,7 +251,7 @@ public static function create($dn, array $objectClass = array()) * @param string|array|\Zend\Ldap\Dn $dn * @param \Zend\Ldap\Ldap $ldap * @return \Zend\Ldap\Node|null - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public static function fromLdap($dn, Ldap $ldap) { @@ -260,7 +260,7 @@ public static function fromLdap($dn, Ldap $ldap) } else if ($dn instanceof Dn) { $dn = clone $dn; } else { - throw new Exception(null, '$dn is of a wrong data type.'); + throw new LdapException(null, '$dn is of a wrong data type.'); } $data = $ldap->getEntry($dn, array('*', '+'), true); if ($data === null) { @@ -276,19 +276,19 @@ public static function fromLdap($dn, Ldap $ldap) * @param array $data * @param boolean $fromDataSource * @return \Zend\Ldap\Node - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public static function fromArray(array $data, $fromDataSource = false) { if (!array_key_exists('dn', $data)) { - throw new Exception(null, '\'dn\' key is missing in array.'); + throw new LdapException(null, '\'dn\' key is missing in array.'); } if (is_string($data['dn']) || is_array($data['dn'])) { $dn = Dn::factory($data['dn']); } else if ($data['dn'] instanceof Dn) { $dn = clone $data['dn']; } else { - throw new Exception(null, '\'dn\' key is of a wrong data type.'); + throw new LdapException(null, '\'dn\' key is of a wrong data type.'); } $fromDataSource = ($fromDataSource === true) ? true : false; $new = new self($dn, $data, $fromDataSource, null); @@ -390,7 +390,7 @@ public function willBeMoved() * * @param \Zend\Ldap\Ldap $ldap * @return \Zend\Ldap\Node Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function update(Ldap $ldap = null) { @@ -399,7 +399,7 @@ public function update(Ldap $ldap = null) } $ldap = $this->getLdap(); if (!($ldap instanceof Ldap)) { - throw new Exception(null, 'No LDAP connection available'); + throw new LdapException(null, 'No LDAP connection available'); } if ($this->willBeDeleted()) { @@ -467,7 +467,7 @@ public function getCurrentDn() * This is an offline method. * * @param \Zend\Ldap\Dn|string|array $newDn - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException * @return \Zend\Ldap\Node Provides a fluid interface */ public function setDn($newDn) @@ -487,7 +487,7 @@ public function setDn($newDn) * This is an offline method. * * @param \Zend\Ldap\Dn|string|array $newDn - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException * @return \Zend\Ldap\Node Provides a fluid interface */ public function move($newDn) @@ -501,7 +501,7 @@ public function move($newDn) * This is an offline method. * * @param \Zend\Ldap\Dn|string|array $newDn - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException * @return \Zend\Ldap\Node Provides a fluid interface */ public function rename($newDn) @@ -516,7 +516,7 @@ public function rename($newDn) * * @param array|string $value * @return \Zend\Ldap\Node Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function setObjectClass($value) { @@ -531,7 +531,7 @@ public function setObjectClass($value) * * @param array|string $value * @return \Zend\Ldap\Node Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function appendObjectClass($value) { @@ -611,7 +611,7 @@ public function getChanges() * @param string $name * @param mixed $value * @return \Zend\Ldap\Node Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function setAttribute($name, $value) { @@ -627,7 +627,7 @@ public function setAttribute($name, $value) * @param string $name * @param mixed $value * @return \Zend\Ldap\Node Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function appendToAttribute($name, $value) { @@ -641,7 +641,7 @@ public function appendToAttribute($name, $value) * @param string $name * @param mixed $value * @param boolean $append - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ protected function _setAttribute($name, $value, $append) { @@ -658,7 +658,7 @@ protected function _setAttribute($name, $value, $append) * @param integer|array $value * @param boolean $utc * @return \Zend\Ldap\Node Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function setDateTimeAttribute($name, $value, $utc = false) { @@ -675,7 +675,7 @@ public function setDateTimeAttribute($name, $value, $utc = false) * @param integer|array $value * @param boolean $utc * @return \Zend\Ldap\Node Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function appendToDateTimeAttribute($name, $value, $utc = false) { @@ -690,7 +690,7 @@ public function appendToDateTimeAttribute($name, $value, $utc = false) * @param integer|array $value * @param boolean $utc * @param boolean $append - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ protected function _setDateTimeAttribute($name, $value, $utc, $append) { @@ -705,7 +705,7 @@ protected function _setDateTimeAttribute($name, $value, $utc, $append) * @param string $hashType * @param string $attribName * @return \Zend\Ldap\Node Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function setPasswordAttribute($password, $hashType = Attribute::PASSWORD_HASH_MD5, $attribName = 'userPassword') @@ -724,7 +724,7 @@ public function setPasswordAttribute($password, $hashType = Attribute::PASSWORD_ * * @param string $name * @return \Zend\Ldap\Node Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function deleteAttribute($name) { @@ -760,19 +760,19 @@ public function removeFromAttribute($attribName, $value) /** * @param string $name * @return boolean - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ protected function _assertChangeableAttribute($name) { $name = strtolower($name); $rdn = $this->getRdnArray(Dn::ATTR_CASEFOLD_LOWER); if ($name == 'dn') { - throw new Exception(null, 'DN cannot be changed.'); + throw new LdapException(null, 'DN cannot be changed.'); } else if (array_key_exists($name, $rdn)) { - throw new Exception(null, 'Cannot change attribute because it\'s part of the RDN'); + throw new LdapException(null, 'Cannot change attribute because it\'s part of the RDN'); } else if (in_array($name, self::$_systemAttributes)) { - throw new Exception(null, 'Cannot change attribute because it\'s read-only'); + throw new LdapException(null, 'Cannot change attribute because it\'s read-only'); } else return true; } @@ -785,7 +785,7 @@ protected function _assertChangeableAttribute($name) * @param string $name * @param mixed $value * @return null - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function __set($name, $value) { @@ -801,7 +801,7 @@ public function __set($name, $value) * * @param string $name * @return null - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function __unset($name) { @@ -817,7 +817,7 @@ public function __unset($name) * @param string $name * @param mixed $value * @return null - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function offsetSet($name, $value) { @@ -834,7 +834,7 @@ public function offsetSet($name, $value) * * @param string $name * @return null - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function offsetUnset($name) { @@ -848,7 +848,7 @@ public function offsetUnset($name) * * @param \Zend\Ldap\Ldap $ldap * @return boolean - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function exists(Ldap $ldap = null) { @@ -866,7 +866,7 @@ public function exists(Ldap $ldap = null) * * @param \Zend\Ldap\Ldap $ldap * @return \Zend\Ldap\Node Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function reload(Ldap $ldap = null) { @@ -887,7 +887,7 @@ public function reload(Ldap $ldap = null) * @param integer $scope * @param string $sort * @return \Zend\Ldap\Node\Collection - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function searchSubtree($filter, $scope = Ldap::SEARCH_SCOPE_SUB, $sort = null) { @@ -903,7 +903,7 @@ public function searchSubtree($filter, $scope = Ldap::SEARCH_SCOPE_SUB, $sort = * @param string|\Zend\Ldap\Filter\AbstractFilter $filter * @param integer $scope * @return integer - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function countSubtree($filter, $scope = Ldap::SEARCH_SCOPE_SUB) { @@ -916,7 +916,7 @@ public function countSubtree($filter, $scope = Ldap::SEARCH_SCOPE_SUB) * This is an online method. * * @return integer - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function countChildren() { @@ -931,7 +931,7 @@ public function countChildren() * @param string|\Zend\Ldap\Filter\AbstractFilter $filter * @param string $sort * @return \Zend\Ldap\Node\Collection - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function searchChildren($filter, $sort = null) { @@ -945,7 +945,7 @@ public function searchChildren($filter, $sort = null) * Can be used offline but returns false if children have not been retrieved yet. * * @return boolean - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function hasChildren() { @@ -966,7 +966,7 @@ public function hasChildren() * Can be used offline but returns an empty array if children have not been retrieved yet. * * @return \Zend\Ldap\Node\ChildrenIterator - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function getChildren() { @@ -987,7 +987,7 @@ public function getChildren() * * @param \Zend\Ldap\Ldap $ldap * @return \Zend\Ldap\Node - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function getParent(Ldap $ldap = null) { diff --git a/library/Zend/Ldap/Node/AbstractNode.php b/library/Zend/Ldap/Node/AbstractNode.php index e8a96f9c51c..d9c8c254d72 100644 --- a/library/Zend/Ldap/Node/AbstractNode.php +++ b/library/Zend/Ldap/Node/AbstractNode.php @@ -30,7 +30,7 @@ * Zend_Ldap_Node_Abstract provides a bas eimplementation for LDAP nodes * * @uses ArrayAccess - * @uses BadMethodCallException + * @uses \Zend\Ldap\Exception\BadMethodCallException * @uses Countable * @uses \Zend\Ldap\Attribute * @uses \Zend\Ldap\Dn @@ -80,7 +80,7 @@ protected function __construct(Ldap\Dn $dn, array $data, $fromDataSource) /** * @param array $data * @param boolean $fromDataSource - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ protected function _loadData(array $data, $fromDataSource) { @@ -98,7 +98,7 @@ protected function _loadData(array $data, $fromDataSource) * * @param \Zend\Ldap\Ldap $ldap * @return \Zend\Ldap\Node\AbstractNode Provides a fluid interface - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function reload(Ldap\Ldap $ldap = null) { @@ -327,7 +327,7 @@ public function attributeHasValue($attribName, $value) * @param string $name * @param integer $index * @return mixed - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function getAttribute($name, $index = null) { @@ -347,7 +347,7 @@ public function getAttribute($name, $index = null) * @param string $name * @param integer $index * @return array|integer - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function getDateTimeAttribute($name, $index = null) { @@ -362,11 +362,11 @@ public function getDateTimeAttribute($name, $index = null) * @param string $name * @param mixed $value * @return null - * @throws BadMethodCallException + * @throws \Zend\Ldap\Exception\BadMethodCallException */ public function __set($name, $value) { - throw new \BadMethodCallException(); + throw new \Zend\Ldap\Exception\BadMethodCallException(); } /** @@ -376,7 +376,7 @@ public function __set($name, $value) * * @param string $name * @return array - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function __get($name) { @@ -392,11 +392,11 @@ public function __get($name) * * @param string $name * @return null - * @throws BadMethodCallException + * @throws \Zend\Ldap\Exception\BadMethodCallException */ public function __unset($name) { - throw new \BadMethodCallException(); + throw new \Zend\Ldap\Exeption\BadMethodCallException(); } /** @@ -421,11 +421,11 @@ public function __isset($name) * @param string $name * @param mixed $value * @return null - * @throws BadMethodCallException + * @throws \Zend\Ldap\Exception\BadMethodCallException */ public function offsetSet($name, $value) { - throw new \BadMethodCallException(); + throw new \Zend\Ldap\Exception\BadMethodCallException(); } /** @@ -436,7 +436,7 @@ public function offsetSet($name, $value) * * @param string $name * @return array - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public function offsetGet($name) { @@ -453,11 +453,11 @@ public function offsetGet($name) * * @param string $name * @return null - * @throws BadMethodCallException + * @throws \Zend\Ldap\Exception\BadMethodCallException */ public function offsetUnset($name) { - throw new \BadMethodCallException(); + throw new \Zend\Ldap\Exception\BadMethodCallException(); } /** diff --git a/library/Zend/Ldap/Node/RootDse.php b/library/Zend/Ldap/Node/RootDse.php index b35afdeda86..0656977d67e 100644 --- a/library/Zend/Ldap/Node/RootDse.php +++ b/library/Zend/Ldap/Node/RootDse.php @@ -52,7 +52,7 @@ class RootDse extends AbstractNode * * @param \Zend\Ldap\Ldap $ldap * @return \Zend\Ldap\Node\RootDse - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public static function create(Ldap\Ldap $ldap) { diff --git a/library/Zend/Ldap/Node/Schema.php b/library/Zend/Ldap/Node/Schema.php index bbd354b7afa..ff17cb3bc99 100644 --- a/library/Zend/Ldap/Node/Schema.php +++ b/library/Zend/Ldap/Node/Schema.php @@ -53,7 +53,7 @@ class Schema extends AbstractNode * * @param \Zend\Ldap\Ldap $ldap * @return \Zend\Ldap\Node\Schema - * @throws \Zend\Ldap\Exception + * @throws \Zend\Ldap\LdapException */ public static function create(Ldap\Ldap $ldap) { diff --git a/library/Zend/Ldap/Node/Schema/Item.php b/library/Zend/Ldap/Node/Schema/Item.php index 3bf2cf4bf7f..fb3b7e50e36 100644 --- a/library/Zend/Ldap/Node/Schema/Item.php +++ b/library/Zend/Ldap/Node/Schema/Item.php @@ -30,7 +30,7 @@ * items like objectClass and attribute. * * @uses ArrayAccess - * @uses BadMethodCallException + * @uses \Zend\Ldap\Exception\BadMethodCallException * @uses Countable * @category Zend * @package Zend_Ldap @@ -106,7 +106,7 @@ public function __isset($name) } /** - * Always throws BadMethodCallException + * Always throws \Zend\Ldap\Exception\BadMethodCallException * Implements ArrayAccess. * * This method is needed for a full implementation of ArrayAccess @@ -114,11 +114,11 @@ public function __isset($name) * @param string $name * @param mixed $value * @return null - * @throws BadMethodCallException + * @throws \Zend\Ldap\Exception\BadMethodCallException */ public function offsetSet($name, $value) { - throw new \BadMethodCallException(); + throw new \Zend\Ldap\Exception\BadMethodCallException(); } /** @@ -133,18 +133,18 @@ public function offsetGet($name) } /** - * Always throws BadMethodCallException + * Always throws \Zend\Ldap\Exception\BadMethodCallException * Implements ArrayAccess. * * This method is needed for a full implementation of ArrayAccess * * @param string $name * @return null - * @throws BadMethodCallException + * @throws \Zend\Ldap\Exception\BadMethodCallException */ public function offsetUnset($name) { - throw new \BadMethodCallException(); + throw new \Zend\Ldap\Exception\BadMethodCallException(); } /** diff --git a/tests/Zend/Ldap/FilterTest.php b/tests/Zend/Ldap/FilterTest.php index 765cf95fca1..839c6a059ad 100644 --- a/tests/Zend/Ldap/FilterTest.php +++ b/tests/Zend/Ldap/FilterTest.php @@ -116,7 +116,7 @@ public function testNegate() } /** - * @expectedException Zend\Ldap\Filter\Exception + * @expectedException Zend\Ldap\Exception\FilterException */ public function testIllegalGroupingFilter() { diff --git a/tests/Zend/Ldap/OfflineTest.php b/tests/Zend/Ldap/OfflineTest.php index 34fb037df92..b721f54891a 100644 --- a/tests/Zend/Ldap/OfflineTest.php +++ b/tests/Zend/Ldap/OfflineTest.php @@ -66,20 +66,20 @@ public function testInvalidOptionResultsInException() $optionName = 'invalid'; try { $this->_ldap->setOptions(array($optionName => 'irrelevant')); - $this->fail('Expected Zend_LDAP_Exception not thrown'); - } catch (Ldap\Exception $e) { - $this->assertEquals("Unknown Zend_LDAP option: $optionName", $e->getMessage()); + $this->fail('Expected Zend_Ldap_Exception not thrown'); + } catch (Ldap\LdapException $e) { + $this->assertEquals("Unknown Zend_Ldap option: $optionName", $e->getMessage()); } } public function testException() { - $e = new Ldap\Exception(null, '', 0); + $e = new Ldap\LdapException(null, '', 0); $this->assertEquals('no exception message', $e->getMessage()); $this->assertEquals(0, $e->getCode()); $this->assertEquals(0, $e->getErrorCode()); - $e = new Ldap\Exception(null, '', 15); + $e = new Ldap\LdapException(null, '', 15); $this->assertEquals('0xf: no exception message', $e->getMessage()); $this->assertEquals(15, $e->getCode()); $this->assertEquals(15, $e->getErrorCode());