Archived
1
0
Fork 0

app/library/Acl.php: some cleanup.

This commit is contained in:
Henrik Hautakoski 2018-08-10 02:23:06 +02:00
parent d6dbb6e085
commit 694eac24ef
No known key found for this signature in database
GPG key ID: 839F3A7EAFAEAFAA

View file

@ -2,8 +2,8 @@
namespace Httpcb;
use Phalcon\Acl\Role;
use Phalcon\Acl\Adapter\Memory as AclList;
use Phalcon\Acl\Role,
Phalcon\Acl\Adapter\Memory as AclList;
class Acl extends AclList
{
@ -11,22 +11,18 @@ class Acl extends AclList
const ROLE_GUEST = 'guest';
public function __construct()
{
$this->_build();
}
protected function _build()
{
// Deny access to everything by default.
$this->setDefaultAction(\Phalcon\Acl::DENY);
// Roles
$user = new Role('user');
$guest = new Role('guest');
$guest = new Role(self::ROLE_GUEST);
$user = new Role(self::ROLE_USER);
$this->addRole($guest);
$this->addRole($user, $guest);
// Public Resources
$public = array(
'index',
'error',
@ -34,20 +30,22 @@ class Acl extends AclList
'api',
);
// Public Resources
foreach($public as $resource) {
$this->addResource($resource, 'Read');
$this->allow($guest->getName(), $resource, 'Read');
}
$this->_grant($guest, $public);
// Protected Resources
$protected = array(
'callback',
'user',
);
foreach($protected as $resource) {
$this->_grant($user, $protected);
}
protected function _grant(Role $role, array $resources)
{
foreach($resources as $resource) {
$this->addResource($resource, 'Read');
$this->allow($user->getName(), $resource, 'Read');
$this->allow($role->getName(), $resource, 'Read');
}
}
}