PHPackages                             trompette/feature-toggles - 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. [DevOps &amp; Deployment](/categories/devops)
4. /
5. trompette/feature-toggles

ActiveLibrary[DevOps &amp; Deployment](/categories/devops)

trompette/feature-toggles
=========================

Feature toggle infrastructure enabling continuous deployment

5.1.0(2y ago)543.3k↓40.4%1[2 issues](https://github.com/trompette/php-feature-toggles/issues)MITPHPPHP &gt;=8.1CI passing

Since Dec 17Pushed 12mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (17)Versions (13)Used By (0)

[![License](https://camo.githubusercontent.com/20d27c1d85fc1c3f4b615e31c2b55e0aa62e9da3cfcd252fd05296f001107143/68747470733a2f2f706f7365722e707567782e6f72672f74726f6d70657474652f666561747572652d746f67676c65732f6c6963656e7365)](LICENSE)[![Stable Version](https://camo.githubusercontent.com/0c91d79060aa7faa0239d71b5f54a6e65f9825300dd80765b54b97f87e00e663/68747470733a2f2f706f7365722e707567782e6f72672f74726f6d70657474652f666561747572652d746f67676c65732f762f737461626c65)](https://packagist.org/packages/trompette/feature-toggles)[![Automated Tests](https://github.com/trompette/php-feature-toggles/actions/workflows/automated-tests.yml/badge.svg)](https://github.com/trompette/php-feature-toggles/actions/workflows/automated-tests.yml)[![Static Analysis](https://github.com/trompette/php-feature-toggles/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/trompette/php-feature-toggles/actions/workflows/static-analysis.yml)

trompette/feature-toggles
=========================

[](#trompettefeature-toggles)

This PHP library implements a feature toggle infrastructure.

Using `trompette/feature-toggles` library can help a team to deliver new features to users iteratively and safely, in other words: it enables continuous deployment.

For more information on the topic, see [*Feature Toggles (aka Feature Flags)* on MartinFowler.com](https://martinfowler.com/articles/feature-toggles.html).

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

[](#installation)

The `trompette/feature-toggles` library is distributed on [Packagist](https://packagist.org/packages/trompette/feature-toggles).

It can be added as a project dependency with the following command:

```
composer require trompette/feature-toggles
```

Standalone usage
----------------

[](#standalone-usage)

When working on a new version of a page, deploying gradually the new version can bring a lot of confidence to a team.

But it also brings more work, as the team needs to:

- keep the code implementing the current version,
- add the code implementing the new version,
- and consistently enable the new version for some users.

With `trompette/feature-toggles` library, enabling the new version is done by asking the [toggle router](sources/ToggleRouter.php) if the current user has a feature:

```
if ($toggleRouter->hasFeature($currentUser, 'new_page_version')) {
    $templating->render('new_page.tpl', $newParameters);
} else {
    $templating->render('page.tpl', $parameters);
}
```

### Feature registry

[](#feature-registry)

Before using the [toggle router](sources/ToggleRouter.php), `new_page_version`feature has to be registered:

```
use Trompette\FeatureToggles\FeatureDefinition;
use Trompette\FeatureToggles\FeatureRegistry;

$featureRegistry = new FeatureRegistry();
$featureRegistry->register(new FeatureDefinition(
    $name = 'new_page_version',
    $description = 'awesome new version of a page',
    $strategy = 'whitelist'
));
```

### Toggling strategies

[](#toggling-strategies)

When defining a feature, a [toggling strategy](sources/TogglingStrategy.php) has to be referenced to specify the algorithm deciding if a target has a feature.

Implemented strategies are:

- feature is enabled for all targets or disabled for all targets, see [`OnOff`](sources/OnOffStrategy/OnOff.php) class,
- feature is enabled for whitelisted targets only, see [`Whitelist`](sources/WhitelistStrategy/Whitelist.php) class,
- feature is enabled for a percentage of all targets, see [`Percentage`](sources/PercentageStrategy/Percentage.php) class.

And strategies can be combined with boolean operators, like so: `onoff and whitelist`, `onoff or whitelist or percentage`, etc.

### Toggle router

[](#toggle-router)

Now that the [feature registry](sources/FeatureRegistry.php) is configured, the [toggle router](sources/ToggleRouter.php) can be created:

```
use Doctrine\DBAL\Connection;
use Trompette\FeatureToggles\DBAL\WhitelistStrategyConfigurationRepository;
use Trompette\FeatureToggles\ToggleRouter;
use Trompette\FeatureToggles\WhitelistStrategy\Whitelist;

$connection = new Connection(...);
$repository = new WhitelistStrategyConfigurationRepository($connection);
$whitelist = new Whitelist($repository);

$toggleRouter = new ToggleRouter(
    $featureRegistry,
    $strategies = ['whitelist' => $whitelist]
);
```

Strategies are injected as an array indexed with names: these are the references that should be used when registering features.

### Feature configuration

[](#feature-configuration)

The [toggle router](sources/ToggleRouter.php) can be used to configure a feature for a given strategy:

```
$toggleRouter->configureFeature('feature', 'onoff', 'on');
$toggleRouter->configureFeature('feature', 'onoff', 'off');

$toggleRouter->configureFeature('feature', 'whitelist', 'allow', 'target');
$toggleRouter->configureFeature('feature', 'whitelist', 'disallow', 'target');

$toggleRouter->configureFeature('feature', 'percentage', 'slide', 25);
$toggleRouter->configureFeature('feature', 'percentage', 'slide', 50);
```

Configuration changes are persisted by calling the associated method on the strategy instance.

All Doctrine DBAL configuration repositories can migrate a schema, since they all implement the [`SchemaMigrator`](sources/DBAL/SchemaMigrator.php) interface:

```
use Doctrine\DBAL\Connection;
use Trompette\FeatureToggles\DBAL\WhitelistStrategyConfigurationRepository;

$connection = new Connection(...);
$repository = new WhitelistStrategyConfigurationRepository($connection);
$repository->migrateSchema();
```

Usage with Symfony
------------------

[](#usage-with-symfony)

All previous code is optional when using Symfony: everything is glued together by the [`FeatureTogglesBundle`](sources/Bundle/FeatureTogglesBundle.php) class.

Registering the [bundle](sources/Bundle/FeatureTogglesBundle.php) in `config/bundles.php` is needed to benefit from the Symfony integration:

```
return [
    // ...
    Trompette\FeatureToggles\Bundle\FeatureTogglesBundle::class => ['all' => true],
];
```

### Bundle configuration

[](#bundle-configuration)

The [bundle](sources/Bundle/FeatureTogglesBundle.php) can be configured as described by `config:dump-reference`:

```
# Default configuration for extension with alias: "feature_toggles"
feature_toggles:
    doctrine_dbal_connection: doctrine.dbal.default_connection
    declared_features:

        # Prototype
        name:
            description:          ~ # Required
            strategy:             ~ # Required
```

For technical details, see [`FeatureTogglesConfiguration`](sources/Bundle/FeatureTogglesConfiguration.php)class.

### Container services

[](#container-services)

There is only one service declared as public: the [toggle router](sources/ToggleRouter.php) with `Trompette\FeatureToggles\ToggleRouter`or `Trompette\FeatureToggles\ToggleRouterInterface` as identifier.

There are also useful console commands defined as services and tagged with `console.command`:

```
 feature-toggles
  feature-toggles:configure-feature           Configures a feature
  feature-toggles:migrate-dbal-schema         Migrates DBAL schema
  feature-toggles:show-feature-configuration  Shows a feature configuration

```

More information about the commands can be found in their help messages.

For technical details, see [`FeatureTogglesExtension`](sources/Bundle/FeatureTogglesExtension.php) class.

License
-------

[](#license)

The `trompette/feature-toggles` library is released under the MIT License.

See the [LICENSE](LICENSE) file for more details.

Acknowledgments
---------------

[](#acknowledgments)

The `trompette/feature-toggles` library is inspired by a practice and a tool used by the [Food Assembly development team](https://github.com/lrqdo).

The team discovered the practice with the article [*Web Experimentation with New Visitors* on Etsy's Engineering Blog](https://codeascraft.com/2014/04/03/web-experimentation-with-new-visitors).

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 97.9% 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 ~141 days

Recently: every ~196 days

Total

12

Last Release

784d ago

Major Versions

1.2.1 → 2.0.02021-06-13

2.1.0 → 3.0.02022-01-30

3.0.2 → 4.0.02022-12-20

4.0.0 → 5.0.02024-03-24

PHP version history (6 changes)1.0.0PHP ^7.2

1.2.0PHP &gt;=7.2

2.0.0PHP &gt;=7.3

3.0.0PHP &gt;=7.4

4.0.0PHP &gt;=8.0

5.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/6285d829991e383c8c3806cef15da52738752bad4dd49f04079e5ab83dafd445?d=identicon)[trompette](/maintainers/trompette)

---

Top Contributors

[![trompette](https://avatars.githubusercontent.com/u/181746?v=4)](https://github.com/trompette "trompette (143 commits)")[![nclavaud](https://avatars.githubusercontent.com/u/1181770?v=4)](https://github.com/nclavaud "nclavaud (2 commits)")[![victor-paumier](https://avatars.githubusercontent.com/u/13373091?v=4)](https://github.com/victor-paumier "victor-paumier (1 commits)")

---

Tags

continuous-deliverycontinuous-deploymentfeature-flagsfeature-togglesphp-librarysymfonyfeatureflagcontinuoustoggledeployment

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/trompette-feature-toggles/health.svg)

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

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[simplesamlphp/simplesamlphp

A PHP implementation of a SAML 2.0 service provider and identity provider.

1.1k12.4M193](/packages/simplesamlphp-simplesamlphp)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)

PHPackages © 2026

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