PHPackages                             flightphp/permissions - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. flightphp/permissions

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

flightphp/permissions
=====================

Library for managing permissions in Flight Applications

v0.2.0(4mo ago)7860↓50%MITPHPPHP &gt;=7.4

Since Jun 4Pushed 4mo ago3 watchersCompare

[ Source](https://github.com/flightphp/permissions)[ Packagist](https://packagist.org/packages/flightphp/permissions)[ Docs](https://docs.flightphp.com)[ RSS](/packages/flightphp-permissions/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

Flight Permissions Plugin
=========================

[](#flight-permissions-plugin)

[![Latest Stable Version](https://camo.githubusercontent.com/a6ed1ea7a22af6bb6dd4ea0da5f19a03d50b49e10e8b4e7e7fff1eb94f38fc0d/68747470733a2f2f706f7365722e707567782e6f72672f666c696768747068702f7065726d697373696f6e732f76)](https://packagist.org/packages/flightphp/permissions)[![License](https://camo.githubusercontent.com/d7c7538921a1650b5618f72c71167a5a508f66e61c3981c37d9db2f828f3c334/68747470733a2f2f706f7365722e707567782e6f72672f666c696768747068702f7065726d697373696f6e732f6c6963656e7365)](https://packagist.org/packages/flightphp/permissions)[![PHP Version Require](https://camo.githubusercontent.com/00cca23ca19b4f3b20101e89f2a759f684938a5e3e0da62fa2fa95df18a80d1f/68747470733a2f2f706f7365722e707567782e6f72672f666c696768747068702f7065726d697373696f6e732f726571756972652f706870)](https://packagist.org/packages/flightphp/permissions)[![Dependencies](https://camo.githubusercontent.com/e7fcd4471405f0bde2305b4b3fa737a2e522e349a6d25653ee292a312f1517ed/68747470733a2f2f706f7365722e707567782e6f72672f666c696768747068702f7065726d697373696f6e732f646570656e64656e7473)](https://packagist.org/packages/flightphp/permissions)

Permissions are an important part to any application. Even in a RESTful API you'll need to check that the API key has permission to perform the action requested. In some cases it makes sense to handle authentication in a middleware, but in other cases, it's more helpful to have a standard set of permissions.

This library follows a CRUD based permissions systems. See [basic example](#basic-example) for example on how this is accomplished.

Basic Example
-------------

[](#basic-example)

Let's assume you have a feature in your application that checks if a user is logged in. You can create a permissions object like this:

```
// index.php
require 'vendor/autoload.php';

// some code

// then you probably have something that tells you who the current role is of the person
// likely you have something where you pull the current role
// from a session variable which defines this
// after someone logs in, otherwise they will have a 'guest' or 'public' role.
$current_role = 'admin';

// setup permissions
$permission = new \flight\Permission($current_role);
$permission->defineRule('loggedIn', function($current_role) {
	return $current_role !== 'guest';
});

// You'll probably want to persist this object in Flight somewhere
Flight::set('permission', $permission);
```

Then in a controller somewhere, you might have something like this.

```
