PHPackages                             byjg/featureflag - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. byjg/featureflag

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

byjg/featureflag
================

Allows you to enable or disable features in your application and dispatch the proper code based on the flags.

6.0.0(5mo ago)00PHPPHP &gt;=8.3 &lt;8.6CI passing

Since Nov 22Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/byjg/php-featureflag)[ Packagist](https://packagist.org/packages/byjg/featureflag)[ GitHub Sponsors](https://github.com/byjg)[ RSS](/packages/byjg-featureflag/feed)WikiDiscussions master Synced 1mo ago

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

   sidebar\_key featureflag   tags    php

    FeatureFlag Dispatcher
======================

[](#featureflag-dispatcher)

A simple feature flag dispatcher that allows conditional code execution based on enabled feature flags.

[![Sponsor](https://camo.githubusercontent.com/fab14b7f7f475072ada0473f193d6f322561fd4a2958e0cc89910d053347cf27/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53706f6e736f722d2532336561346161613f6c6f676f3d67697468756273706f6e736f7273266c6f676f436f6c6f723d7768697465266c6162656c436f6c6f723d306431313137)](https://github.com/sponsors/byjg)[![Build Status](https://github.com/byjg/uri/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/byjg/php-featureflag/actions/workflows/phpunit.yml)[![Opensource ByJG](https://camo.githubusercontent.com/425c1bbccc0f292bf4d20569ae74a6b2e384fd648f1af8911bc61de9a8dcfc0b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6f70656e736f757263652d62796a672d737563636573732e737667)](https://opensource.byjg.com)[![GitHub source](https://camo.githubusercontent.com/88e61eb211719144efdd570290a0456b6e13099c2df8d973f1bb43fe33bf0039/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4769746875622d736f757263652d696e666f726d6174696f6e616c3f6c6f676f3d676974687562)](https://github.com/byjg/php-featureflag/)[![GitHub license](https://camo.githubusercontent.com/f67d6c6319db9287d2a8c31405b8b2bfd62e7e6660b6753a60db54f097e09655/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f62796a672f7068702d66656174757265666c61672e737667)](https://opensource.byjg.com/opensource/licensing.html)[![GitHub release](https://camo.githubusercontent.com/cf98b52e365dc7a81058d9f76b5b6763e753d1206d67e3a1a65d6f6df40326c0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f62796a672f7068702d66656174757265666c61672e737667)](https://github.com/byjg/php-featureflag/releases/)

Feature flags are a powerful technique for managing features in your application, enabling you to toggle functionality on/off without deploying new code. This library provides a clean, interface-based approach to dispatch handlers based on feature flag states.

Basic Usage
-----------

[](#basic-usage)

```
use ByJG\FeatureFlag\FeatureFlags;
use ByJG\FeatureFlag\FeatureFlagDispatcher;
use ByJG\FeatureFlag\FeatureFlagSelector;
use ByJG\FeatureFlag\FeatureFlagHandlerInterface;

// Initialize the enabled features
FeatureFlags::addFlag('flag1', 'value1');
FeatureFlags::addFlag('flag2', 'value2');
FeatureFlags::addFlag('flag3');

// Create handler implementations
class MyHandler implements FeatureFlagHandlerInterface
{
    public function execute(mixed ...$args): mixed
    {
        echo "Handler executed!\n";
        return null;
    }
}

// Create a Dispatcher
$dispatcher = new FeatureFlagDispatcher();

// Add feature flag handlers
$dispatcher->add(FeatureFlagSelector::whenFlagIs('flag2', 'value1', new MyHandler()));
$dispatcher->add(FeatureFlagSelector::whenFlagIs('flag2', 'value2', new MyHandler()));

// Dispatch the request
$dispatcher->dispatch();

// Since there is a feature flag 'flag2' with value 'value2', the corresponding handler will be executed
```

:::note If one or more feature flags match the condition, **all matching handlers will be executed** in the order they were added. :::

Handler Types
-------------

[](#handler-types)

- [Handler Interface](docs/handler-interface.md) - Create custom handlers implementing `FeatureFlagHandlerInterface`
- [Attributes](docs/attribute-dispatchers.md) - Use PHP 8 attributes to mark methods as handlers

Selector Types
--------------

[](#selector-types)

- [FeatureFlagSelector](docs/featureflag-selector.md) - Single condition selectors
- [FeatureFlagSelectorSet](docs/featureflag-selectorset.md) - Multiple condition selectors (ALL must match)

Advanced Usage
--------------

[](#advanced-usage)

- [Search Order](docs/search-order.md) - Control the order of handler execution
- [Passing Arguments](docs/passing-arguments.md) - Pass runtime arguments to handlers

Install
-------

[](#install)

```
composer require "byjg/featureflag"
```

Requirements
------------

[](#requirements)

- PHP 8.3 to 8.5
- PSR-11 Container (optional, for container integration)

Unit tests
----------

[](#unit-tests)

```
composer test
```

Dependencies
------------

[](#dependencies)

 ```
flowchart TD
    byjg/featureflag --> php8.3-8.5
    byjg/featureflag --> psr/container
```

      Loading ---

[Open source ByJG](https://opensource.byjg.com)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance79

Regular maintenance activity

Popularity0

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.6% 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 ~4 days

Total

2

Last Release

173d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/981924?v=4)[Joao Gilberto Magalhaes](/maintainers/byjg)[@byjg](https://github.com/byjg)

---

Top Contributors

[![byjg](https://avatars.githubusercontent.com/u/981924?v=4)](https://github.com/byjg "byjg (19 commits)")[![claude](https://avatars.githubusercontent.com/u/81847?v=4)](https://github.com/claude "claude (4 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/byjg-featureflag/health.svg)

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

###  Alternatives

[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k431.1M7.5k](/packages/symfony-dependency-injection)[illuminate/contracts

The Illuminate Contracts package.

704122.9M10.1k](/packages/illuminate-contracts)[illuminate/container

The Illuminate Container package.

31278.1M2.0k](/packages/illuminate-container)[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[internal/dload

Downloads binaries.

98142.7k10](/packages/internal-dload)

PHPackages © 2026

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