2017 © Pedro Peláez
 

library php-feature-toggle

A PHP Feature toggle library

image

niborb/php-feature-toggle

A PHP Feature toggle library

  • Sunday, November 8, 2015
  • by niborb
  • Repository
  • 2 Watchers
  • 4 Stars
  • 35 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 9 % Grown

The README.md

PHP 5 feature toggle library

Build Status Coverage Status, (*1)

Installation

You can install the library with Composer., (*2)

composer.phar require "niborb/php-feature-toggle"

or check packagist.org: https://packagist.org/packages/niborb/php-feature-toggle, (*3)

Example (see also the examples directory)

require 'vendor/autoload.php';

require 'User.php';

use Doctrine\Common\Cache\ArrayCache;
use Niborb\FeatureToggle\Cache\CacheProxy;
use Niborb\FeatureToggle\Entity\Feature;
use Niborb\FeatureToggle\Toggle;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;

$toggle = new Toggle();
$toggle->setExpressionLanguage(
    new ExpressionLanguage(
        new CacheProxy(
            new ArrayCache()
        )
    )
);

// new user interface only available for users with an ID in range (1000-2000)
$feature = new Feature('user-interface-2.0');
$feature->enable();
$feature->setExpression('user.getId() in 1000..2000');

// add user to the toggle manager
$toggle->addFeature($feature);

// some users as context
$userOne = new User(3000);
$userTwo = new User(1500);

// check for both users if the feature is enabled

foreach ([$userOne, $userTwo] as $user) {
    if ($toggle->isEnabled('user-interface-2.0', ['user' => $user])
    ) {
        echo "User " . $user->getId() . " can see new interface" . PHP_EOL;
    } else {
        echo "User " . $user->getId() . " cannot(!) see new interface" . PHP_EOL;
    }
}

Output:, (*4)

User 3000 cannot(!) see new interface
User 1500 can see new interface

PHPSpec

The library contains PHPSpec tests (./spec). Clone the repository and run:, (*5)

vendor/bin/phpspec run

The Versions

08/11 2015

dev-master

9999999-dev

A PHP Feature toggle library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Robin Breuker

08/11 2015

1.0.1

1.0.1.0

A PHP Feature toggle library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Robin Breuker

05/07 2015

dev-niborb-5.6

dev-niborb-5.6

A PHP Feature toggle library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Robin Breuker

05/07 2015

1.0.0

1.0.0.0

A PHP Feature toggle library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Robin Breuker