Skip to content

Commit

Permalink
Implement #6: remove Zend_Acl_Role_Registry_Exception class
Browse files Browse the repository at this point in the history
  • Loading branch information
Bui Sy Nguyen committed Jan 21, 2016
1 parent f7959cd commit 8857f25
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 68 deletions.
44 changes: 12 additions & 32 deletions fproject/Zend/Acl/Role/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,15 @@ class Zend_Acl_Role_Registry
*
* @param Zend_Acl_Role_Interface $role
* @param Zend_Acl_Role_Interface|string|array $parents
* @throws Zend_Acl_Role_Registry_Exception
* @throws \fproject\amf\AmfException
* @return Zend_Acl_Role_Registry Provides a fluent interface
*/
public function add(Zend_Acl_Role_Interface $role, $parents = null)
{
$roleId = $role->getRoleId();

if ($this->has($roleId)) {
/**
* @see Zend_Acl_Role_Registry_Exception
*/
require_once 'Zend/Acl/Role/Registry/Exception.php';
throw new Zend_Acl_Role_Registry_Exception("Role id '$roleId' already exists in the registry");
throw new \fproject\amf\AmfException("Role id '$roleId' already exists in the registry");
}

$roleParents = [];
Expand All @@ -78,10 +74,6 @@ public function add(Zend_Acl_Role_Interface $role, $parents = null)
if (!is_array($parents)) {
$parents = array($parents);
}
/**
* @see Zend_Acl_Role_Registry_Exception
*/
require_once 'Zend/Acl/Role/Registry/Exception.php';
foreach ($parents as $parent) {
try {
if ($parent instanceof Zend_Acl_Role_Interface) {
Expand All @@ -90,8 +82,8 @@ public function add(Zend_Acl_Role_Interface $role, $parents = null)
$roleParentId = $parent;
}
$roleParent = $this->get($roleParentId);
} catch (Zend_Acl_Role_Registry_Exception $e) {
throw new Zend_Acl_Role_Registry_Exception("Parent Role id '$roleParentId' does not exist", 0, $e);
} catch (\fproject\amf\AmfException $e) {
throw new \fproject\amf\AmfException("Parent Role id '$roleParentId' does not exist", 0, $e);
}
$roleParents[$roleParentId] = $roleParent;
$this->_roles[$roleParentId]['children'][$roleId] = $role;
Expand All @@ -113,7 +105,7 @@ public function add(Zend_Acl_Role_Interface $role, $parents = null)
* The $role parameter can either be a Role or a Role identifier.
*
* @param Zend_Acl_Role_Interface|string $role
* @throws Zend_Acl_Role_Registry_Exception
* @throws \fproject\amf\AmfException
* @return Zend_Acl_Role_Interface
*/
public function get($role)
Expand All @@ -125,11 +117,7 @@ public function get($role)
}

if (!$this->has($role)) {
/**
* @see Zend_Acl_Role_Registry_Exception
*/
require_once 'Zend/Acl/Role/Registry/Exception.php';
throw new Zend_Acl_Role_Registry_Exception("Role '$roleId' not found");
throw new \fproject\amf\AmfException("Role '$roleId' not found");
}

return $this->_roles[$roleId]['instance'];
Expand Down Expand Up @@ -187,20 +175,16 @@ public function getParents($role)
* @param Zend_Acl_Role_Interface|string $role
* @param Zend_Acl_Role_Interface|string $inherit
* @param boolean $onlyParents
* @throws Zend_Acl_Role_Registry_Exception
* @throws \fproject\amf\AmfException
* @return boolean
*/
public function inherits($role, $inherit, $onlyParents = false)
{
/**
* @see Zend_Acl_Role_Registry_Exception
*/
require_once 'Zend/Acl/Role/Registry/Exception.php';
try {
$roleId = $this->get($role)->getRoleId();
$inheritId = $this->get($inherit)->getRoleId();
} catch (Zend_Acl_Role_Registry_Exception $e) {
throw new Zend_Acl_Role_Registry_Exception($e->getMessage(), $e->getCode(), $e);
} catch (\fproject\amf\AmfException $e) {
throw new \fproject\amf\AmfException($e->getMessage(), $e->getCode(), $e);
}

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

foreach ($this->_roles[$roleId]['children'] as $childId => $child) {
Expand Down
36 changes: 0 additions & 36 deletions fproject/Zend/Acl/Role/Registry/Exception.php

This file was deleted.

0 comments on commit 8857f25

Please sign in to comment.