为您的 PHP 应用程序提供强大而高效的访问控制库。
MyCLabs ACL is a library that helps managing permissions on your model. It is different from other ACL libraries in that it focuses on controlling access to your model classes (Doctrine entities). As such, you access control model follows your real model, which makes it possible to have access in cascade easily (e.g. if you can access a category, you can also access all the sub-categories it contains).
It is also optimized as much as possible: authorizations are stored in database in a way to allow very efficient filtering at the SQL level through Doctrine queries (you can load only the objects a user can access). No other ACL system that we know of allows this.
Requirements:
Vocabulary:
There are 2 kinds of resources:
We hate being lost and confused, so everything you have to do with ACL is done on the ACL service. You can start by creating it:
// full configuration shown in the documentation
$acl = new ACL($entityManager);You give permissions to a user by adding it a role:
$acl->grant($user, new ArticleEditorRole($user, $article));Roles are classes that you write and which define the permissions a user has on a resource.
You remove permissions to a user by removing the role:
$acl->revoke($user, $role);Test permissions:
$acl->isAllowed($user, Actions::EDIT, $article);You can also filter your queries to get only the entities the user has access to:
$qb = $entityManager->createQueryBuilder();
$qb->select('article')->from('Model\Article', 'article');
ACLQueryHelper::joinACL($qb, $user, Actions::EDIT);
// This query will return only the articles the user can edit
$articles = $qb->getQuery()->getResult();isAllowed means one call to the database暂无开放 Issues,或尚未同步最近议题。