2017 © Pedro Peláez
 

library feature-toggler

Feature toggling library for php

image

bazo/feature-toggler

Feature toggling library for php

  • Thursday, July 7, 2016
  • by bazo
  • Repository
  • 1 Watchers
  • 8 Stars
  • 4,911 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 2 % Grown

The README.md

feature-toggler

Feature toggling library for php, (*1)

usage:, (*2)

$toggler = new Toggler($config);
if($toggler->enabled('featureName')) {
    ...
}

you can also pass context to toggler:, (*3)

$toggler = new Toggler($config);

$context = [
    'userId' => 150,
    'site' => 'sk'

];
//using only globals
if($toggler->enabled('feature1')) { //true
    ...
}

or
//using globals and local context
if($toggler->enabled('feature1', $context)) { //true
    ...
}

configuration:, (*4)

simple, with an array, (*5)

$config = [
        'globals' => [
            'site'=> 'sk'
        ],
        'feature1' => [
            'conditions' => [
                ['field' => 'site', 'operator' => 'in', 'arg' => ['sk', 'cz']],
                ['field' => 'userId', 'operator' => '>', 'arg' => 140]
        ],
        'paypal' => [
            'conditions' => [
                ['field' => 'site', 'operator' => 'in', 'arg' => ['sk', 'cz', 'de', 'at']]
            ]
        ]
];

or you can use use shorthand syntax for conditions, it's much cleaner and more readable, (*6)

['site', 'in', ['sk', 'cz', 'de', 'at']]

Operators:, (*7)

there's 5 built-in operators, that cannot be overriden:, (*8)

  • value must be greater than arg < - value must be lower than arg = - value must be equal than arg in - value must be in set of args notIn - value must not be in set of args

You can also register custom operators. A custom operator must implement IOperator interface, (*9)

$operator = new MyCustomOperator;
$toggler->registerOperator($operator);

you can also override the default operator sign, (*10)

$toggler->registerOperator($operator, 'myCustomSign');

then you write a condition like this, (*11)

['field' => 'site', 'operator' => 'myCustomSign', 'arg' => [1, 2, 3, ...]]

Custom features backend:, (*12)

You can also a custom backend for storing features and their conditions, for example a database, (*13)

The backend needs to implement IFeaturesBackend interface which has one method: getConfig(), (*14)

then you use it like this, (*15)

$backend = new MyRedisBackend(...);
$toggler = new BackendDrivenToggler($backend)

enjoy!, (*16)

The Versions

07/07 2016

dev-master

9999999-dev https://github.com/bazo/feature-toggler

Feature toggling library for php

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

features toggling