PHPackages                             phputil/flags - 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. [Framework](/categories/framework)
4. /
5. phputil/flags

ActiveLibrary[Framework](/categories/framework)

phputil/flags
=============

A lightweight, extensible feature flags framework for PHP

v0.6.1(1y ago)16012MITPHPPHP ^7.4 || ^8.0

Since May 10Pushed 1y ago1 watchersCompare

[ Source](https://github.com/thiagodp/phputil-flags)[ Packagist](https://packagist.org/packages/phputil/flags)[ RSS](/packages/phputil-flags/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (9)Used By (2)

phputil/flags
=============

[](#phputilflags)

[![Version](https://camo.githubusercontent.com/58e086b2e3ee3245ca80b5c7c1db91492c36dd76bfe778521c3afc91813c301d/68747470733a2f2f706f7365722e707567782e6f72672f7068707574696c2f666c6167732f763f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phputil/flags)[![Build](https://github.com/thiagodp/phputil-flags/actions/workflows/ci.yml/badge.svg?style=flat)](https://github.com/thiagodp/phputil-flags/actions/workflows/ci.yml/badge.svg?style=flat)[![License](https://camo.githubusercontent.com/18266cac504ec4cec666ee3101340a19d6e564529ad663cf3f2863245ee5919b/68747470733a2f2f706f7365722e707567782e6f72672f7068707574696c2f666c6167732f6c6963656e73653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phputil/flags)[![PHP](https://camo.githubusercontent.com/2fa2a952e5275abb1135b0ad24294aecdc8a3c8e7a90bf4fa61e7ec248b0be84/687474703a2f2f706f7365722e707567782e6f72672f7068707574696c2f666c6167732f726571756972652f706870)](https://packagist.org/packages/phputil/flags)

> 🚩 A lightweight, customizable [feature flags](https://en.wikipedia.org/wiki/Feature_toggle) framework for PHP

You can customize:

- 🧠 How flags are evaluated, through [Strategies](#strategies).
- 💾 How flags are stored, through [Storages](#storages).
- 📢 Who is notified about flag changes or removal, through [Listeners](#listeners).

Installation
------------

[](#installation)

> PHP 7.4 or later. No external dependencies.

```
composer require phputil/flags
```

👉 You may also like to install some of the official [extensions](#extensions).

Extensions
----------

[](#extensions)

Official extensions:

- [`phputil/flags-pdo`](https://github.com/thiagodp/phputil-flags-pdo) - a [PDO](https://www.php.net/manual/en/intro.pdo.php)-based [storage](#storages).
- ⏳ SOON - [`phputil/flags-firebase`](https://github.com/thiagodp/phputil-flags-firebase) - a [Firebase](https://firebase.google.com/)-based [storage](#storages).
- [`phputil/flags-webhooks`](https://github.com/thiagodp/phputil-flags-webhooks) a [listener](#listeners) that works like a webhook, by notifying external APIs about flags' changes.

Third-party extensions:

- Create yours and open an Issue to be evaluated. It may appear here.

Usage
-----

[](#usage)

Basic flag checking:

```
require_once 'vendor/autoload.php';
use phputil\flags\FlagManager;

// By default, it uses a storage-based strategy with an in-memory storage
$flag = new FlagManager();

if ( $flag->isEnabled( 'my-cool-feature' ) ) {
    echo 'Cool feature available!', PHP_EOL;
} else {
    echo 'Not-so-cool feature here', PHP_EOL;
}
```

Customizing a certain verification:

```
// ...
use phputil\flags\FlagVerificationStrategy;

$flag = new FlagManager();

$myLuckBasedStrategy = new class implements FlagVerificationStrategy {
    function isEnabled( string $flag ): bool {
        return rand( 1, 100 ) >= 50; // 50% chance
    }
};

if ( $flag->isEnabled( 'my-cool-feature', [ $myLuckBasedStrategy ] ) ) {
    echo 'Cool feature available!', PHP_EOL;
} else {
    echo 'Not-so-cool feature here', PHP_EOL;
}
```

Customizing all the verifications:

```
$flag = new FlagManager( null, [ $myLuckBasedStrategy ] );

if ( $flag->isEnabled( 'my-cool-feature' ) ) {
    ...
```

Setting a flag:

```
$flag->enable( 'my-cool-feature' );
$flag->disable( 'my-cool-feature' );
$flag->setEnable( 'my-cool-feature', true /* or false */ );
```

Removing a flag:

```
$flag->remove( 'my-cool-feature' );
```

Retrieving flag data:

```
$flagData = $flag->getStorage()->get( 'my-cool-feature' ); // null if not found
```

Adding a listener:

```
// ...
use phputil\flags\FlagListener;
use phputil\flags\FlagData;

$myListener = new class implements FlagListener {
  public function notify( string $event, FlagData $flagData ): void {
    if ( $event === 'change' ) {
        echo 'Flag ', $flagData->key, ' is now ', $flagData->enabled ? 'enabled': 'disabled', PHP_EOL;
    } else if ( $event === 'removal' ) {
        echo 'Flag ', $flagData->key, ' was removed.', PHP_EOL;
    }
  }
};

$flag->addListener( $myListener ); // v0.5.0+
// or $flag->getListeners()->add( $myListener );

$flag->enable( 'my-cool-feature' ); // Notify the listener
```

Customization
-------------

[](#customization)

### Storages

[](#storages)

Use a different flag storage by:

- Creating your own, extending [`FlagStorage`](/src/FlagStorage.php); OR
- Using an external [storage extension](#extensions).

How to configure it:

```
$storage = /* Create your storage here, e.g. new InMemoryStorage() */;
$flag = new FlagManager( $storage );
```

Storages available in the framework:

- [`InMemoryStorage`](src/storages/InMemoryStorage.php), that store flags in memory.

### Strategies

[](#strategies)

Use a flag verification strategy by:

- Creating your own, extending [`FlagVerificationStrategy`](/src/FlagVerificationStrategy.php); OR
- Using an external [strategy extension](#extensions).

How to configure it globally:

```
$strategies = [ /* pass your strategies here   */ ];
$flag = new FlagManager( null, $strategies );
```

Strategies available in the framework:

- [`StorageBasedVerificationStrategy`](src/strategies/StorageBasedVerificationStrategy.php), that checks flags in a storage.
- [`EnvBasedVerificationStrategy`](src/strategies/EnvBasedVerificationStrategy.php), that checks flags based on environment variables.

👉 A flag is considered enabled when **all** the strategies considered it enabled.

### Listeners

[](#listeners)

Define a listener by:

- Creating your own, extending [`FlagListener`](/src/FlagListener.php); OR
- Using an external [listener extension](#extensions).

How to configure it:

```
$flag->addListener( $myListener ); // v0.5.0+
// or $flag->getListeners()->add( $myListener );
```

Roadmap
-------

[](#roadmap)

- Extensible library
- Official extensions:
    - PDO-based storage
    - Firebase-based storage
    - Webhook-like listener
- REST API (external repository)
- Web-based control panel (external repository)

License
-------

[](#license)

[MIT](/LICENSE) © [Thiago Delgado Pinto](https://github.com/thiagodp)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity41

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

Recently: every ~45 days

Total

8

Last Release

555d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/154324d722a6ee9c252a0338329781084a97af2d0ea9faaf39176df5a689a2ec?d=identicon)[thiagodp](/maintainers/thiagodp)

---

Top Contributors

[![thiagodp](https://avatars.githubusercontent.com/u/2997844?v=4)](https://github.com/thiagodp "thiagodp (23 commits)")

---

Tags

featureflagframeworklibraryphptogglephpframeworklibraryfeatureflagtoggle

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phputil-flags/health.svg)

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

###  Alternatives

[digitalstars/simplevk

Powerful PHP library/framework for VK API bots, supporting LongPoll &amp; Callback &amp; OAuth

883.9k3](/packages/digitalstars-simplevk)[marwanalsoltany/mighty

The last validation library you will ever need!

591.3k](/packages/marwanalsoltany-mighty)[ollyxar/websockets

PHP WebSocket server

311.9k1](/packages/ollyxar-websockets)

PHPackages © 2026

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