Skip to content

Commit

Permalink
Moved from Exception-handling in zf1-style to
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Andreas Heigl committed Sep 18, 2010
1 parent 6ab34e0 commit c8f4aa4
Show file tree
Hide file tree
Showing 17 changed files with 463 additions and 332 deletions.
6 changes: 3 additions & 3 deletions library/Zend/Ldap/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function count()
* Implements Iterator
*
* @return array|null
* @throws \Zend\Ldap\Exception
* @throws \Zend\Ldap\LdapException
*/
public function current()
{
Expand Down Expand Up @@ -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()
{
Expand All @@ -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()
{
Expand Down
22 changes: 11 additions & 11 deletions library/Zend/Ldap/Collection/DefaultIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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');
}
}

Expand Down Expand Up @@ -192,7 +192,7 @@ public function count()
* Implements Iterator
*
* @return array|null
* @throws \Zend\Ldap\Exception
* @throws \Zend\Ldap\LdapException
*/
public function current()
{
Expand Down Expand Up @@ -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 {
Expand All @@ -259,19 +259,19 @@ public function key()
* Move forward to next result item
* Implements Iterator
*
* @throws \Zend\Ldap\Exception
* @throws \Zend\Ldap\LdapException
*/
public function next()
{
if (is_resource($this->_current)) {
$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 . ')');
}
}
}
Expand All @@ -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');
}
}
}
Expand Down
46 changes: 23 additions & 23 deletions library/Zend/Ldap/Dn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand All @@ -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');
}
}

Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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);
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
}
Expand All @@ -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');
}
}
}
Expand All @@ -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)
{
Expand Down Expand Up @@ -557,15 +557,15 @@ 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)
{
$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++) {
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 = ',')
{
Expand Down
Loading

0 comments on commit c8f4aa4

Please sign in to comment.