Maybe a quick and dirty tests independent of routing, something like this, this the gist of my ACL study code, I'm a little embarrassed, but what the hell:
$acl = new \Phalcon\Acl\Adapter\Memory();
$acl->setDefaultAction(\Phalcon\Acl::DENY);
//Register roles
$roles = array(
'admin' => new \Phalcon\Acl\Role('admin'),
'guest' => new \Phalcon\Acl\Role('guest')
);
foreach ($roles as $role) {
$acl->addRole($role);
}
//Private area resources
$privateResources = array(
'acl-protected' => array('protected'),
);
foreach ($privateResources as $resource => $actions) {
$acl->addResource(new \Phalcon\Acl\Resource($resource), $actions);
}
//Public area resources
$publicResources = array(
'index' => array('index'),
'acl-protected' => array('index')
);
foreach ($publicResources as $resource => $actions) {
$acl->addResource(new \Phalcon\Acl\Resource($resource), $actions);
}
//Grant access to public areas to both users and guests
foreach ($roles as $role) {
foreach ($publicResources as $resource => $actions) {
$acl->allow('admin', $resource, '*'); // every controller's actions allowed, Carte blanche
$acl->allow('guest', $resource, $actions); // A controller has both public and protected actions, only specified ones are allowed, instead of * (all)
}
}
//Grant acess to private area to role admin
foreach ($privateResources as $resource => $actions) {
foreach ($actions as $action){
//echo $resource,' ', $action.'<br>';
$acl->allow('admin', $resource, $action);
}
}
// eyeball test
foreach ($roles as $role) {
foreach ($publicResources as $resource => $actions) {
foreach ($actions as $action){
echo $role ,' - ', $resource, '/', $action,' [access: ';
echo ($acl->isAllowed((string)$role, (string)$resource, $action) ? 'allowed' : 'false'),'] <br>';
}
}
foreach ($privateResources as $resource => $actions) {
foreach ($actions as $action){
echo $role ,' - ', $resource, '/', $action,' [access: ';
echo ($acl->isAllowed((string)$role, (string)$resource, $action) ? 'allowed' : 'false'),'] <br>';
}
}
echo '<hr>';
}