Archived
1
0
Fork 0
This repository has been archived on 2026-04-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
httpcb/app/library/Acl.php

51 lines
1.1 KiB
PHP

<?php
namespace Httpcb;
use Phalcon\Acl\Role,
Phalcon\Acl\Adapter\Memory as AclList;
class Acl extends AclList
{
const ROLE_USER = 'user';
const ROLE_GUEST = 'guest';
public function __construct()
{
// Deny access to everything by default.
$this->setDefaultAction(\Phalcon\Acl::DENY);
// Roles
$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',
'auth',
'api',
);
$this->_grant($guest, $public);
// Protected Resources
$protected = array(
'callback',
'user',
);
$this->_grant($user, $protected);
}
protected function _grant(Role $role, array $resources)
{
foreach($resources as $resource) {
$this->addResource($resource, 'Read');
$this->allow($role->getName(), $resource, 'Read');
}
}
}