Skip to content

Commit

Permalink
Merge commit 'zf2/milestones/exceptions' into serializer-exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-mabe committed Sep 14, 2010
2 parents 48be19d + b8192d8 commit 9cfa4b2
Show file tree
Hide file tree
Showing 32 changed files with 214 additions and 191 deletions.
43 changes: 22 additions & 21 deletions library/Zend/Acl/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class Acl
* @param Zend\Acl\Role $role
* @param Zend\Acl\Role|string|array $parents
* @uses Zend\Acl\Role\Registry::add()
* @throws Zend\Acl\InvalidArgumentException
* @return Zend\Acl\Acl Provides a fluent interface
*/
public function addRole($role, $parents = null)
Expand All @@ -133,7 +134,7 @@ public function addRole($role, $parents = null)
}

if (!$role instanceof Role) {
throw new Exception('addRole() expects $role to be of type Zend_Acl_Role_Interface');
throw new InvalidArgumentException('addRole() expects $role to be of type Zend_Acl_Role_Interface');
}


Expand Down Expand Up @@ -257,7 +258,7 @@ public function removeRoleAll()
*
* @param Zend\Acl\Resource|string $resource
* @param Zend\Acl\Resource|string $parent
* @throws Zend\Acl\Exception
* @throws Zend\Acl\InvalidArgumentException
* @return Zend\Acl\Acl Provides a fluent interface
*/
public function addResource($resource, $parent = null)
Expand All @@ -267,13 +268,13 @@ public function addResource($resource, $parent = null)
}

if (!$resource instanceof Resource) {
throw new Exception('addResource() expects $resource to be of type Zend_Acl_Resource_Interface');
throw new InvalidArgumentException('addResource() expects $resource to be of type Zend_Acl_Resource_Interface');
}

$resourceId = $resource->getResourceId();

if ($this->hasResource($resourceId)) {
throw new Exception("Resource id '$resourceId' already exists in the ACL");
throw new InvalidArgumentException("Resource id '$resourceId' already exists in the ACL");
}

$resourceParent = null;
Expand All @@ -287,7 +288,7 @@ public function addResource($resource, $parent = null)
}
$resourceParent = $this->getResource($resourceParentId);
} catch (Exception $e) {
throw new Exception("Parent Resource id '$resourceParentId' does not exist", 0, $e);
throw new InvalidArgumentException("Parent Resource id '$resourceParentId' does not exist", 0, $e);
}
$this->_resources[$resourceParentId]['children'][$resourceId] = $resource;
}
Expand All @@ -307,7 +308,7 @@ public function addResource($resource, $parent = null)
* The $resource parameter can either be a Resource or a Resource identifier.
*
* @param Zend\Acl\Resource|string $resource
* @throws Zend\Acl\Exception
* @throws Zend\Acl\InvalidArgumentException
* @return Zend\Acl\Resource
*/
public function getResource($resource)
Expand All @@ -319,7 +320,7 @@ public function getResource($resource)
}

if (!$this->hasResource($resource)) {
throw new Exception("Resource '$resourceId' not found");
throw new InvalidArgumentException("Resource '$resourceId' not found");
}

return $this->_resources[$resourceId]['instance'];
Expand Down Expand Up @@ -356,7 +357,7 @@ public function hasResource($resource)
* @param Zend\Acl\Resource|string $resource
* @param Zend\Acl\Resource|string $inherit
* @param boolean $onlyParent
* @throws Zend_Acl_Resource_Exception
* @throws Zend\Acl\InvalidArgumentException
* @return boolean
*/
public function inheritsResource($resource, $inherit, $onlyParent = false)
Expand All @@ -365,7 +366,7 @@ public function inheritsResource($resource, $inherit, $onlyParent = false)
$resourceId = $this->getResource($resource)->getResourceId();
$inheritId = $this->getResource($inherit)->getResourceId();
} catch (Exception $e) {
throw new Exception($e->getMessage(), $e->getCode(), $e);
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
}

if (null !== $this->_resources[$resourceId]['parent']) {
Expand Down Expand Up @@ -395,15 +396,15 @@ public function inheritsResource($resource, $inherit, $onlyParent = false)
* The $resource parameter can either be a Resource or a Resource identifier.
*
* @param Zend\Acl\Resource|string $resource
* @throws Zend\Acl\Exception
* @throws Zend\Acl\InvalidArgumentException
* @return Zend\Acl\Acl Provides a fluent interface
*/
public function removeResource($resource)
{
try {
$resourceId = $this->getResource($resource)->getResourceId();
} catch (Exception $e) {
throw new Exception($e->getMessage(), $e->getCode(), $e);
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
}

$resourcesRemoved = array($resourceId);
Expand Down Expand Up @@ -555,7 +556,7 @@ public function removeDeny($roles = null, $resources = null, $privileges = null)
* @param Zend\Acl\Resource|string|array $resources
* @param string|array $privileges
* @param Zend\Acl\Assertion $assert
* @throws Zend\Acl\Exception
* @throws Zend\Acl\InvalidArgumentException
* @return Zend\Acl\Acl Provides a fluent interface
*/
public function setRule($operation, $type, $roles = null, $resources = null,
Expand All @@ -564,7 +565,7 @@ public function setRule($operation, $type, $roles = null, $resources = null,
// ensure that the rule type is valid; normalize input to uppercase
$type = strtoupper($type);
if (self::TYPE_ALLOW !== $type && self::TYPE_DENY !== $type) {
throw new Exception("Unsupported rule type; must be either '" . self::TYPE_ALLOW . "' or '"
throw new InvalidArgumentException("Unsupported rule type; must be either '" . self::TYPE_ALLOW . "' or '"
. self::TYPE_DENY . "'");
}

Expand Down Expand Up @@ -673,7 +674,7 @@ public function setRule($operation, $type, $roles = null, $resources = null,
break;

default:
throw new Exception("Unsupported operation; must be either '" . self::OP_ADD . "' or '"
throw new InvalidArgumentException("Unsupported operation; must be either '" . self::OP_ADD . "' or '"
. self::OP_REMOVE . "'");
}

Expand Down Expand Up @@ -841,12 +842,12 @@ protected function _roleDFSAllPrivileges(Role $role, Resource $resource = null)
* @param Zend\Acl\Resource $resource
* @param array $dfs
* @return boolean|null
* @throws \Zend\Acl\Exception
* @throws \Zend\Acl\RuntimeException
*/
protected function _roleDFSVisitAllPrivileges(Role $role, Resource $resource = null, &$dfs = null)
{
if (null === $dfs) {
throw new Exception('$dfs parameter may not be null');
throw new RuntimeException('$dfs parameter may not be null');
}

if (null !== ($rules = $this->_getRules($resource, $role))) {
Expand Down Expand Up @@ -879,12 +880,12 @@ protected function _roleDFSVisitAllPrivileges(Role $role, Resource $resource = n
* @param Zend\Acl\Resource $resource
* @param string $privilege
* @return boolean|null
* @throws Zend\Acl\Exception
* @throws Zend\Acl\RuntimeException
*/
protected function _roleDFSOnePrivilege(Role $role, Resource $resource = null, $privilege = null)
{
if (null === $privilege) {
throw new Exception('$privilege parameter may not be null');
throw new RuntimeException('$privilege parameter may not be null');
}

$dfs = array(
Expand Down Expand Up @@ -920,7 +921,7 @@ protected function _roleDFSOnePrivilege(Role $role, Resource $resource = null, $
* @param string $privilege
* @param array $dfs
* @return boolean|null
* @throws Zend\Acl\Exception
* @throws Zend\Acl\RuntimeException
*/
protected function _roleDFSVisitOnePrivilege(Role $role, Resource $resource = null,
$privilege = null, &$dfs = null
Expand All @@ -929,14 +930,14 @@ protected function _roleDFSVisitOnePrivilege(Role $role, Resource $resource = nu
/**
* @see Zend_Acl_Exception
*/
throw new Exception('$privilege parameter may not be null');
throw new RuntimeException('$privilege parameter may not be null');
}

if (null === $dfs) {
/**
* @see Zend_Acl_Exception
*/
throw new Exception('$dfs parameter may not be null');
throw new RuntimeException('$dfs parameter may not be null');
}

if (null !== ($ruleTypeOnePrivilege = $this->_getRuleType($resource, $role, $privilege))) {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Acl/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Exception extends \Zend\Exception
interface Exception
{}
8 changes: 8 additions & 0 deletions library/Zend/Acl/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Zend\Acl;

class InvalidArgumentException extends \InvalidArgumentException implements Exception
{

}
19 changes: 10 additions & 9 deletions library/Zend/Acl/Role/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace Zend\Acl\Role;

use Zend\Acl\Role;
use Zend\Acl;

/**
* @uses Zend\Acl\Role
Expand Down Expand Up @@ -59,15 +60,15 @@ class Registry
*
* @param Zend\Acl\Role $role
* @param Zend\Acl\Role|string|array $parents
* @throws Zend\Acl\Role\Exception
* @throws Zend\Acl\InvalidArgumentException
* @return Zend\Acl\Role\Registry Provides a fluent interface
*/
public function add(Role $role, $parents = null)
{
$roleId = $role->getRoleId();

if ($this->has($roleId)) {
throw new Exception("Role id '$roleId' already exists in the registry");
throw new Acl\InvalidArgumentException("Role id '$roleId' already exists in the registry");
}

$roleParents = array();
Expand All @@ -85,7 +86,7 @@ public function add(Role $role, $parents = null)
}
$roleParent = $this->get($roleParentId);
} catch (Exception $e) {
throw new Exception("Parent Role id '$roleParentId' does not exist", 0, $e);
throw new Acl\InvalidArgumentException("Parent Role id '$roleParentId' does not exist", 0, $e);
}
$roleParents[$roleParentId] = $roleParent;
$this->_roles[$roleParentId]['children'][$roleId] = $role;
Expand All @@ -107,7 +108,7 @@ public function add(Role $role, $parents = null)
* The $role parameter can either be a Role or a Role identifier.
*
* @param Zend\Acl\Role|string $role
* @throws Zend\Acl\Role\Exception
* @throws Zend\Acl\InvalidArgumentException
* @return Zend\Acl\Role
*/
public function get($role)
Expand All @@ -119,7 +120,7 @@ public function get($role)
}

if (!$this->has($role)) {
throw new Exception("Role '$roleId' not found");
throw new Acl\InvalidArgumentException("Role '$roleId' not found");
}

return $this->_roles[$roleId]['instance'];
Expand Down Expand Up @@ -177,7 +178,7 @@ public function getParents($role)
* @param Zend\Acl\Role|string $role
* @param Zend\Acl\Role|string $inherit
* @param boolean $onlyParents
* @throws Zend\Acl\Role\Exception
* @throws Zend\Acl\InvalidArgumentException
* @return boolean
*/
public function inherits($role, $inherit, $onlyParents = false)
Expand All @@ -186,7 +187,7 @@ public function inherits($role, $inherit, $onlyParents = false)
$roleId = $this->get($role)->getRoleId();
$inheritId = $this->get($inherit)->getRoleId();
} catch (Exception $e) {
throw new Exception($e->getMessage(), $e->getCode(), $e);
throw new Acl\InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
}

$inherits = isset($this->_roles[$roleId]['parents'][$inheritId]);
Expand All @@ -210,15 +211,15 @@ public function inherits($role, $inherit, $onlyParents = false)
* The $role parameter can either be a Role or a Role identifier.
*
* @param Zend\Acl\Role|string $role
* @throws Zend\Acl\Role\Exception
* @throws Zend\Acl\InvalidArgumentException
* @return Zend\Acl\Role\Registry Provides a fluent interface
*/
public function remove($role)
{
try {
$roleId = $this->get($role)->getRoleId();
} catch (Exception $e) {
throw new Exception($e->getMessage(), $e->getCode(), $e);
throw new Acl\InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
}

foreach ($this->_roles[$roleId]['children'] as $childId => $child) {
Expand Down
8 changes: 8 additions & 0 deletions library/Zend/Acl/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Zend\Acl;

class RuntimeException extends \RuntimeException implements Exception
{

}
9 changes: 6 additions & 3 deletions library/Zend/Authentication/Adapter/DbTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ protected function _setDbAdapter(AbstractDBAdapter $zendDb = null)
if(null === $this->_zendDb) {
$this->_zendDb = AbstractTable::getDefaultAdapter();
if (null === $this->_zendDb) {
throw new Exception('No database adapter present');
throw new RuntimeException(
'Null was provided for the adapter but there is no default'
. ' adatper registered with Zend\Db\Table to utilize.'
);
}
}

Expand Down Expand Up @@ -409,7 +412,7 @@ protected function _authenticateSetup()
}

if (null !== $exception) {
throw new Exception($exception);
throw new RuntimeException($exception);
}

$this->_authenticateResultInfo = array(
Expand Down Expand Up @@ -476,7 +479,7 @@ protected function _authenticateQuerySelect(DBSelect $dbSelect)
unset($origDbFetchMode);
}
} catch (\Exception $e) {
throw new Exception('The supplied parameters to Zend\\Authentication\\Adapter\\DbTable failed to '
throw new RuntimeException('The supplied parameters to Zend\Authentication\Adapter\DbTable failed to '
. 'produce a valid sql statement, please check table and column names '
. 'for validity.', 0, $e);
}
Expand Down
6 changes: 3 additions & 3 deletions library/Zend/Authentication/Adapter/Digest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,20 @@ public function setPassword($password)
/**
* Defined by Zend_Auth_Adapter_Interface
*
* @throws Zend\Authentication\Adapter\Exception
* @throws Zend\Authentication\Adapter\RuntimeException
* @return Zend\Authentication\Result
*/
public function authenticate()
{
$optionsRequired = array('filename', 'realm', 'username', 'password');
foreach ($optionsRequired as $optionRequired) {
if (null === $this->{"_$optionRequired"}) {
throw new Exception("Option '$optionRequired' must be set before authentication");
throw new RuntimeException("Option '$optionRequired' must be set before authentication");
}
}

if (false === ($fileHandle = @fopen($this->_filename, 'r'))) {
throw new Exception("Cannot open '$this->_filename' for reading");
throw new UnexpectedValueException("Cannot open '$this->_filename' for reading");
}

$id = "$this->_username:$this->_realm";
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Authentication/Adapter/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Exception extends \Zend\Authentication\Exception
interface Exception extends \Zend\Authentication\Exception
{}
Loading

0 comments on commit 9cfa4b2

Please sign in to comment.