PHPackages                             systream/feature-switch - 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. systream/feature-switch

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

systream/feature-switch
=======================

This package provides feature switch functionality. A/B test support and time based switcher.

1.2.6(9y ago)2387MITPHPPHP &gt;=5.6.0

Since May 8Pushed 9y ago2 watchersCompare

[ Source](https://github.com/systream/feature-switch)[ Packagist](https://packagist.org/packages/systream/feature-switch)[ RSS](/packages/systream-feature-switch/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (10)Dependencies (2)Versions (14)Used By (0)

Feature switch
==============

[](#feature-switch)

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

[](#installation)

You can install this package via [packagist.org](https://packagist.org/packages/systream/feature-switch) with [composer](https://getcomposer.org/).

`composer require systream/feature-switch`

composer.json:

```
"require": {
    "systream/feature-switch": "1.*"
}
```

This library requires `php 5.6` or higher.

Usage examples
--------------

[](#usage-examples)

By default the feature is not enabled.

```
$feature = new Feature('foo_bar_feature_key');
$feature->isEnabled(); // will return: false
```

If you want to change the feature state, you have to set up one or more switcher.

### Switchers (/ toggles / flippers)

[](#switchers--toggles--flippers)

#### Simple

[](#simple)

You can easily switch on a feature:

```
$feature = new Feature('foo_bar_feature_key');
$feature->addSwitcher(Simple::on());
$feature->isEnabled(); // will return: true
```

#### A/B testing

[](#ab-testing)

This will enable the feature approximately 50% of the visitors. The feature status is tracking by cookie, so if the visitor returns, the same state of the feature will be shown.

```
$feature = new Feature('foo_bar_feature_key');
$feature->addSwitcher(new AB());
$feature->isEnabled();
```

#### Time based switching

[](#time-based-switching)

With this library you can set up a time based feature toggle too. For example you cool new feature will be available for every visitor after a point in time.

```
$feature = new Feature('foo_bar_feature_key');
$feature->addSwitcher(new Until(\DateTime::createFromFormat('Y-m-d H:i:s', '2017-08-12 10:00:00')));
$feature->isEnabled(); // brefore 2017-08-12 10:00:00 it's return false, after will return true
```

If you want to disable a feature after a date:

```
$feature = new Feature('foo_bar_feature_key');
$feature->addSwitcher(new Until(\DateTime::createFromFormat('Y-m-d H:i:s', '2017-08-12 10:00:00'), false));
$feature->isEnabled(); // brefore 2017-08-12 10:00:00 it's return true, after will return false
```

#### Callback

[](#callback)

For custom cases:

```
$feature = new Feature('foo_bar_feature_key');
$feature->addSwitcher(
	new Callback(function() {
		/* do custom logic */
		return true;
	})
);
$feature->isEnabled();
```

#### Writing custom switcher

[](#writing-custom-switcher)

The only thing you should do that your class need to implement `FeatureSwitcherInterface` interface.

### Add multiple switcher/toggle

[](#add-multiple-switchertoggle)

```
$feature = new Feature('foo_bar_feature_key');
$feature->addSwitcher(new AB());
$feature->addSwitcher(new Until(\DateTime::createFromFormat('Y-m-d H:i:s', '2017-08-12 10:00:00')));
$feature->isEnabled();
```

The feature will passed to all of the switcher until one of them return true; In this case the feature will tested first with AB switcher and if it returns false then it passes to the next time based switcher.

FeatureSwitch
-------------

[](#featureswitch)

### Simple feature builder

[](#simple-feature-builder)

```
$feature1 = FeatureSwitch::buildFeature('foo_feature', true); // enabled
$feature2 = FeatureSwitch::buildFeature('another_bar_feature', false); // disabled
```

### Container

[](#container)

```
$featureSwitch = new FeatureSwitch();
$featureSwitch->addFeature(FeatureSwitch::buildFeature('foo', true));

$feature = new Feature('bar2');
$feature->addSwitcher(new AB());

$featureSwitch->addFeature($feature);
```

```
$featureSwitch->isEnabled('foo'); // true
$featureSwitch->isEnabled('bar2');
```

#### FeatureSwitchArray

[](#featureswitcharray)

This class decorates the `FeatureSwitch` with array access support.

You can user FeatureSwitchArray class as Array:

```
$featureSwitch = new FeatureSwitchArray();

$featureSwitch[] = FeatureSwitch::buildFeature('foo', true);
$featureSwitch->isEnabled('foo'); // returns true
$featureSwitch['foo']->isEnabled();
```

Test
----

[](#test)

[![Build Status](https://camo.githubusercontent.com/605ddea9ec497089944b5d571425571533f4feef5de6c37cd4065383c00c2b2b/68747470733a2f2f7472617669732d63692e6f72672f737973747265616d2f666561747572652d7377697463682e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/systream/feature-switch)

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

Established project with proven stability

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

Recently: every ~43 days

Total

13

Last Release

3506d ago

PHP version history (2 changes)1.0.1PHP &gt;=5.6.0

1.0.4PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/2c5ea6e7d8143a1fba541e1f41419cf36a4f970806d4bd91094d3b46177aea6d?d=identicon)[systream](/maintainers/systream)

---

Top Contributors

[![systream](https://avatars.githubusercontent.com/u/1583029?v=4)](https://github.com/systream "systream (37 commits)")

---

Tags

featureswitcherflagtoggleswitchflipperflipab testfeature switch

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/systream-feature-switch/health.svg)

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

###  Alternatives

[qandidate/toggle

Feature toggling for your PHP application.

3812.1M9](/packages/qandidate-toggle)[opensoft/rollout

Feature switches or flags for PHP

2571.9M5](/packages/opensoft-rollout)[zumba/swivel

Strategy driven feature toggles

208139.1k5](/packages/zumba-swivel)[ajgarlag/feature-flag-bundle

Provides a feature flag mechanism

1421.0k](/packages/ajgarlag-feature-flag-bundle)[francescomalatesta/laravel-feature

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

211206.8k](/packages/francescomalatesta-laravel-feature)[flagception/flagception-bundle

Feature toggle bundle on steroids.

324.0M](/packages/flagception-flagception-bundle)

PHPackages © 2026

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