PHPackages                             lanlin/god - 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. lanlin/god

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

lanlin/god
==========

An authority proving system that supports ACL, RBAC, ABAC

2.0.0(6y ago)523MITPHPPHP &gt;=7.2

Since Jun 25Pushed 6y ago3 watchersCompare

[ Source](https://github.com/lanlin/god)[ Packagist](https://packagist.org/packages/lanlin/god)[ Docs](https://github.com/lanlin/god)[ RSS](/packages/lanlin-god/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (6)Dependencies (3)Versions (7)Used By (0)

God Permission System
---------------------

[](#god-permission-system)

"God said, Let there be light, and there was light."

"God will decide if you have permission."

"God bless you!"

Install
-------

[](#install)

```
composer require lanlin/god
```

The Origin
----------

[](#the-origin)

God is written after referring to the Casbin(golang) project, thanks for their hard work.

For more detail, please refer to the documentation of [Casbin](https://github.com/casbin/casbin).

Supported models
----------------

[](#supported-models)

1. [**ACL (Access Control List)**](https://en.wikipedia.org/wiki/Access_control_list)
2. **ACL with [superuser](https://en.wikipedia.org/wiki/Superuser)**
3. **ACL without users**: especially useful for systems that don't have authentication or user log-ins.
4. **ACL without resources**: some scenarios may target for a type of resources instead of an individual resource by using permissions like `write-article`, `read-log`. It doesn't control the access to a specific article or log.
5. **[RBAC (Role-Based Access Control)](https://en.wikipedia.org/wiki/Role-based_access_control)**
6. **RBAC with resource roles**: both users and resources can have roles (or groups) at the same time.
7. **RBAC with domains/tenants**: users can have different role sets for different domains/tenants.
8. **[ABAC (Attribute-Based Access Control)](https://en.wikipedia.org/wiki/Attribute-Based_Access_Control)**: syntax sugar like `resource.Owner` can be used to get the attribute for a resource.
9. **[RESTful](https://en.wikipedia.org/wiki/Representational_state_transfer)**: supports paths like `/res/*`, `/res/:id` and HTTP methods like `GET`, `POST`, `PUT`, `DELETE`.
10. **Deny-override**: both allow and deny authorizations are supported, deny overrides the allow.
11. **Priority**: the policy rules can be prioritized like firewall rules.

Supported Adapters
------------------

[](#supported-adapters)

1. file adapter
2. MongoDB adapter
3. PHP PDO adapters (now support: MySQL, PostgreSQL, SQLite, SqlServer.)

How it works?
-------------

[](#how-it-works)

does "Who" as "Role" or "Group" from "Where" do "Operator" to "What" will got "How"?

IdentifierDescriptionrRequest (r = sub, obj, act)pPolicy (p = sub, obj, act, eft)gGroup or Role (g = \_, \_)ePolicy Efftect (e = some(where (p.eft == allow)))mMatchers (m = r.obj == p.obj)subSubject (Who)domDomain (Where)objObject (What)actAction (Operator)eftEfftect (How) (allow, deny, indeterminate)An access control model is abstracted into a CONF file based on the **PERM metamodel (Policy, Effect, Request, Matchers)**.

So switching or upgrading the authorization mechanism for a project is just as simple as modifying a configuration.

You can customize your own access control model by combining the available models.

For example, you can get RBAC roles and ABAC attributes together inside one model and share one set of policy rules.

The most basic and simplest model in God is ACL. ACL's model CONF is:

```
# Request definition
[request_definition]
r = sub, obj, act

# Policy definition
[policy_definition]
p = sub, obj, act

# Policy effect
[policy_effect]
e = some(where (p.eft == allow))

# Matchers
[matchers]
m = r.sub == p.sub && r.obj == p.obj && r.act == p.act
```

An example policy for ACL model is like:

```
p, alice, data1, read
p, bob, data2, write

```

It means:

- alice can read data1
- bob can write data2

Demo
----

[](#demo)

```
use God\God;

$God = new God('path/to/model.conf', 'path/to/policy.csv');

$God->allows('you', 'evil book', 'read');  // Does God allows you to do this?

new God();

new God(string $modelPath);

new God(string $modelPath, string $policyFile);

new God(string $modelPath, Adapter $adapter);

new God(Model $model);

new God(Model $model, Adapter $adapter);

// demo for mysql
$dbHost   = "127.0.0.1";
$dbPort   = 3306;
$dbName   = "your_database_name";
$username = "root";
$password = "your_password";

// php mysql pdo demo
$pdo = new \PDO("mysql:host={$dbHost};port={$dbPort};dbname={$dbName}", $username, $password);

// init god model with csv
$g = new God('tests/Examples/rbac_model.conf', 'tests/Examples/rbac_policy.csv');
$m = $g->getModel();

// save policy to database
$a = new Adapter($pdo);
$a->savePolicy($m);
```

For more usage demos, please view the unit tests or

[Casbin 中文文档](https://casbin.org/docs/zh-CN/overview)

[Casbin Documents](https://casbin.org/docs/en/overview)

License
-------

[](#license)

This project is licensed under the MIT license.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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 ~80 days

Recently: every ~100 days

Total

6

Last Release

2473d ago

Major Versions

1.0.4 → 2.0.02019-08-01

PHP version history (2 changes)1.0.0PHP &gt;=7.0

1.0.2PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/81188f0c83f3b0af04324b15cea141930fdb84ccc72af777b5351ddd0b1fe746?d=identicon)[lanlin](/maintainers/lanlin)

---

Top Contributors

[![lanlin](https://avatars.githubusercontent.com/u/3468024?v=4)](https://github.com/lanlin "lanlin (38 commits)")

---

Tags

abacaclpermissionphprbacrestfulphpauthorizationaclpermissionrbacrestfulabac

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lanlin-god/health.svg)

```
[![Health](https://phpackages.com/badges/lanlin-god/health.svg)](https://phpackages.com/packages/lanlin-god)
```

###  Alternatives

[casbin/casbin

a powerful and efficient open-source access control library for php projects.

1.3k1.4M54](/packages/casbin-casbin)[santigarcor/laratrust

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

2.3k5.4M42](/packages/santigarcor-laratrust)[casbin/laravel-authz

An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.

324339.9k4](/packages/casbin-laravel-authz)[casbin/think-authz

An authorization library that supports access control models like ACL, RBAC, ABAC for ThinkPHP.

27918.5k6](/packages/casbin-think-authz)[casbin/webman-permission

webman casbin permission plugin

523.4k2](/packages/casbin-webman-permission)[casbin/codeigniter-permission

Associate users with roles and permissions, use Casbin in CodeIgniter4 Web Framework.

443.0k](/packages/casbin-codeigniter-permission)

PHPackages © 2026

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