PHPackages                             codevia/permission-middleware - 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. codevia/permission-middleware

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

codevia/permission-middleware
=============================

PHP permission middleware for Slim 4

v1.0.2(3y ago)011MITPHP

Since May 18Pushed 3y agoCompare

[ Source](https://github.com/codevia-io/permission-middleware)[ Packagist](https://packagist.org/packages/codevia/permission-middleware)[ RSS](/packages/codevia-permission-middleware/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

permission-middleware
=====================

[](#permission-middleware)

PHP permission middleware for Slim 4. Requires PHP &gt;= 8.0.

When defining your routes, you may want to verify if the visitor is permitted to access each resource. But don't want to waste time writing unmaintainable per controller method guards. Then, this permission middleware has been written for you.

Usage
=====

[](#usage)

Your permission list must be a class extending `PermissionList`. Each permission level must be a bitwise number constant (1, 2, 4, 8...).

```
// src/Permission.php
namespace App;

use Codevia\PermissionMiddleware\PermissionList;

class Permission extends PermissionList
{
    public const GUEST = 1;
    public const USER = 2;
    public const ADMIN = 4;
}
```

You may store your visitor permission level in a session like so:

```
use App\Permission;
use Codevia\PermissionMiddleware\PermissionMiddleware;

$_SESSION[PermissionMiddleware::SESSION_PERMISSION] = Permission::USER;
```

When you add the permission middleware to your Slim app, you must give it your permission list with the default value (in case it is not included in `$_SESSION`).

```
// public/index.php
require_once __DIR__ . '../bootstrap.php';

use App\Permission;
use Codevia\PermissionMiddleware\PermissionMiddleware;
use Slim\Factory\AppFactory;

$app = AppFactory::create();
$app->addMiddleware(new PermissionMiddleware(
    new Permission(Permission::GUEST) // Permission::GUEST is your default
));
```

Now you can set the permission level on each route you define. The unique way to do so is using the array [container resolution](https://www.slimframework.com/docs/v4/objects/routing.html#container-resolution). That means your app must implement controllers and methods.

```
use App\Permission as P;

$app->get('/test', [TestController::class, 'testMethod', P::USER | P::ADMIN]);
$app->get('/public', [TestController::class, 'publicMethod', P::GUEST]);
```

If the visitor permission is rejected, a `Slim\Exception\HttpForbiddenException`is thrown.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Total

3

Last Release

1417d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1c4efd468a664adacdd012e710159c45e79a910fdcd8b5555d77af2ef1a9defe?d=identicon)[d9beuD](/maintainers/d9beuD)

---

Top Contributors

[![d9beuD](https://avatars.githubusercontent.com/u/53569029?v=4)](https://github.com/d9beuD "d9beuD (9 commits)")

### Embed Badge

![Health badge](/badges/codevia-permission-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/codevia-permission-middleware/health.svg)](https://phpackages.com/packages/codevia-permission-middleware)
```

###  Alternatives

[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)[havenshen/slim-born

Slim Framework 3 skeleton application has authentication.

1941.7k](/packages/havenshen-slim-born)[egroupware/openid

EGroupware OpenID Connect / OAuth2 server

1226.8k2](/packages/egroupware-openid)[madesimple/slim-auth

Authentication and authorisation middleware for Slim framework

179.6k](/packages/madesimple-slim-auth)[lucatacconi/crunz-ui

User interface for lavary/crunz. Integrate Crunz library and funtions: Tabular, monthly or weekly interface to view the scheduled and executed tasks. Quick display of the execution result of the tasks that have been executed (Indicator icons easily show the result). Upload, download, edit or delete tasks. Forced run of the task, even outside the scheduled time with eventual display of the log once the execution is completed. It can be used with integrated Crunz or with a version of Crunz already installed on the system

151.5k](/packages/lucatacconi-crunz-ui)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
