PHPackages                             tihloh/prefab-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. tihloh/prefab-permissions

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

tihloh/prefab-permissions
=========================

Standalone, framework-independent permissions with group inheritance and user overrides for Prefab PHP.

v0.1.0(yesterday)01↑2900%MITPHPPHP &gt;=8.1

Since Aug 23Pushed yesterdayCompare

[ Source](https://github.com/tihloh/prefab-permissions)[ Packagist](https://packagist.org/packages/tihloh/prefab-permissions)[ Docs](https://github.com/tihloh/prefab-php)[ RSS](/packages/tihloh-prefab-permissions/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

Tihloh Prefab Permissions
=========================

[](#tihloh-prefab-permissions)

Framework-independent permissions and authorization for PHP, with optional framework integration.

Prefab Permissions is standalone. It does not require Prefab Database, Users, Auth, Logs, Laravel, or another framework package.

Permission definitions
----------------------

[](#permission-definitions)

Definitions may come from an inline PHP array, a PHP template file, or a JSON template file.

```
$permissions = new PermissionManager([
    'definitions' => __DIR__ . '/config/permissions.php',
]);
```

Equivalent JSON is also supported:

```
$permissions = new PermissionManager([
    'definitions' => __DIR__ . '/config/permissions.json',
]);
```

A definition may include a stable permission ID, human-friendly name, description, and default value.

Standalone storage
------------------

[](#standalone-storage)

A custom `PermissionStoreInterface` can be supplied directly:

```
$permissions = new PermissionManager(
    definitions: $definitions,
    store: $customStore,
);
```

The built-in database store accepts either plain PDO or Prefab's `DatabaseInterface`:

```
$permissions = new PermissionManager(
    $definitions,
    new PdoPermissionStore($pdo),
);
```

The historical `PdoPermissionStore` class name is retained for compatibility, but it now consumes `DatabaseInterface` internally. PDO is automatically wrapped by `PdoDatabaseAdapter`.

Automatic database configuration
--------------------------------

[](#automatic-database-configuration)

The normal quick form is:

```
PrefabConfig::set([
    'database' => $mainPdo,

    'modules' => [
        'permissions' => [
            'definitions' => __DIR__ . '/config/permissions.php',
        ],
    ],
]);

$permissions = new PermissionManager();
```

Or use a named Prefab Database connection:

```
PrefabConfig::set([
    'modules' => [
        'permissions' => [
            'connection' => 'security',
        ],
    ],
]);
```

Resolution remains:

```
1. direct Permissions store / database / connection
2. Permissions-specific PrefabConfig
3. common PrefabConfig
4. compatible database capability
5. clear error when database-backed storage is still unresolved

```

Permission inheritance
----------------------

[](#permission-inheritance)

Effective permission resolution is:

```
User override
    ↓
Group permission
    ↓
Permission definition default

```

A missing user override means inherit. Clearing an override restores group/default resolution.

```
$permissions->set(
    'user',
    $userId,
    'documents.approve',
    true,
);

$permissions->clear(
    'user',
    $userId,
    'documents.approve',
);
```

Subject integration
-------------------

[](#subject-integration)

Projects keep their own user/group models. A user only needs to implement `PermissionSubjectInterface` when object-based resolution is desired:

```
class User implements PermissionSubjectInterface
{
    public function __construct(
        public int $id,
        public array $groupIds = [],
    ) {
    }

    public function permissionSubjectId(): int|string
    {
        return $this->id;
    }

    public function permissionGroupIds(): array
    {
        return $this->groupIds;
    }
}
```

Then:

```
if ($permissions->can($user, 'documents.approve')) {
    // Allowed.
}
```

Laravel compatibility
---------------------

[](#laravel-compatibility)

Laravel's own user model and Auth/Gate system do not need to be replaced. A Laravel adapter/bridge can expose the required Prefab contracts while Laravel remains the host framework.

The same principle applies to other frameworks: Prefab consumes contracts/capabilities rather than requiring its own full application stack.

Database abstraction
--------------------

[](#database-abstraction)

Built-in storage uses:

```
PDO or framework database
        ↓
DatabaseInterface
        ↓
PdoPermissionStore

```

The remaining database-specific DDL/upsert differences are isolated inside the built-in store for MySQL/MariaDB, PostgreSQL, SQLite, and SQL Server. A future optional schema abstraction can centralize those differences without enlarging the minimal shared database contract prematurely.

Logging and diagnostics
-----------------------

[](#logging-and-diagnostics)

When Prefab Logs exists, permission changes are emitted automatically. Human-friendly logs can use permission definition names, for example:

```
Demo Admin denied View Documents for Test User.

```

Use:

```
$permissions->explain();
```

to inspect how definitions, storage, table, and database resources were resolved.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

1d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ec00222b22ba37eb69aff9973c5303fe5773cb4c7016bf0e7aae09fe9edb232?d=identicon)[tihloh](/maintainers/tihloh)

---

Top Contributors

[![tihloh](https://avatars.githubusercontent.com/u/8960509?v=4)](https://github.com/tihloh "tihloh (47 commits)")

---

Tags

phpauthorizationaclpermissionsrbacmodularprefabframework-independent

### Embed Badge

![Health badge](/badges/tihloh-prefab-permissions/health.svg)

```
[![Health](https://phpackages.com/badges/tihloh-prefab-permissions/health.svg)](https://phpackages.com/packages/tihloh-prefab-permissions)
```

###  Alternatives

[santigarcor/laratrust

This package provides a flexible way to add Role-based Permissions to Laravel

2.3k5.9M47](/packages/santigarcor-laratrust)[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6796.8k7](/packages/hasinhayder-tyro)[shanmuga/laravel-entrust

This package provides a flexible solution to add ACL to Laravel

68346.9k2](/packages/shanmuga-laravel-entrust)

PHPackages © 2026

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