PHPackages                             jadb/feature\_toggle - 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. jadb/feature\_toggle

ActiveLibrary

jadb/feature\_toggle
====================

Feature Flip, Feature Flag, Feature Switch

v0.1.0(9y ago)54.0kBSD-3-ClausePHPPHP &gt;=5.3.0

Since Feb 26Pushed 9y ago3 watchersCompare

[ Source](https://github.com/jadb/feature_toggle)[ Packagist](https://packagist.org/packages/jadb/feature_toggle)[ Docs](http://github.com/jadb/feature_toggle)[ RSS](/packages/jadb-feature-toggle/feed)WikiDiscussions master Synced 4d ago

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

[![Build Status](https://camo.githubusercontent.com/8a7164dd871b20272d93e86c4b7f0a660f1f5889e6566f5f485e1ab557f0e931/68747470733a2f2f7472617669732d63692e6f72672f6a6164622f666561747572655f746f67676c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jadb/feature_toggle)[![Total Downloads](https://camo.githubusercontent.com/dfaecff42fa8b7e0ceaf2683d4265ae991fc1189971319da859863e44e104773/68747470733a2f2f706f7365722e707567782e6f72672f6a6164622f666561747572655f746f67676c652f646f776e6c6f6164732e737667)](https://packagist.org/packages/jadb/feature_toggle)[![License](https://camo.githubusercontent.com/403459e9d9b180fe09c194fe6f59dbbd435a91f9be53241a08933908d27c2b49/68747470733a2f2f706f7365722e707567782e6f72672f6a6164622f666561747572655f746f67676c652f6c6963656e73652e737667)](https://packagist.org/packages/jadb/feature_toggle)

Feature Toggle
==============

[](#feature-toggle)

*a.k.a. Feature Flip, Feature Flag, Feature Switch*

From [Wikipedia](http://en.wikipedia.org/wiki/Feature_toggle):

> Feature Toggle is a technique in software development that attempts to provide an alternative to maintaining multiple source code branches, called feature branches.
>
> Continuous release and continuous deployment enables you to have quick feedback about your coding. This requires you to integrate your changes as early as possible. Feature branches introduce a by-pass to this process. Feature toggles brings you back to the track, but the execution paths of your feature is still “dead” and “untested”, if a toggle is “off”. But the effort is low to enable the new execution paths just by setting a toggle to “on”.

### Common use cases:

[](#common-use-cases)

- Limited testing (i.e. employees only based on email address, subset of users, etc.)
- Gradual feature release (i.e. by location, by subscription, by browser, etc.)

Install
-------

[](#install)

FeatureToggle can be installed using [Composer](http://getcomposer.org) (of course, you could always clone it from GitHub).

**NOTE:** For PHP5.x support, please check the [0.1.0](https://github.com/jadb/feature_toggle/tree/0.1.0) branch.

In `composer.json`:

```
{
    "require": {
        "jadb/feature_toggle": "^1.0"
    }
}
```

To install, you may then run:

```
$ php composer.phar install

```

Example
-------

[](#example)

In your application's bootstrap:

```
use FeatureToggle\FeatureRegistry;
use Predis\Client as Redis;

FeatureRegistry::setStorage(new Redis());

FeatureRegistry::init('Cool Feature', [
	'description' => 'A cool new feature!',
	'strategies' => [
		'UserAgent' => [['/opera/', '/Mozilla\/5\.0/']],
		function ($Feature) {
			return !empty($_SESSION['isAdmin']);
		},
		function ($Feature) {
			return !empty($_SESSION[$Feature->getName()]);
		}
	]
]);

FeatureRegistry::init('Another Cool Feature', [
	'type' => 'threshold', // use the `ThresholdFeature`
	'description' => 'Another cool new feature!',
	'strategies' => [
		'UserAgent' => [['/opera/', '/Mozilla\/5\.0/']],
		function ($Feature) {
			return !empty($_SESSION['isAdmin']);
		},
		function ($Feature) {
			return !empty($_SESSION[$Feature->getName()]);
		}
	]
])->threshold(2); // Require at least 2 strategies to pass
```

and then, anywhere in your code, you can check this feature's status like so:

```
if (\FeatureToggle\FeatureManager::isEnabled('Cool Feature')) {
	// do something
}
```

What's included?
----------------

[](#whats-included)

### Features

[](#features)

- **BooleanFeature**: Enabled if one ore more strategies pass.
- **StrictBooleanFeature**: Enabled only if entire strategies' set passes.
- **ThresholdFeature**: Enabled only if a minimum number of strategies pass.
- **EnabledFeature**: Forces feature to always be enabled.
- **DisabledFeature**: Forces feature to always be disabled.

Features **MUST** implement the `FeatureInterface`.

### Strategies

[](#strategies)

- **DateTimeStrategy**: Compares today's time to set date and time.
- **DateTimeRangeStrategy**: Checks if today's time is in set date time range.
- **UserAgentStrategy**: Checks if browser's user agent matches any allowed agent.

Strategies **MUST** implement the `StrategyInterface`.

### Storage Adapters

[](#storage-adapters)

- **HashStorage**: Default. Basic associative array (a.k.a. in memory)
- **FileStorage**: Filesystem used (only good if features stored in database).
- **MemcachedStorage**: Memcached store, requires the [`Memcached`](http://php.net/manual/en/book.memcached.php) extension.
- **RedisStorage**: Redis store, requires the [`predis/predis`](http://packagist.org/predis/predis) package.

Storage adapaters **MUST** implement the `StorageInterface`.

Todo
----

[](#todo)

- `PercentageStrategy` enable feature to a percentage of users - requires `RedisStorage`
- Option to automatically disable a feature if error threshold reached - requires `RedisStorage`

Contributing
------------

[](#contributing)

- Fork
- Mod, fix, test
- *Optionally* write some documentation (currently in `README.md`)
- Send pull request

All contributed code must be licensed under the \[BSD 3-Clause License\]\[bsd3clause\].

Bugs &amp; Feedback
-------------------

[](#bugs--feedback)

[http://github.com/jadb/feature\_toggle/issues](http://github.com/jadb/feature_toggle/issues)

License
-------

[](#license)

Copyright (c) 2014, [Jad Bitar](http://jadb.io)

Licensed under the [MIT license](https://github.com/jadb/feature_toggle/blob/master/LICENSE).

Redistributions of files must retain the above copyright notice.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75% 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 ~280 days

Total

4

Last Release

3620d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ccb57ae849b67ade8d9c1e266bc2868183bbcf07fb6c66c2d45254a452272d54?d=identicon)[jadb](/maintainers/jadb)

---

Top Contributors

[![borfast](https://avatars.githubusercontent.com/u/4837?v=4)](https://github.com/borfast "borfast (6 commits)")[![jadb](https://avatars.githubusercontent.com/u/33527?v=4)](https://github.com/jadb "jadb (2 commits)")

---

Tags

continuous integrationfeature togglefeature toggling

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jadb-feature-toggle/health.svg)

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

###  Alternatives

[ondram/ci-detector

Detect continuous integration environment and provide unified access to properties of current build

22249.4M33](/packages/ondram-ci-detector)[flagception/flagception-bundle

Feature toggle bundle on steroids.

283.8M](/packages/flagception-flagception-bundle)[mehrancodes/laravel-harbor

A CLI tool to Quickly create On-Demand preview environment for your apps.

9989.0k](/packages/mehrancodes-laravel-harbor)[flagception/flagception

Feature toggle on steroids.

134.3M5](/packages/flagception-flagception)[jbzoo/ci-report-converter

The tool converts different error reporting standards for deep integration with popular CI systems (TeamCity, IntelliJ IDEA, GitHub Actions, etc)

30784.4k2](/packages/jbzoo-ci-report-converter)[cytopia/awesome-ci

Lot's of tools for git, file and static source code analysis.

3386.4k](/packages/cytopia-awesome-ci)

PHPackages © 2026

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