PHPackages                             digital-gravy/feature-flag - 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. digital-gravy/feature-flag

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

digital-gravy/feature-flag
==========================

Feature Flag for WordPress

v1.0.10(1y ago)04.7k↓31.1%GPL-3.0-or-laterPHPPHP ^7.4|^8.0CI passing

Since Dec 16Pushed 1y ago2 watchersCompare

[ Source](https://github.com/Digital-Gravy/feature-flag)[ Packagist](https://packagist.org/packages/digital-gravy/feature-flag)[ Docs](https://github.com/Digital-Gravy/feature-flag)[ RSS](/packages/digital-gravy-feature-flag/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (12)Used By (0)

PHP Feature Flag Manager
========================

[](#php-feature-flag-manager)

[![Build Status](https://github.com/Digital-Gravy/feature-flag/actions/workflows/ci.yml/badge.svg)](https://github.com/digitalgravy/feature-flag/actions/workflows/ci.yml)[![Latest Stable Version](https://camo.githubusercontent.com/79cac0ed4134d27eb88d63c331011191bed90a4242f033d16889cdc40ba98833/68747470733a2f2f706f7365722e707567782e6f72672f6469676974616c2d67726176792f666561747572652d666c61672f76)](https://packagist.org/packages/digital-gravy/feature-flag)[![License](https://camo.githubusercontent.com/03cf5e37f7bef3948890668c73262599ea2780144772bd7590f73d7ff0d4ae86/68747470733a2f2f706f7365722e707567782e6f72672f6469676974616c2d67726176792f666561747572652d666c61672f6c6963656e7365)](https://packagist.org/packages/digital-gravy/feature-flag)

A flexible PHP library for managing feature flags with multiple storage backends.

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

[](#installation)

You can install the library via Composer:

```
composer require digital-gravy/feature-flag
```

Features
--------

[](#features)

- Simple on/off feature flag management
- Multiple storage backends:
    - JSON file
    - PHP Constants
    - Array-based storage
- Type-safe implementation
- Extensible storage interface
- Exception handling for invalid flags

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use DigitalGravy\FeatureFlag\FeatureFlagStore;
use DigitalGravy\FeatureFlag\Storage\KeyedArray;

// Create a feature flag store with array storage
$flags = new KeyedArray([
    'dark_mode' => 'on',
    'beta_feature' => 'off'
]);

$store = new FeatureFlagStore($flags->get_flags());

// Check if a feature is enabled
if ($store->is_on('dark_mode')) {
    // Dark mode is enabled
}
```

### JSON File Storage

[](#json-file-storage)

```
use DigitalGravy\FeatureFlag\Storage\JsonFile;

$flags = new JsonFile('/path/to/flags.json');
$store = new FeatureFlagStore($flags->get_flags());
```

Example flags.json:

```
{
  "dark_mode": "on",
  "beta_feature": "off"
}
```

### PHP Constants Storage

[](#php-constants-storage)

```
use DigitalGravy\FeatureFlag\Storage\PHPConstant;

define('DARK_MODE', true);
define('BETA_FEATURE', 'off');

$flags = new PHPConstant(['DARK_MODE', 'BETA_FEATURE']);
$store = new FeatureFlagStore($flags->get_flags());
```

### Multiple Sources

[](#multiple-sources)

The `FeatureFlagStore` constructor accepts an array of flags from different storage backends. When multiple sources are provided, the flags are merged together, and the last source overrides the previous ones.

```
$store = new FeatureFlagStore(
    $jsonFlags->get_flags(),
    $constantFlags->get_flags(),
    $arrayFlags->get_flags()
);
```

### Flag Rules

[](#flag-rules)

- Flag keys must contain only alphanumeric characters, underscores, and dashes
- Flag values must be either 'on' or 'off'
- Flag keys are case-insensitive and stored in lowercase

### Custom Storage Backend

[](#custom-storage-backend)

You can implement your own storage backend by implementing the FlagStorageInterface:

```
use DigitalGravy\FeatureFlag\Storage\FlagStorageInterface;

class CustomStorage implements FlagStorageInterface {
    public function get_flags(): array {
        // Return array of FeatureFlag objects
    }
}
```

### Error Handling

[](#error-handling)

The library includes several exception types:

- `Invalid_Flag_Key`: Thrown when a flag key contains invalid characters
- `Invalid_Flag_Value`: Thrown when a flag value is not 'on' or 'off'
- `Flag_Key_Not_Found`: Thrown when attempting to check a non-existent flag
- `Not_A_Flag`: Thrown when invalid flag types are provided
- `FileNotFoundException`: Thrown when the JSON file does not exist
- `FileNotReadableException`: Thrown when the JSON file exists but is not readable

### License

[](#license)

GPLv3 - see LICENSE file for details

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance47

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

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

Recently: every ~31 days

Total

11

Last Release

391d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/49420aa2bae0bf6aae204b8d3d2a532061ffb7f609f55adf4579dce79801eb6f?d=identicon)[matteogreco](/maintainers/matteogreco)

---

Top Contributors

[![matteo-greco](https://avatars.githubusercontent.com/u/20144092?v=4)](https://github.com/matteo-greco "matteo-greco (73 commits)")

---

Tags

phpwordpressfeature togglefeature flag

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/digital-gravy-feature-flag/health.svg)

```
[![Health](https://phpackages.com/badges/digital-gravy-feature-flag/health.svg)](https://phpackages.com/packages/digital-gravy-feature-flag)
```

PHPackages © 2026

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