/**
* @param Zend_Acl_Resource_Interface|string $resource
* @return Zend_Acl_Resource_Interface|null
*/
public function getParent($resource) {
$resourceId = $this->get($resource)->getResourceId();
return $this->_resources[ $resourceId ]['parent'];
}
/**
* @param Zend_Acl_Resource_Interface|string $resource
* @return array([ string => Zend_Acl_Resource_Interface[, ...]])
*/
public function getAllParents($resource) {
$resource = $this->get($resource);
$parents = array();
do {
$parent = $this->getParent($resource);
if (!$parent) {
break;
} else {
$resource = $parent;
$parents[ $parent->getResourceId() ] = $parent;
}
} while (true);
return $parents;
}
// This method must implemented in Zend_Acl_Role_Registry
public function getAllParentRoles($role) {
$role = $this->getRole($role);
$parents = $this->_getRoleRegistry()->getParents($role);
foreach ($parents as $role) {
$parents = array_merge($parents, $this->getAllParentRoles($role));
}
return $parents;
}
Comments
Posted by Bill Karwin (bkarwin) on 2007-05-07T11:57:20.000+0000
Assigning to Darby.
Posted by Sorin Alin Stoiana (sorin) on 2007-07-30T14:26:35.000+0000
Posted by Sorin Alin Stoiana (sorin) on 2007-07-30T14:28:12.000+0000
There should also be some methods for retrieving Role children. I'm working on those, and will post them here.
Posted by Darby Felton (darby) on 2007-07-31T11:54:22.000+0000
Resources are organized into a tree. Therefore, at most one parent resource can exist for any given resource.
Roles are organized into a directed acyclic graph (DAG). Therefore, a role may have zero, one, or more than one parent roles.
Posted by Darby Felton (darby) on 2007-07-31T11:59:36.000+0000
I see that the intent is to fetch all ancestors (i.e., parents, grandparents, and so on) of a role or resource. Though this is fine, the results hide the actual data structure. For example, it is not apparent whether a returned "parent" resource is actually a parent, the parent of a parent, and so on.
Further, for what purpose is such information useful, I'm curious? That is, what use case requirements do these new methods help to meet?
Posted by Sorin Alin Stoiana (sorin) on 2007-08-01T14:24:01.000+0000
It seems logical to be able to interrogate the Acl object once created, to meet the needs of (say) a CMS, where roles, resources and permissions vary dynamically to match the structure of the content.
A typical use case would be listing all the Roles defined in the Acl:
Posted by Ralph Schindler (ralph) on 2009-09-10T08:36:40.000+0000
While this is a worthwhile feature, the ZF team will not develop this feature, but if a community member would like to pick up and develop it, they may make an assignment of it.
Posted by Thomas Weidner (thomas) on 2010-03-21T10:30:26.000+0000
Reassigned to component maintainer