diff --git a/composer.json b/composer.json index 44c376c3..27ee70bc 100644 --- a/composer.json +++ b/composer.json @@ -13,12 +13,12 @@ } }, "require": { - "php": ">=5.3.3" + "php": ">=5.3.23" }, "extra": { "branch-alias": { - "dev-master": "2.2-dev", - "dev-develop": "2.3-dev" + "dev-master": "2.3-dev", + "dev-develop": "2.4-dev" } }, "autoload-dev": { diff --git a/src/AbstractIterator.php b/src/AbstractIterator.php index 4f922ec1..5b28a922 100644 --- a/src/AbstractIterator.php +++ b/src/AbstractIterator.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -13,7 +13,13 @@ abstract class AbstractIterator implements RecursiveIterator { + /** + * @var int + */ protected $index = 0; + /** + * @var array + */ protected $children = array(); /** @@ -42,7 +48,7 @@ public function next() * (PHP 5 >= 5.0.0)
* Return the key of the current element * @link http://php.net/manual/en/iterator.key.php - * @return scalar scalar on success, or null on failure. + * @return int|null scalar on success, or null on failure. */ public function key() { @@ -90,7 +96,7 @@ public function hasChildren() /** * (PHP 5 >= 5.1.0)
* Returns an iterator for the current entry. - * @link http://php.net/manual/en/recursiveiterator.getRoles.php + * @link http://php.net/manual/en/recursiveiterator.getchildren.php * @return RecursiveIterator An iterator for the current entry. */ public function getChildren() diff --git a/src/AbstractRole.php b/src/AbstractRole.php index fff1a9ac..d3d6ea76 100644 --- a/src/AbstractRole.php +++ b/src/AbstractRole.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/AssertionInterface.php b/src/AssertionInterface.php index b94e0aa5..0a01addc 100644 --- a/src/AssertionInterface.php +++ b/src/AssertionInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index abeb69b2..c94f8b80 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index a53b3950..9c89a682 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/Rbac.php b/src/Rbac.php index d1397812..3ce66aa2 100644 --- a/src/Rbac.php +++ b/src/Rbac.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ @@ -108,15 +108,22 @@ public function getRole($objectOrName) ); } + if (is_object($objectOrName)) { + $requiredRole = $objectOrName->getName(); + } else { + $requiredRole = $objectOrName; + } + $it = new RecursiveIteratorIterator($this, RecursiveIteratorIterator::CHILD_FIRST); foreach ($it as $leaf) { - if ((is_string($objectOrName) && $leaf->getName() == $objectOrName) || $leaf == $objectOrName) { + /** @var RoleInterface $leaf */ + if ($leaf->getName() == $requiredRole) { return $leaf; } } throw new Exception\InvalidArgumentException(sprintf( - 'No child with name "%s" could be found', + 'No role with name "%s" could be found', is_object($objectOrName) ? $objectOrName->getName() : $objectOrName )); } @@ -127,6 +134,7 @@ public function getRole($objectOrName) * @param RoleInterface|string $role * @param string $permission * @param AssertionInterface|Callable|null $assert + * @throws Exception\InvalidArgumentException * @return bool */ public function isGranted($role, $permission, $assert = null) diff --git a/src/Role.php b/src/Role.php index 212bd0d0..9daa1d74 100644 --- a/src/Role.php +++ b/src/Role.php @@ -3,7 +3,7 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ diff --git a/src/RoleInterface.php b/src/RoleInterface.php index df75d79a..fd8a65c5 100644 --- a/src/RoleInterface.php +++ b/src/RoleInterface.php @@ -3,13 +3,15 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Permissions\Rbac; -interface RoleInterface extends \RecursiveIterator +use RecursiveIterator; + +interface RoleInterface extends RecursiveIterator { /** * Get the name of the role. diff --git a/test/RbacTest.php b/test/RbacTest.php index 234ed960..cf6f1ab7 100644 --- a/test/RbacTest.php +++ b/test/RbacTest.php @@ -3,20 +3,15 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Permissions */ namespace ZendTest\Permissions\Rbac; use Zend\Permissions\Rbac; -use ZendTest\Permissions\Rbac\TestAsset; /** - * @category Zend - * @package Zend_Permissions - * @subpackage UnitTests * @group Zend_Rbac */ class RbacTest extends \PHPUnit_Framework_TestCase @@ -87,16 +82,30 @@ public function testIsGrantedChildRoles() $this->assertEquals(false, $this->rbac->isGranted('bar', 'can.baz')); } + /** + * @covers Zend\Permissions\Rbac\Rbac::hasRole() + */ public function testHasRole() { $foo = new Rbac\Role('foo'); + $snafu = new TestAsset\RoleTest('snafu'); $this->rbac->addRole('bar'); $this->rbac->addRole($foo); + $this->rbac->addRole('snafu'); + + // check that the container has the same object $foo + $this->assertTrue($this->rbac->hasRole($foo)); + + // check that the container has the same string "bar" + $this->assertTrue($this->rbac->hasRole('bar')); + + // check that the container do not have the string "baz" + $this->assertFalse($this->rbac->hasRole('baz')); - $this->assertEquals(true, $this->rbac->hasRole($foo)); - $this->assertEquals(true, $this->rbac->hasRole('bar')); - $this->assertEquals(false, $this->rbac->hasRole('baz')); + // check that we can compare two different objects with same name + $this->assertNotEquals($this->rbac->getRole('snafu'), $snafu); + $this->assertTrue($this->rbac->hasRole($snafu)); } public function testAddRoleFromString() diff --git a/test/TestAsset/RoleMustMatchAssertion.php b/test/TestAsset/RoleMustMatchAssertion.php index 5cefa212..369ef842 100644 --- a/test/TestAsset/RoleMustMatchAssertion.php +++ b/test/TestAsset/RoleMustMatchAssertion.php @@ -3,9 +3,8 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Permissions */ namespace ZendTest\Permissions\Rbac\TestAsset; @@ -15,9 +14,6 @@ use Zend\Permissions\Rbac\Rbac; /** - * @category Zend - * @package Zend_Permissions - * @subpackage UnitTests * @group Zend_Rbac */ class RoleMustMatchAssertion implements AssertionInterface diff --git a/test/TestAsset/RoleTest.php b/test/TestAsset/RoleTest.php new file mode 100644 index 00000000..81a2987c --- /dev/null +++ b/test/TestAsset/RoleTest.php @@ -0,0 +1,23 @@ +name = $name; + } +} diff --git a/test/TestAsset/SimpleFalseAssertion.php b/test/TestAsset/SimpleFalseAssertion.php index 637e1df4..99766906 100644 --- a/test/TestAsset/SimpleFalseAssertion.php +++ b/test/TestAsset/SimpleFalseAssertion.php @@ -3,9 +3,8 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Permissions */ namespace ZendTest\Permissions\Rbac\TestAsset; @@ -14,9 +13,6 @@ use Zend\Permissions\Rbac\Rbac; /** - * @category Zend - * @package Zend_Permissions - * @subpackage UnitTests * @group Zend_Rbac */ class SimpleFalseAssertion implements AssertionInterface diff --git a/test/TestAsset/SimpleTrueAssertion.php b/test/TestAsset/SimpleTrueAssertion.php index 2eac096b..1ea5eb2c 100644 --- a/test/TestAsset/SimpleTrueAssertion.php +++ b/test/TestAsset/SimpleTrueAssertion.php @@ -3,9 +3,8 @@ * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository - * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Permissions */ namespace ZendTest\Permissions\Rbac\TestAsset; @@ -14,9 +13,6 @@ use Zend\Permissions\Rbac\Rbac; /** - * @category Zend - * @package Zend_Permissions - * @subpackage UnitTests * @group Zend_Rbac */ class SimpleTrueAssertion implements AssertionInterface