Issues

ZF-5638: Add methods to get defined roles, ressources, rules

Description

I haven't found a method to get the defined roles (or ressources or rules for that matter). The use case I need it for is quite simple.

Very early in the request we setup a Zend_Acl instance with some roles, predefined ressources and rules. We also have a database with users and their assigned ACL role. Now what we want to do is creating a simple form with all the defined roles, so one of them can be assigned to a specific user.

But all roles defined earlier are hidden in the protected variable _roles and having to store them in an extra variable, just to be able to use them in one form, doesn't seem to be right.

At least for roles it should be quite easy to add a method like this to Zend_Acl_Role_Registry: public function getRoles() { return array_keys($this->_roles); }

As ressources and rules seems to be hidden too, there also should be an easy way to access them.

Comments

Just hit upon this very matter myself. Clearly it would be trivial to implement as an extended class, butshould this feature be included within Zend_Acl for shipping?

To do this Zend_Acl_Role_Registry requires a new method:

public function getRoles() { return $this->_roles; }

Then Zend_Acl requires a new method:

public function getRegisteredRoles() { return $this->_getRoleRegistry()->getRoles(); }

You may then iterate over the list returned by Zend_Acl::getRegisteredRoles(). The keys will be the role ID.

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.

Like the other commenter said, it appears trivial to add getRegisteredRoles() method. I have added the methods in Acl.php and Acl_Role_Registry.php with unit test method.

Patch applied; allowing to add to 1.9 release branch as well.