2017 © Pedro PelĂĄez
 

library feature_toggle

Feature Flip, Feature Flag, Feature Switch

image

jadb/feature_toggle

Feature Flip, Feature Flag, Feature Switch

  • Friday, June 17, 2016
  • by jadb
  • Repository
  • 3 Watchers
  • 5 Stars
  • 3,988 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Build Status Total Downloads License, (*1)

Feature Toggle

a.k.a. Feature Flip, Feature Flag, Feature Switch, (*2)

From Wikipedia:, (*3)

Feature Toggle is a technique in software development that attempts to provide an alternative to maintaining multiple source code branches, called feature branches., (*4)

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

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

FeatureToggle can be installed using Composer (of course, you could always clone it from GitHub)., (*6)

NOTE: For PHP5.x support, please check the 0.1.0 branch., (*7)

In composer.json:, (*8)

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

To install, you may then run:, (*9)

$ php composer.phar install

Example

In your application's bootstrap:, (*10)

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

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

What's included?

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

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

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 extension.
  • RedisStorage: Redis store, requires the predis/predis package.

Storage adapaters MUST implement the StorageInterface., (*14)

Todo

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

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

Bugs & Feedback

http://github.com/jadb/feature_toggle/issues, (*16)

License

Copyright (c) 2014, Jad Bitar, (*17)

Licensed under the MIT license., (*18)

Redistributions of files must retain the above copyright notice., (*19)

The Versions

17/06 2016

dev-master

9999999-dev http://github.com/jadb/feature_toggle

Feature Flip, Feature Flag, Feature Switch

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

continuous integration feature flag feature switch feature toggle feature toggling feature flip

17/06 2016

0.1.0.x-dev

0.1.0.9999999-dev http://github.com/jadb/feature_toggle

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.0

 

The Development Requires

continuous integration feature toggle feature toggling

17/06 2016

v0.1.0

0.1.0.0 http://github.com/jadb/feature_toggle

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.0

 

The Development Requires

continuous integration feature toggle feature toggling

04/09 2014

0.0.2

0.0.2.0 http://github.com/jadb/feature_toggle

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.0

 

The Development Requires

continuous integration feature toggle feature toggling

26/02 2014

0.0.1

0.0.1.0 http://github.com/jadb/feature_toggle

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.0

 

The Development Requires

continuous integration feature toggle feature toggling