dev-master
9999999-dev https://github.com/bazo/feature-togglerFeature toggling library for php
MIT
The Requires
- php >=5.4.0
The Development Requires
by Martin Bažík
features toggling
Feature toggling library for php
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)
Feature toggling library for php
MIT
features toggling