Download the PHP package arc/grants without Composer
On this page you can find all versions of the php package arc/grants. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package grants
Short Description Ariadne Component Library: user and group rights management Component
License MIT
Homepage https://github.com/Ariadne-CMS/arc/wiki
Informations about the package grants
arc/grants: access control management
A flexible component library for PHP
The Ariadne Component Library is a spinoff from the Ariadne Web Application Framework and Content Management System [ http://www.ariadne-cms.org/ ]
How it works
arc/grants is a simple and extensible system to manage access in a hierarchical system like a filesystem. At each node in the tree you can assign access grants for a specific user or group. There are no predefined grants, a grant can be any word. e.g.
This assigns the grant 'read' for the user 'public' on the path '/foo/'. This grant is automatically set for any path under '/foo/' as well. e.g:
You can assign multiple grants as a space-seperated string:
Grants for users do not stack. If you assign grants for a user somewhere, those will be the only grants available starting at that node. Previous grants are overwritten. If you want to revoke grants, simply set the grants again, without the grant you want revoked. To revoke all grants, set a 'marker' grant that is never checked, e.g:
The grants string is a simple DSL (Domain Specific Language) that allows you to set grants that do not 'trickle down' or to set grants that only apply on child nodes:
- '=read' only assigns the grant on this node. Child nodes won't have the read grant.
- '>delete' assigns the grant only on child nodes, not on the current node.
Default user and path
You can assign a default user for the grants system to use:
Then you can assign grants and check them, without specifying the user:
If you don't set a specific path with the cd() method, grants will be set and checked for the 'default' path. This is the path that is last set using \arc\grants::cd( $path ), e.g.:
This checks the grants for user 'admin' at '/foo/'. Any subsequent calls to \arc\grants assume this is the user and path you want to use. Untill you again call either cd() or switchUser() on the \arc\grants class (statically).
Groups
If a user is member of one or more groups, you can set it like this:
And check it like this:
Group grants are added to any user grants previously set. If you set user grants at a node, any group grants set at parent nodes are ignored. Only group grants under that node are added to the user grants.
If you override grants for a specific group, only the later group grants are applied, but only for that specific group.
Because mike has the 'edit' grant on '/', the group grants cannot remove it, so this works:
Because the group 'editors' grants with 'read add edit >delete' are set at the same node as Mike's personal grants, they are overruled by Mike's personal more restrictive grants, so this returns false:
Finally the group grants for 'editors' is overridden at '/foo/', so this also returns false:
Listing grants
This will return a list of all user grants at a specific node. It will only return the grants set at this specific node, not a list of all currently applicable grants:
Both will return an array with the user or group as the key and the grants string as the value or an empty string if no grants are set.
Todo
- add support for 'owner' group, need to have a link to an owner tree, otherwise grants tree gets too large