2017 © Pedro Peláez
 

library feature-switch

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

image

systream/feature-switch

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

  • Thursday, November 24, 2016
  • by systream
  • Repository
  • 2 Watchers
  • 2 Stars
  • 322 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 14 Versions
  • 1 % Grown

The README.md

Feature switch

Installation

You can install this package via packagist.org with composer., (*1)

composer require systream/feature-switch, (*2)

composer.json:, (*3)

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

This library requires php 5.6 or higher., (*4)

Usage examples

By default the feature is not enabled., (*5)

$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., (*6)

Switchers (/ toggles / flippers)

Simple

You can easily switch on a feature:, (*7)

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

A/B 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., (*8)

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

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., (*9)

$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:, (*10)

$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

For custom cases:, (*11)

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

Writing custom switcher

The only thing you should do that your class need to implement FeatureSwitcherInterface interface., (*12)

Add multiple switcher/toggle

$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., (*13)

FeatureSwitch

Simple feature builder

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

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

This class decorates the FeatureSwitch with array access support., (*14)

You can user FeatureSwitchArray class as Array:, (*15)

$featureSwitch = new FeatureSwitchArray();

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

Test

Build Status, (*16)

The Versions

24/11 2016

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Peter Tihanyi

switch feature toggle flag ab test flipper feature switch switcher flip

24/11 2016

1.2.6

1.2.6.0

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

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Peter Tihanyi

switch feature toggle flag ab test flipper feature switch switcher flip

24/11 2016

1.2.5

1.2.5.0

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

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Peter Tihanyi

switch feature toggle flag ab test flipper switcher flip

01/11 2016

1.2.4

1.2.4.0

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

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Peter Tihanyi

switch feature toggle flag ab test flipper switcher flip

26/10 2016

1.2.3

1.2.3.0

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

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Peter Tihanyi

switch feature toggle flag ab test flipper switcher flip

05/06 2016

1.2.2

1.2.2.0

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

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Peter Tihanyi

switch feature toggle flag ab test flipper switcher flip

30/05 2016

1.2.1

1.2.1.0

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

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Peter Tihanyi

switch feature toggle flag ab test flipper switcher flip

22/05 2016

1.2.0

1.2.0.0

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

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Peter Tihanyi

switch feature toggle flag ab test flipper switcher flip

09/05 2016

1.1.1

1.1.1.0

This package provides feature toggle/switch functionality

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Peter Tihanyi

switch feature toggle flag ab test flipper switcher flip

09/05 2016

1.1.0

1.1.0.0

This package provides feature toggle/switch functionality

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Peter Tihanyi

switch feature toggle flag ab test flipper switcher flip

09/05 2016

1.0.4

1.0.4.0

This package provides feature toggle/switch functionality

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Peter Tihanyi

switch feature toggle flag ab test flipper switcher flip

09/05 2016

1.0.3

1.0.3.0

This package provides feature toggle/switch functionality

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Peter Tihanyi

switch feature toggle flag ab test flipper switcher flip

08/05 2016

1.0.2

1.0.2.0

This package provides feature toggle/switch functionality

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Peter Tihanyi

switch feature toggle flag ab test flipper switcher flip

08/05 2016

1.0.1

1.0.1.0

This package provides feature toggle/switch functionality

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Peter Tihanyi

switch feature toggle flag ab test flipper switcher flip