Phalcon PHP - Get all permitted resources

453 views Asked by At

I am using ACL in Phalcon PHP (Phalcon\Acl\Adapter\Memory). I would like to know if it is possible to get all resources / actions a specific role is permitted to do / to access?

This code checks if a specific role is permitted to perform a specific action on a specific resource:

$acl->isAllowed("Guests", "Customers", "create");

I don't want to run over all resources and actions and check permissions with the code above. I need it all at once.

Is it possible?

1

There are 1 answers

0
James Fenwick On
<?php
use \Phalcon\Acl\Adapter\Memory as Acl;

class CustomAcl extends Acl {

    public function getAllowed($role) {
        $accessList = array();
        foreach ($this->_access as $resource => $permission) {
            $resourceRole = explode("!", $resource);
            if ($resourceRole[0] != $role) {
                continue;
            }
            if ($permission == 1) {
                $accessList[] = $resource;
            }
        }
        return $accessList;
    }

}

This would return all the roles in the form of an array:

array (
    0 => 'role!resource!action',
    1 => 'role!resource!action',
    ...
    n => 'role!resource!action'
)

the same way they are stored inside the acl.