Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add parent roles with traversable object #4020

Closed
wants to merge 1 commit into from

3 participants

@ossinkine

No description provided.

@Freeaqingme Freeaqingme was assigned
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney [#4020] Import Traversable 6ac6b65
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/4020'
Close #4020
7332eb5
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/4020' into develop
Forward port #4020
f2c0be3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 13, 2013
  1. @ossinkine
This page is out of date. Refresh to see the latest.
View
6 library/Zend/Permissions/Acl/Role/Registry.php
@@ -34,8 +34,8 @@ class Registry
* will have the least priority, and the last parent added will have the
* highest priority.
*
- * @param RoleInterface $role
- * @param RoleInterface|string|array $parents
+ * @param RoleInterface $role
+ * @param RoleInterface|string|array|\Traversable $parents
* @throws Exception\InvalidArgumentException
* @return Registry Provides a fluent interface
*/
@@ -53,7 +53,7 @@ public function add(RoleInterface $role, $parents = null)
$roleParents = array();
if (null !== $parents) {
- if (!is_array($parents)) {
+ if (!is_array($parents) && !$parents instanceof \Traversable) {
$parents = array($parents);
}
foreach ($parents as $parent) {
View
37 tests/ZendTest/Permissions/Acl/AclTest.php
@@ -182,11 +182,11 @@ public function testRoleRegistryInherits()
}
/**
- * Tests basic Role multiple inheritance
+ * Tests basic Role multiple inheritance with array
*
* @return void
*/
- public function testRoleRegistryInheritsMultiple()
+ public function testRoleRegistryInheritsMultipleArray()
{
$roleParent1 = new Role\GenericRole('parent1');
$roleParent2 = new Role\GenericRole('parent2');
@@ -212,6 +212,39 @@ public function testRoleRegistryInheritsMultiple()
}
/**
+ * Tests basic Role multiple inheritance with traversable object
+ *
+ * @return void
+ */
+ public function testRoleRegistryInheritsMultipleTraversable()
+ {
+ $roleParent1 = new Role\GenericRole('parent1');
+ $roleParent2 = new Role\GenericRole('parent2');
+ $roleChild = new Role\GenericRole('child');
+ $roleRegistry = new Role\Registry();
+ $roleRegistry->add($roleParent1)
+ ->add($roleParent2)
+ ->add(
+ $roleChild,
+ new \ArrayIterator(array($roleParent1, $roleParent2))
+ );
+ $roleChildParents = $roleRegistry->getParents($roleChild);
+ $this->assertTrue(2 === count($roleChildParents));
+ $i = 1;
+ foreach ($roleChildParents as $roleParentId => $roleParent) {
+ $this->assertTrue("parent$i" === $roleParentId);
+ $i++;
+ }
+ $this->assertTrue($roleRegistry->inherits($roleChild, $roleParent1));
+ $this->assertTrue($roleRegistry->inherits($roleChild, $roleParent2));
+ $roleRegistry->remove($roleParent1);
+ $roleChildParents = $roleRegistry->getParents($roleChild);
+ $this->assertTrue(1 === count($roleChildParents));
+ $this->assertTrue(isset($roleChildParents['parent2']));
+ $this->assertTrue($roleRegistry->inherits($roleChild, $roleParent2));
+ }
+
+ /**
* Ensures that the same Role cannot be registered more than once to the registry
*
* @return void
Something went wrong with that request. Please try again.