PHPackages                             bubobox/guard - 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. bubobox/guard

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

bubobox/guard
=============

Fine grained permission checking library built with REST resources in mind

0.1.0(10y ago)05MITPHPPHP ^5.4

Since Aug 8Pushed 10y ago4 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Guard [![Circle CI](https://camo.githubusercontent.com/afc1be01da53ddced394534dbdc3ebd8ef03580836815f232fd9a9d6452b5b76/68747470733a2f2f636972636c6563692e636f6d2f67682f6275626f626f782f67756172642f747265652f6d61737465722e7376673f7374796c653d736869656c64)](https://circleci.com/gh/bubobox/guard/tree/master)
=================================================================================================================================================================================================================================================================================================================

[](#guard-)

Fine grained permission checking library built with REST resources in mind.

Install
-------

[](#install)

```
composer require bubobox/guard

```

Developing
----------

[](#developing)

Unit test and code quality checks are all integrated into the composer `test` script, please run the following command before checking anything in, CircleCI will run the same tests to check your code.

```
composer test

```

Usage
-----

[](#usage)

There are two ways to use the library. Either with a `Guard` instance or by turning your own classes (e.g. the class you use for the currently active user) into locks by implementing the `LockInterface` on them.

### Guard

[](#guard)

A guard object can be used to setup and check rules on your resources.

A `Guard` option can be created by calling its constructor with the `new` keyword or using the class' static `make`method. Both approaches take one optional parameter. This optional parameter is the caller (generic name for user, apikey, ...) associated with this `Guard` instance. Callers must implement the `CallerInterface` interface. At this point in time, the caller is only used to pass to your [assertion methods](#assertions).

- `allow($action = '*', $resource = '*', $property = '*', callable $assertion = null)`
- `deny($action = '*', $resource = '*', $property = '*')`
- `can($action, $resource = null, $property = null)`

Allows cascade down, so calling `allow('read')` will tell the Guard that the `read` action is allowed on every resource and every property of those resources. The

Denies are only useful when you have already allowed something. Say you call `allow('read')` and afterwards `deny('read', 'foo')`. Now Guard will allow the `read` action on every resource except `foo`. They also cascade down, when you deny access to an action, it will effect all resources. Denies always supersede allows, once you deny something it does not matter if you allow it again afterwards.

You can add your own custom check by adding an assertion callable to the `allow` call. See [assertions](#assertions) for more information.

`can` will return true or false, based on the rules defined in the guard.

### Lock

[](#lock)

By adding the `LockTrait` to any class, it will be fully compliant with the `LockInterface`, you could write your own implmentation instead of using `LockTrait` but this should be pointless in most cases. By implementing `LockInterface` on your classes, they will expose the same three methods as the `Guard` explained above as well as one extra `setGuard` function. The `setGuard` function needs to be called once to supply your `LockInterface` instance with a `Guard` to use in the background, if you do not do this, a `NoGuardException` will be raised.

Complex resources
-----------------

[](#complex-resources)

Instead of using a string for the resource, your resource can also be an instance of a class that implements the `ResourceInterface` interface.

Assertions
----------

[](#assertions)

An assertion is a method that is called to add extra checks to the guard. It can be any `callable` and will be passed these parameters in order: `caller` (CallerInterface of null), `action` (string), `resource` (ResourceInterface, string or null) and `property` (string or null). Caller will be the CallerInterface associated with the `Guard` instance, while action, resource and property will be the values that were originally passed to the `can` method.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

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

3936d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/23435a2430f9c30343fc3a6c6cc14d5e537811e83d74887cb0891353d5fa081e?d=identicon)[Sitebase](/maintainers/Sitebase)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bubobox-guard/health.svg)

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

###  Alternatives

[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)[beatswitch/lock

A flexible, driver based Acl package for PHP 5.4+

870304.7k2](/packages/beatswitch-lock)[amocrm/amocrm-api-library

amoCRM API Client

182728.5k6](/packages/amocrm-amocrm-api-library)[vonage/jwt

A standalone package for creating JWTs for Vonage APIs

424.1M4](/packages/vonage-jwt)

PHPackages © 2026

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