Skip to content

alaz/php-toggles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Feature Toggles, aka. Features, Toggles, Flags, etc.

Why another library?

  • Very short & simple
  • Compatible with its Play Framework counterpart: play-toggles

Features

  • Calculates strategies only once per browser session and then caches the result in a session cookie
  • Gradual rollout strategy does not depend on user ID per se. Instead, it may be given any user-related textual ID.
  • Whitelist and Blacklist depend on the same user ID.
  • Provides AnonymousOn (enables a feature for anonymous users) and AnonymousOff (disables a feature for anonymous users)

Use

Init:

use Osinka\Toggles\Toggles;
use Osinka\Toggles\Strategies;

class UserStrategies extends Osinka\Toggles\UserStrategies {
  function user_id() {
    # return `null` when the current user is anonymous and
    # user ID if he/she is authenticated
  }
}

$UserStrategies = new UserStrategies();

$Toggles = new Toggles(
  array(
    'socialBlock' => array(
      Strategies::internalNet(),
      $UserStrategies->anonymousOff(),
      $UserStrategies->whitelist(array("012345", "98765")),
      $UserStrategies->blacklist(array("678")),
      $UserStrategies->gradual(10) # 10%
    ),
    'testedAndOn' => TRUE,
    'inDevelopment' => FALSE
  )
);

Check anywhere:

if (Toggles::active('socialBlock')) {
 # display new social block
}

About

Feature toggles in plain PHP. Simple

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages