2017 © Pedro Peláez
 

library feature-flag

Simple feature flag checking for PHP >=5.5

image

fraserreed/feature-flag

Simple feature flag checking for PHP >=5.5

  • Saturday, September 19, 2015
  • by fraserreed
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

FeatureFlag

Simple feature flag checking for PHP >=5.5., (*1)

Build Status Coverage Status, (*2)

Installation

Install this package in your application using composer., (*3)

In the require section, add the following dependency:, (*4)

"fraserreed/feature-flag": "~0.2"

Usage

Any of these approaches can be extended and put in a view helper in most frameworks., (*5)

Static Configuration

For static, array based feature flags, ideally used in multi-environment deploys., (*6)

First create the static filter:, (*7)

$config = [
    'feature-one'   => true,
    'feature-two'   => false,
    'feature-three' => true,
    'feature-four'  => true
];

$featureFlagFilter = new \FeatureFlag\Filter\Simple( $config );

Then assert that a feature is enabled or not:, (*8)

$featureFlag = new \FeatureFlag\FeatureFlag( $featureFlagFilter );

echo (int) $featureFlag->isEnabled( 'feature-one' ) . " should be true\n";
echo (int) $featureFlag->isEnabled( 'feature-two' ) . " should be false\n";
echo (int) $featureFlag->isEnabled( 'feature-three' ) . " should be true\n";
echo (int) $featureFlag->isEnabled( 'feature-four' ) . " should be true\n";
echo (int) $featureFlag->isEnabled( 'feature-five' ) . " should be false (doesn't exist)\n";

Distributed IP Address Weighting

For an expected distribution across the IPv4 spectrum, a weighted configuration can be used. A crc32 hash checksum is computed for the IP, modulo 100., (*9)

First create the filter with the expected distribution factor., (*10)

//feature flag will be enabled 75% of the time
$featureFlagFilter = new \FeatureFlag\Filter\DistributedIp( 75 );

Then assert that a feature is enabled or not:, (*11)

$featureFlag = new \FeatureFlag\FeatureFlag( $featureFlagFilter );

echo (int) $featureFlag->isEnabled( 'feature-one', '192.168.0.161' ) . " should be false\n";
echo (int) $featureFlag->isEnabled( 'feature-one', '31.12.127.255' ) . " should be true\n";
echo (int) $featureFlag->isEnabled( 'feature-one', '46.248.224.183' ) . " should be true\n";
echo (int) $featureFlag->isEnabled( 'feature-one', '58.136.218.102' ) . " should be true\n";

Tests

To run the tests you'll need to have phpunit installed., (*12)

Running the tests:, (*13)

$ phpunit

Contributing

For any issues, submit an issue via this repo. For contributing please fork and submit PRs., (*14)

License

MIT, see LICENSE., (*15)

The Versions

19/09 2015

dev-master

9999999-dev http://github.com/fraserreed/feature-flag

Simple feature flag checking for PHP >=5.5

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Fraser Reed

feature flag

16/09 2015

v0.3

0.3.0.0 http://github.com/fraserreed/feature-flag

Simple feature flag checking for PHP >=5.5

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Fraser Reed

feature flag

15/09 2015

v0.2

0.2.0.0 http://github.com/fraserreed/feature-flag

Simple feature flag checking for PHP >=5.5

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Fraser Reed

feature flag

15/09 2015

v0.1

0.1.0.0

  Sources   Download

The Requires

  • php >=5.5

 

The Development Requires

by Fraser Reed