Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rodzyk/permission
Simple PHP library for Permission Validation
https://github.com/rodzyk/permission
permission permission-validation permission-validator validation validator
Last synced: 4 days ago
JSON representation
Simple PHP library for Permission Validation
- Host: GitHub
- URL: https://github.com/rodzyk/permission
- Owner: rodzyk
- Created: 2020-02-18T09:50:27.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-18T15:13:16.000Z (almost 5 years ago)
- Last Synced: 2024-05-17T16:49:13.776Z (8 months ago)
- Topics: permission, permission-validation, permission-validator, validation, validator
- Language: PHP
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Raisins Permission Validation
Simple PHP library for Permission Validation
## Composer Installation
1. Get [Composer](http://getcomposer.org/)
2. Require Raisins Validation with `composer require raisins/permission`
3. Add the following to your application's main PHP file: `require 'vendor/autoload.php';`## Usage
```php
use\Raisins\{PermissionValidation, Permission};$pv = new PermissionValidation();
// set required permissions
$pv->required = [
new Permission("read", -1),
new Permission("edit"),
new Permission("delete", 1)
];// set available permission
$pv->available = [
new Permission("read"),
new Permission("edit"),
new Permission("delete", -1)
];$result = $pv->validate();
echo $result; // false
// merge overridden permissions (option)
$pv->merge([
new Permission("delete", 1)
]);$result = $pv->validate();
echo $result; // true
```## Set by JSON
```php
$pv = new PermissionValidation();$permissionsJson = '[{"name": "read", "state": -1}, {"name": "edit", "state": 0}, {"name": "delete", "state": 1}]';
$pv->setAvailable($permissionsJson);
$pv->setRequired($permissionsJson);// ...
```