Skip to content

Commit

Permalink
Merge branch 'hotfix/ZF-27-ACL' of https://github.com/gabriel403/zf2
Browse files Browse the repository at this point in the history
…into hotfix/acl-interface

Conflicts:
	library/Zend/Acl/Acl.php

For story [zen-27]
  • Loading branch information
weierophinney committed Apr 9, 2012
2 parents 2856d64 + ef25edc commit d56cc9d
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 154 deletions.
157 changes: 75 additions & 82 deletions library/Zend/Acl/Acl.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Acl;
namespace Zend\Acl\Assertion;

use Zend\Acl;
/**
* @uses Zend\Acl\Acl
* @uses Zend\Acl\Resource
* @uses Zend\Acl\Role
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Assertion
interface AssertionInterface
{
/**
* Returns true if and only if the assertion conditions are met
Expand All @@ -38,11 +36,11 @@ interface Assertion
* $role, $resource, or $privilege parameters are null, it means that the query applies to all Roles, Resources, or
* privileges, respectively.
*
* @param Acl $acl
* @param Role $role
* @param Resource $resource
* @param string $privilege
* @param Acl $acl
* @param Role\RoleInterface $role
* @param Resource\ResourceInterface $resource
* @param string $privilege
* @return boolean
*/
public function assert(Acl $acl, Role $role = null, Resource $resource = null, $privilege = null);
public function assert(Acl\Acl $acl, Acl\Role\RoleInterface $role = null, Acl\Resource\ResourceInterface $resource = null, $privilege = null);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Acl;
namespace Zend\Acl\Exception;

/**
* @uses Zend\Exception
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Exception
interface ExceptionInterface
{}
2 changes: 1 addition & 1 deletion library/Zend/Acl/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class InvalidArgumentException
extends \InvalidArgumentException
implements \Zend\Acl\Exception
implements \Zend\Acl\Exception\ExceptionInterface
{

}
2 changes: 1 addition & 1 deletion library/Zend/Acl/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class RuntimeException
extends \RuntimeException
implements \Zend\Acl\Exception
implements \Zend\Acl\Exception\ExceptionInterface
{

}
5 changes: 2 additions & 3 deletions library/Zend/Acl/Resource/GenericResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@

namespace Zend\Acl\Resource;

use Zend\Acl\Resource;
use Zend\Acl\Resource\ResourceInterface;

/**
* @uses \Zend\Acl\Resource\ResourceInterface
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class GenericResource implements Resource
class GenericResource implements ResourceInterface
{
/**
* Unique id of Resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Acl;
namespace Zend\Acl\Resource;

/**
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Resource
interface ResourceInterface
{
/**
* Returns the string identifier of the Resource
Expand Down
9 changes: 4 additions & 5 deletions library/Zend/Acl/Role/GenericRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@

namespace Zend\Acl\Role;

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

/**
* @uses Zend\Acl\Role
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class GenericRole implements Role
class GenericRole implements RoleInterface
{
/**
* Unique id of Role
Expand All @@ -50,7 +49,7 @@ public function __construct($roleId)
}

/**
* Defined by Zend\Acl\Role; returns the Role identifier
* Defined by Zend\Acl\Role\RoleInterface; returns the Role identifier
*
* @return string
*/
Expand All @@ -60,7 +59,7 @@ public function getRoleId()
}

/**
* Defined by Zend\Acl\Role; returns the Role identifier
* Defined by Zend\Acl\Role\RoleInterface; returns the Role identifier
* Proxies to getRoleId()
*
* @return string
Expand Down
26 changes: 12 additions & 14 deletions library/Zend/Acl/Role/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@


/**
* @uses Zend\Acl\Role
* @uses Zend\Acl\Role\Exception
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
Expand Down Expand Up @@ -56,12 +54,12 @@ class Registry
* will have the least priority, and the last parent added will have the
* highest priority.
*
* @param \Zend\Acl\Role $role
* @param \Zend\Acl\Role|string|array $parents
* @param \Zend\Acl\Role\RoleInterface $role
* @param \Zend\Acl\Role\RoleInterface|string|array $parents
* @throws \Zend\Acl\Exception\InvalidArgumentException
* @return Registry Provides a fluent interface
*/
public function add(Role $role, $parents = null)
public function add(Role\RoleInterface $role, $parents = null)
{
$roleId = $role->getRoleId();

Expand All @@ -77,13 +75,13 @@ public function add(Role $role, $parents = null)
}
foreach ($parents as $parent) {
try {
if ($parent instanceof Role) {
if ($parent instanceof Role\RoleInterface) {
$roleParentId = $parent->getRoleId();
} else {
$roleParentId = $parent;
}
$roleParent = $this->get($roleParentId);
} catch (Exception $e) {
} catch (\Exception $e) {
throw new Acl\Exception\InvalidArgumentException("Parent Role id '$roleParentId' does not exist", 0, $e);
}
$roleParents[$roleParentId] = $roleParent;
Expand Down Expand Up @@ -111,7 +109,7 @@ public function add(Role $role, $parents = null)
*/
public function get($role)
{
if ($role instanceof Role) {
if ($role instanceof Role\RoleInterface) {
$roleId = $role->getRoleId();
} else {
$roleId = (string) $role;
Expand All @@ -134,7 +132,7 @@ public function get($role)
*/
public function has($role)
{
if ($role instanceof Role) {
if ($role instanceof Role\RoleInterface) {
$roleId = $role->getRoleId();
} else {
$roleId = (string) $role;
Expand All @@ -154,7 +152,7 @@ public function has($role)
* If the Role does not have any parents, then an empty array is returned.
*
* @uses Zend\Acl\Role\Registry::get()
* @param \Zend\Acl\Role|string $role
* @param \Zend\Acl\Role\RoleInterface|string $role
* @return array
*/
public function getParents($role)
Expand All @@ -173,9 +171,9 @@ public function getParents($role)
* through the entire inheritance DAG to determine whether $role
* inherits from $inherit through its ancestor Roles.
*
* @param \Zend\Acl\Role|string $role
* @param \Zend\Acl\Role|string $inherit
* @param boolean $onlyParents
* @param \Zend\Acl\Role\RoleInterface|string $role
* @param \Zend\Acl\Role\RoleInterface|string $inherit
* @param boolean $onlyParents
* @throws \Zend\Acl\Exception\InvalidArgumentException
* @return boolean
*/
Expand Down Expand Up @@ -208,7 +206,7 @@ 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
* @param \Zend\Acl\Role\RoleInterface|string $role
* @throws \Zend\Acl\Exception\InvalidArgumentException
* @return Registry Provides a fluent interface
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Acl;
namespace Zend\Acl\Role;

/**
* @category Zend
* @package Zend_Acl
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Role
interface RoleInterface
{
/**
* Returns the string identifier of the Role
Expand Down
36 changes: 18 additions & 18 deletions tests/Zend/Acl/AclTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testRoleAddAndGetOneByString()
{
$role = $this->_acl->addRole('area')
->getRole('area');
$this->assertInstanceOf('Zend\Acl\Role', $role);
$this->assertInstanceOf('Zend\Acl\Role\RoleInterface', $role);
$this->assertEquals('area', $role->getRoleId());
}

Expand Down Expand Up @@ -275,7 +275,7 @@ public function testResourceAddAndGetOneByString()
{
$resource = $this->_acl->addResource('area')
->getResource('area');
$this->assertInstanceOf('Zend\Acl\Resource', $resource);
$this->assertInstanceOf('Zend\Acl\Resource\ResourceInterface', $resource);
$this->assertEquals('area', $resource->getResourceId());
}

Expand Down Expand Up @@ -314,7 +314,7 @@ public function testResourceRemoveOne()
*/
public function testResourceRemoveOneNonExistent()
{
$this->setExpectedException('Zend\Acl\Exception', 'not found');
$this->setExpectedException('Zend\Acl\Exception\ExceptionInterface', 'not found');
$this->_acl->removeResource('nonexistent');
}

Expand Down Expand Up @@ -365,14 +365,14 @@ public function testResourceInheritsNonExistent()
$this->_acl->addResource($resourceArea);
try {
$this->_acl->inheritsResource('nonexistent', $resourceArea);
$this->fail('Expected Zend\Acl\Exception not thrown upon specifying a non-existent child Resource');
} catch (Acl\Exception $e) {
$this->fail('Expected Zend\Acl\Exception\ExceptionInterface not thrown upon specifying a non-existent child Resource');
} catch (Acl\Exception\ExceptionInterface $e) {
$this->assertContains('not found', $e->getMessage());
}
try {
$this->_acl->inheritsResource($resourceArea, 'nonexistent');
$this->fail('Expected Zend\Acl\Exception not thrown upon specifying a non-existent parent Resource');
} catch (Acl\Exception $e) {
$this->fail('Expected Zend\Acl\Exception\ExceptionInterface not thrown upon specifying a non-existent parent Resource');
} catch (Acl\Exception\ExceptionInterface $e) {
$this->assertContains('not found', $e->getMessage());
}
}
Expand Down Expand Up @@ -407,7 +407,7 @@ public function testResourceInherits()
*/
public function testResourceDuplicate()
{
$this->setExpectedException('Zend\Acl\Exception', 'already exists');
$this->setExpectedException('Zend\Acl\Exception\ExceptionInterface', 'already exists');
$resourceArea = new Resource\GenericResource('area');
$this->_acl->addResource($resourceArea)
->addResource($resourceArea);
Expand All @@ -420,7 +420,7 @@ public function testResourceDuplicate()
*/
public function testResourceDuplicateId()
{
$this->setExpectedException('Zend\Acl\Exception', 'already exists');
$this->setExpectedException('Zend\Acl\Exception\ExceptionInterface', 'already exists');
$resourceArea1 = new Resource\GenericResource('area');
$resourceArea2 = new Resource\GenericResource('area');
$this->_acl->addResource($resourceArea1)
Expand All @@ -436,13 +436,13 @@ public function testIsAllowedNonExistent()
{
try {
$this->_acl->isAllowed('nonexistent');
$this->fail('Expected Zend\Acl\Role\Exception not thrown upon non-existent Role');
$this->fail('Expected Zend\Acl\Role\Exception\ExceptionInterface not thrown upon non-existent Role');
} catch (Acl\Exception\InvalidArgumentException $e) {
$this->assertContains('not found', $e->getMessage());
}
try {
$this->_acl->isAllowed(null, 'nonexistent');
$this->fail('Expected Zend\Acl\Exception not thrown upon non-existent Resource');
$this->fail('Expected Zend\Acl\Exception\ExceptionInterface not thrown upon non-existent Resource');
} catch (Acl\Exception\InvalidArgumentException $e) {
$this->assertContains('not found', $e->getMessage());
}
Expand Down Expand Up @@ -845,7 +845,7 @@ public function testRulesResourceRemove()
try {
$this->_acl->isAllowed(null, 'area');
$this->fail('Expected Zend\Acl\Exception not thrown upon isAllowed() on non-existent Resource');
} catch (Acl\Exception $e) {
} catch (Acl\Exception\ExceptionInterface $e) {
$this->assertContains('not found', $e->getMessage());
}
$this->_acl->addResource(new Resource\GenericResource('area'));
Expand All @@ -865,8 +865,8 @@ public function testRulesResourceRemoveAll()
$this->_acl->removeResourceAll();
try {
$this->_acl->isAllowed(null, 'area');
$this->fail('Expected Zend\Acl\Exception not thrown upon isAllowed() on non-existent Resource');
} catch (Acl\Exception $e) {
$this->fail('Expected Zend\Acl\Exception\ExceptionInterface not thrown upon isAllowed() on non-existent Resource');
} catch (Acl\Exception\ExceptionInterface $e) {
$this->assertContains('not found', $e->getMessage());
}
$this->_acl->addResource(new Resource\GenericResource('area'));
Expand Down Expand Up @@ -1076,28 +1076,28 @@ public function testAclInternalDFSMethodsBehaveProperly()
try {
$acl->roleDFSVisitAllPrivileges($someRole, $someResource, $nullReference);
$this->fail('Expected Zend\Acl\Exception not thrown');
} catch (Acl\Exception $e) {
} catch (Acl\Exception\ExceptionInterface $e) {
$this->assertEquals('$dfs parameter may not be null', $e->getMessage());
}

try {
$acl->roleDFSOnePrivilege($someRole, $someResource, null);
$this->fail('Expected Zend\Acl\Exception not thrown');
} catch (Acl\Exception $e) {
} catch (Acl\Exception\ExceptionInterface $e) {
$this->assertEquals('$privilege parameter may not be null', $e->getMessage());
}

try {
$acl->roleDFSVisitOnePrivilege($someRole, $someResource, null);
$this->fail('Expected Zend\Acl\Exception not thrown');
} catch (Acl\Exception $e) {
} catch (Acl\Exception\ExceptionInterface $e) {
$this->assertEquals('$privilege parameter may not be null', $e->getMessage());
}

try {
$acl->roleDFSVisitOnePrivilege($someRole, $someResource, 'somePrivilege', $nullReference);
$this->fail('Expected Zend\\Acl\\Exception not thrown');
} catch (Acl\Exception $e) {
} catch (Acl\Exception\ExceptionInterface $e) {
$this->assertEquals('$dfs parameter may not be null', $e->getMessage());
}
}
Expand Down
Loading

0 comments on commit d56cc9d

Please sign in to comment.