PHPackages                             theroadbunch/bouncer - 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. theroadbunch/bouncer

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

theroadbunch/bouncer
====================

Bouncer is an easy-to-use allow/deny list interface.

v2.1(3y ago)36MITPHPPHP ^8.1

Since Jan 22Pushed 3y ago1 watchersCompare

[ Source](https://github.com/The-Road-Bunch/bouncer)[ Packagist](https://packagist.org/packages/theroadbunch/bouncer)[ RSS](/packages/theroadbunch-bouncer/feed)WikiDiscussions main Synced today

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

📋 Bouncer
=========

[](#-bouncer)

[![Latest Stable Version](https://camo.githubusercontent.com/44598eb9b2b875c4ba4c578d9fc0e9dbc1788b7cc4d090e4b4a9e2c17945b426/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746865726f616462756e63682f626f756e6365722e737667)](https://packagist.org/packages/theroadbunch/bouncer)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![Build Status](https://camo.githubusercontent.com/a2370173760f935c1c4904e9fdceffcf864306640612fb48611437256425f50d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5468652d526f61642d42756e63682f626f756e6365722f6261646765732f6275696c642e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/The-Road-Bunch/bouncer/build-status/main)

*What is Bouncer?*

Bouncer is an easy-to-use allow/deny list interface.

*Why the name Bouncer?*

In the real-world, a bouncer holds the list of who is allowed entry and who is not.

- AllowBouncer: At an exclusive club, the bouncer has a list and if you're not on it, you can't come in.
- DenyBouncer: The local bar allows almost everyone in, the bouncer has a list of trouble-makers to stop at the door.

### Contents

[](#contents)

1. [Installation](#install)
2. [Implementation](#Implementation)
    1. [Standard Usage](#standard-usage)
    2. [Real-World Use-Case](#example-of-a-real-world-use-case)
3. [Bouncers](#bouncers)
4. [Abstract Bouncer](#abstract-bouncer)
5. [License](LICENSE)

### Install using composer [\[?\]](https://getcomposer.org)

[](#install-using-composer-)

`composer require theroadbunch/bouncer`

### Implementation

[](#implementation)

#### Standard Usage

[](#standard-usage)

Use `Bouncer::allow()` or `Bouncer::deny()` to create your allow/deny lists (bouncer).

```
use RoadBunch\Bouncer\Bouncer;

$subjectList = ['example', 'one', 'two', 'three'];
$bouncer = Bouncer::allow($subjectList);
$bouncer->isAllowed('example'); // true

$bouncer = Bouncer::deny($subjectList);
$bouncer->isAllowed('example'); // false

// or
$subjectList = 'example;one;two;three';
$bouncer = Bouncer::allow($subjectList);
$bouncer->isAllowed('one'); // true
$bouncer->isAllowed('not in list'); // false

$bouncer = Bouncer::deny($subjectList);
$bouncer->isAllowed('two'); // false
$bouncer->isAllowed('not in list'); // true

// or
$subject = 'onlydomainiwanttosendemailto.com';
$bouncer = Bouncer::allow($subject);
$bouncer->isAllowed($subject); // true
$bouncer->isAllowed('example.com'); //false
```

Update the Bouncer in real time

```
use RoadBunch\Bouncer\Bouncer;

$subject = 'allowedAndThenDenied';

$bouncer = Bouncer::allow($subject);
$bouncer->isAllowed($subject); // true

$bouncer->deny($subject);
$bouncer->isAllowed($subject); // false
```

Using `BouncerFactory::create()`
*This has been deprecated and will be removed from the documentation in version **2.4***

```
use RoadBunch\Bouncer\Rule;
use RoadBunch\Bouncer\BouncerFactory;

$subjectList = ['example', 'one', 'two', 'three'];
$bouncer = BouncerFactory::create(Rule::ALLOW, $subjectList);
$bouncer->isAllowed('example'); // true
$bouncer->isAllowed('not in list'); // false
```

#### Example of a real-world use-case

[](#example-of-a-real-world-use-case)

```
