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

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

xepozz/feature-flag
===================

Feature-flag management system for Yii 3

1.0.0(2y ago)25PHPPHP ^8.1

Since Jul 28Pushed 2y ago1 watchersCompare

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

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

Feature Flag
============

[](#feature-flag)

This is a simple library to enable/disable features based on a set of rules.

[![Latest Stable Version](https://camo.githubusercontent.com/304ff6461f8a2274de92488aa67e6137d3e554abb751888a5701420f09520b44/68747470733a2f2f706f7365722e707567782e6f72672f7865706f7a7a2f666561747572652d666c61672f762f737461626c652e737667)](https://packagist.org/packages/xepozz/feature-flag)[![Total Downloads](https://camo.githubusercontent.com/80c680d6e9ba1b30b07f5c9eb66c33fb4084235932fa4335f1abd9ef07ac4853/68747470733a2f2f706f7365722e707567782e6f72672f7865706f7a7a2f666561747572652d666c61672f646f776e6c6f6164732e737667)](https://packagist.org/packages/xepozz/feature-flag)[![phpunit](https://github.com/xepozz/feature-flag/workflows/PHPUnit/badge.svg)](https://github.com/xepozz/feature-flag/actions)[![codecov](https://camo.githubusercontent.com/080c2503fe0b88be04286da096397013e70c672f7abd63013ce0298e5357d605/68747470733a2f2f636f6465636f762e696f2f67682f7865706f7a7a2f666561747572652d666c61672f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d55524558414f5548544a)](https://codecov.io/gh/xepozz/feature-flag)[![type-coverage](https://camo.githubusercontent.com/c29f05e3d027bf7b34277096107f7ad393dc72bd91055a55a9f838e76cd25680/68747470733a2f2f73686570686572642e6465762f6769746875622f7865706f7a7a2f666561747572652d666c61672f636f7665726167652e737667)](https://shepherd.dev/github/xepozz/feature-flag)

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

[](#installation)

```
composer require xepozz/feature-flag
```

Configuration
-------------

[](#configuration)

Choose the driver you want to use. Currently, the library supports the following drivers:

- [InMemory](src/Driver/InMemoryDriver.php) - stores data in memory. This driver is used by default.
- [Redis](src/Driver/RedisDriver.php) - stores data in Redis. Uses [phpredis extension](https://github.com/phpredis/phpredis#installation)

### InMemory

[](#inmemory)

Configure the driver in the dependency injection container configuration file:

`di.php`

```
\Xepozz\FeatureFlag\Driver\InMemoryDriver::class => [
    '__construct()' => [
        'flags' => [
            155 => false,
            'feature_name' => true,
            FeaturesEnum::FEATURE_NAME => true,
        ],
    ],
],
```

Or with `params.php`:

```
'xepozz/feature-flag' => [
    'flags' => [
        155 => false,
        'feature_name' => true,
        FeaturesEnum::FEATURE_NAME => true,
    ],
],
```

> Configuring the driver with `params.php` is only available for the `InMemoryDriver`.

### Redis

[](#redis)

Configure the driver in the dependency injection container configuration file:

`di.php`

```
\Xepozz\FeatureFlag\Driver\RedisDriver::class => function () {
    $redis = new Redis();
    $redis->pconnect(
        host: '127.0.0.1',
        port: 6379,
        timeout: 2.5,
    );

    return new \Xepozz\FeatureFlag\Driver\RedisDriver(redis: $redis, hashTableKey: 'ab');
},
```

The driver uses a hash table functions to store and retrieve data. Read more about the hash table functions [here](https://redis.io/commands/?group=hash).

### Choose a driver

[](#choose-a-driver)

After you have chosen a driver, you need to configure the dependency injection container:

`di.php`

```
use Xepozz\FeatureFlag\FlagStorageInterface;
use \Xepozz\FeatureFlag\Driver\RedisDriver;

return [
    // ...
    FlagStorageInterface::class => RedisDriver::class,
    // ...
]
```

Usage
-----

[](#usage)

Pull `\Xepozz\FeatureFlag\FlagStorageInterface` from the dependency injection container and use it:

### `isActive(string|int|BackedEnum $flag): bool`

[](#isactivestringintbackedenum-flag-bool)

```
use Xepozz\FeatureFlag\FlagStorageInterface;

class Controller
{
    public function index(FlagStorageInterface $flagStorage)
    {
        if ($flagStorage->isActive('feature_name')) {
            // feature is enabled
        } else {
            // feature is disabled
        }
    }
}
```

### `setFlag(string|int|BackedEnum $flag, bool $active): void`

[](#setflagstringintbackedenum-flag-bool-active-void)

> Be careful, in case of using not the `InMemoryDriver`, the flag will be stored permanently.

> In case of using the `InMemoryDriver`, the flag will be stored only for the current request. So you can switch the flag depending on the conditions in your code. For instance, you can enable the feature only for trusted IP addresses.

```
use Xepozz\FeatureFlag\FlagStorageInterface;

class Controller
{
    public function index(FlagStorageInterface $flagStorage)
    {
        if ($condition) {
            $flagStorage->setFlag('feature_name', true);
        }
    }
}
```

### `getAll(): array`

[](#getall-array)

Returns all flags as an associative array `array`.

The only `InMemoryDriver` supports returning `BackendEnum` as a key, because it does not need to serialize the key.

The key is the flag name, the value is the flag state.

```
use Xepozz\FeatureFlag\FlagStorageInterface;

class Controller
{
    public function index(FlagStorageInterface $flagStorage)
    {
        $flags = $flagStorage->getAll();
        // ...
    }
}
```

Testing
-------

[](#testing)

#### Redis

[](#redis-1)

Redis driver requires [phpredis extension](https://github.com/phpredis/phpredis) and a running Redis server.

You can use the following command to start a Redis server in a Docker container:

```
docker run --rm -p 6379:6379 redis
```

Or use docker-compose:

```
docker-compose up -d
```

### Run tests:

[](#run-tests)

```
composer test
```

Or

```
./vendor/bin/phpunit
```

Looking for more modules?
-------------------------

[](#looking-for-more-modules)

- [Unique ID](https://github.com/xepozz/unique-id) - Allows you to track the unique user in the application.
- [Request ID](https://github.com/xepozz/request-id) - A simple library to generate both unique request and response IDs for tracing purposes.
- [AB](https://github.com/xepozz/ab) - A simple library to enable A/B testing based on a set of rules.
- [Shortcut](https://github.com/xepozz/shortcut) - Sets of helper functions for rapid development of Yii 3 applications.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

Unknown

Total

1

Last Release

1022d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6815714?v=4)[Dmitrii Derepko](/maintainers/xepozz)[@xepozz](https://github.com/xepozz)

---

Top Contributors

[![xepozz](https://avatars.githubusercontent.com/u/6815714?v=4)](https://github.com/xepozz "xepozz (6 commits)")

---

Tags

feature-flagfeature-flaggingfeature-flagsffmanagementyiiyii3featureyiiflagyii3feature flagyii-extensionyii-moduleyii-packageyii-feature-flagyii-featureyii-flag

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[opensoft/rollout

Feature switches or flags for PHP

2571.8M5](/packages/opensoft-rollout)[francescomalatesta/laravel-feature

A simple package to manage feature flagging in a Laravel project.

211206.4k](/packages/francescomalatesta-laravel-feature)[zumba/swivel

Strategy driven feature toggles

209135.7k5](/packages/zumba-swivel)[novaway/feature-flag-bundle

Very KISS bundle to manage features flag

24278.1k](/packages/novaway-feature-flag-bundle)[ajgarlag/feature-flag-bundle

Provides a feature flag mechanism

1417.8k](/packages/ajgarlag-feature-flag-bundle)

PHPackages © 2026

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