PHP code example of treehouselabs / feature-toggle

1. Go to this page and download the library: Download treehouselabs/feature-toggle 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/ */

    

treehouselabs / feature-toggle example snippets


$features = new FeatureToggleCollection();
$features->registerToggle(
    'feature-x',
    new BooleanFeatureToggle(true)
);

if ($features->isEnabled('feature-x')) {
    // perform stuff for feature-x
}



   class Feature
   {
       private $features;

       public function __construct(FeatureToggleCollectionInterface $features) {
           $this->features = $features;
       }

       public function indexAction()
       {
           if ($this->features->isEnabled('feature-y')) {
               return 'Enabled!';
           }

           return 'Disabled!';
       }
   }

   $toggleCollection = new CacheFeatureToggleCollection();
   $toggleCollection->setCacheItemPool($psr6CacheItemPool);

   // Overwrite the FeatureToggleCollection with the CacheFeatureToggleCollection in test env
   new Feature($toggleCollection);