class Pike\Auth\ACL
Piken Access Contrl List -implementaatio. Katso myös Käyttäjäroolit ja oikeudet.
Synopsis
class ACL {
/* Vakiot */
const ROLE_SUPER_ADMIN = 1 << 0 ;
const ROLE_EDITOR = 1 << 1 ;
const ROLE_AUTHOR = 1 << 2 ;
const ROLE_CONTRIBUTOR = 1 << 3 ;
const ROLE_LAST = 1 << 23 ;
const ROLE_VIEWER = self::ROLE_LAST ;
const NO_PERMISSIONS = 0 ;
/* Metodit */
public __construct ( bool $doThrowDevWarnings = false )
public setRules ( stdClass $compactRules ) : void
public can ( int $role, string $action, string $resource ) : bool
public static makePermissions ( array|string $allowedActions, stdClass $resourceActions ) : int
}
Metodit
__construct()
Lue uuden ACL-olion.
Signature
public function __construct ( bool $doThrowDevWarnings = false )
Esimerkit
$acl = new ACL(false);
$acl->can(ACL::ROLE_EDITOR, 'ei-olemassa', 'ei-olemassa'); // false
$acl = new ACL(true);
$acl->can(ACL::ROLE_EDITOR, 'ei-olemassa', 'ei-olemassa'); // heittää PikeExceptionin
setRules()
Asettaa ACL-säännöt, roolit ja oikeudet.
Signature
public function setRules ( stdClass $compactRules ) : void
Esimerkit
$acl->setRules((object) ['resources' => ..., 'userPermissions' => ...]);
can()
Kertoo onko käyttäjällä ($role) oikeus suorittaa aie ($action) resursissa $resource. Mikäli roolia, resurssia, tai aietta ei löydy, palauttaa aina false. Mikäli $role === Acl::ROLE_SUPER_ADMIN, palauttaa aina true.
Signature
public function can ( int $role, string $action, string $resource ) : bool
Esimerkit
$hasPermission = $acl->can(ACL::ROLE_AUTHOR, 'edit', 'posts');
makePermissions()
Luo arvoja setRules()-metodille tarjoiltavaa oliota varten.
Signature
public static function makePermissions ( array|string $allowedActions, stdClass $resourceActions ) : int
Esimerkit
$perms = ACL::makePermissions('*', ...);