1. Go to this page and download the library: Download zumba/swivel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zumba / swivel example snippets
// Old School Feature Flag
if ($flagIsOn) {
// Do something new
} else {
// Do something old
}
$map = [
// This is a parent feature slug, arbitrarily named "Payment."
// The "Payment" feature is enabled for users in buckets 4, 5, and 6
'Payment' => [4,5,6],
// This is a behavior slug. It is a subset of the parent slug,
// and it is only enabled for users in buckets 4 and 5
'Payment.Test' => [4, 5],
// Behavior slugs can be nested.
// This one is only enabled for users in bucket 5.
'Payment.Test.VersionA' => [5]
];
// Get this value from the session or from persistent storage.
$userBucket = 5; // $_SESSION['bucket'];
// Get the feature map data from persistent storage.
$mapData = [ 'Feature' => [4,5,6], 'Feature.Test' => [4,5] ];
// Make a new configuration object
$config = new \Zumba\Swivel\Config($mapData, $userBucket);
// Make a new Swivel Manager. This is your primary API to the Swivel library.
$swivel = new \Zumba\Swivel\Manager($config);
$map = [ 'Search' => [5], 'Search.NewAlgorithm' => [5] ];
$config = new \Zumba\Swivel\Config($map, $_SESSION['bucketIndex']);
$swivel = new \Zumba\Swivel\Manager($config);
// ServiceLocator is fictional in this example. Use your own framework or repository to store the
// swivel instance.
ServiceLocator::add('Swivel', $swivel);
public function search($params = []) {
$swivel = ServiceLocator::get('Swivel');
return $swivel->forFeature('Search')
->addBehavior('NewAlgorithm', [$this, 'awesomeSearch'], [$params])
->defaultBehavior([$this, 'normalSearch'], [$params])
->execute();
}
protected function normalSearch($params) {
// Tried and True method.
}
protected function awesomeSearch($params) {
// Super cool new search method.
}
$builder = $swivel->forFeature('Test');
$builder
// Inline function. This one will return 'ab'
->addBehavior('versionA', function($a, $b) { return $a . $b; }, ['a', 'b'])
// Callable. Will return the result of $obj->someMethod('c', 'd');
->addBehavior('versionB', [$obj, 'someMethod'], ['c', 'd'])
// Since version 2.0.0, this will throw a \LogicException. Use `addValue` instead.
->addBehavior('versionC', 'result');
$builder = $swivel->forFeature('Test');
$builder
// This will return `'result'`
->addValue('versionA', 'result')
// Callable. This will not be executed; Swivel will just return the unexecuted callable.
->addValue('versionB', [$obj, 'someMethod']);
// $result will contain either the result of
// $this->someMethod(1, 2, 3) or $this->defaultMethod('test')
// depending on the user's bucket
$result = $swivel
->forFeature('Test');
->addBehavior('New.Version', [$this, 'someMethod'], [1, 2, 3])
->defaultBehavior([$this, 'defaultMethod'], ['test'])
->execute();