1. Go to this page and download the library: Download pablojoan/feature 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/ */
pablojoan / feature example snippets
use PabloJoan\Feature\Features; // Import the namespace.
$featureConfigs = [
'foo' => [
'variants' => [
'variant1' => 100, //100% chance this variable will be chosen
'variant2' => 0 //0% chance this variable will be chosen
]
],
'bar' => [
'variants' => [
'variant1' => 25, //25% chance this variable will be chosen
'variant2' => 25, //25% chance this variable will be chosen
'variant3' => 50 //50% chance this variable will be chosen
],
'bucketing' => 'id' //same id string will always return the same variant
]
];
$features = new Features($featureConfigs);
$features->isEnabled(featureName: 'foo'); // true
$features->getEnabledVariant(featureName: 'foo'); // 'variant1'
if ($features->isEnabled(featureName: 'my_feature')) {
// do stuff
}
switch ($features->getEnabledVariant(featureName: 'my_feature')) {
case 'foo':
// do stuff appropriate for the 'foo' variant
break;
case 'bar':
// do stuff appropriate for the 'bar' variant
break;
}