Download the PHP package skibish/simple-rest-acl without Composer
On this page you can find all versions of the php package skibish/simple-rest-acl. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package simple-rest-acl
Simple REST ACL
Simplest ACL build, ever.
How to install
Run composer require skibish/simple-rest-acl
Idea and motivation
Configure ACL by routes and methods as simply as possible.
How to use it
First, you will need to create acl.yml
file. Which can look like this:
In your code you start ACL as follows:
And you are ready to go!
acl.yml file configuration
File has following possibilities:
Better way to understand thing is using examples.
Examples
Example #1
Assume, we have following configuration:
And we have request GET /photos/12
and available role is role1
. It will match, because default type
is resource
. If type
is resource
it will match following routes:
- /photos
- /photos/new
- /photos/{id}
- /photos/{id}/edit
- /photos/{id}
And in GET
we specified array of two roles role1
and role2
. Available role is role1
and it is in array. So, method verify()
in this case will return true
.
Example #2
Assume, we have following configuration:
Behind the scenes ACL uses nikic/FastRoute to match the routes. Thus you can use regex in route definition. But in this case don't forget to set type
to strict
.
In this case only routes that have digit after /strict
part will match. If we pass GET /strict/foo
, method verify()
will return false
. If GET /strict/42
- it will be true
.
Options
Third parameter in ACL
constructor is array of options. Currently there are two options:
cacheFile
- path to cache file. Example:__DIR__.'/cache/acl-cache.php'
. This configuration will cache your configuration. If you need to update cache, just delete the cache file.resourceRegex
- regex fortype
resource
. By default regex is[/{id:\d+|new}[/edit]]
. If you want it to match RESTful Resource Controllers, as example, overwrite this option with[/{id:\d+|create}[/edit]]
.
Code snippet:
Logging
If you need to log something from this library, you can use PSR-3
compatible loggers.
Missing roles
If you need to know, what roles are missing, use $acl->getMissingRoles()
. It will return array of missing roles.
Contribution
If you see, that something can be improved, feel free to submit a pull request.
All versions of simple-rest-acl with dependencies
symfony/yaml Version ^3.1
nikic/fast-route Version ^1.0
psr/log Version ^1.0