Git Product home page Git Product logo

rollout's Introduction

rollout (for php)

Build Status Scrutinizer Code Quality Code Coverage

Feature flippers for PHP. A port of ruby's rollout.

Install It

composer require opensoft/rollout

How it works

Initialize a rollout object:

use Opensoft\Rollout\Rollout;
use Opensoft\Rollout\Storage\ArrayStorage;

$rollout = new Rollout(new ArrayStorage());

Check if a feature is active for a particular user:

$rollout->isActive('chat', $user);  // returns true/false

Check if a feature is activated globally:

$rollout->isActive('chat'); // returns true/false

Storage

There are a number of different storage implementations for where the configuration for the rollout is stored.

  • ArrayStorage - default storage, not persistent
  • DoctrineCacheStorageAdapter - requires doctrine/cache
  • PDOStorageAdapter - persistent using PDO
  • RedisStorageAdapter - persistent using Redis
  • MongoDBStorageAdapter - persistent using Mongo

All storage adapters must implement Opensoft\Rollout\Storage\StorageInterface.

Groups

Rollout ships with one group by default: all, which does exactly what it sounds like.

You can activate the all group for chat features like this:

$rollout->activateGroup('chat', 'all');

You may also want to define your own groups. We have one for caretakers:

$rollout->defineGroup('caretakers', function(RolloutUserInterface $user = null) {
  if (null === $user) {
    return false;
  }

  return $user->isCaretaker(); // boolean
});

You can activate multiple groups per feature.

Deactivate groups like this:

$rollout->deactivateGroup('chat');

Specific Users

You may want to let a specific user into a beta test or something. If that user isn't part of an existing group, you can let them in specifically:

$rollout->activateUser('chat', $user);

Deactivate them like this:

$rollout->deactivateUser('chat', $user);

Rollout users must implement the RolloutUserInterface.

User Percentages

If you're rolling out a new feature, you may want to test the waters by slowly enabling it for a percentage of your users.

$rollout->activatePercentage('chat', 20);

The algorithm for determining which users get let in is this:

crc32($user->getRolloutIdentifier()) % 100 < $percentage

So, for 20%, users 0, 1, 10, 11, 20, 21, etc would be allowed in. Those users would remain in as the percentage increases.

Deactivate all percentages like this:

$rollout->deactivatePercentage('chat');

Note: Activating a feature for 100% of users will also make it activate globally. This is like calling $rollout->isActive() without a user object.

Feature is Broken

Deactivate everybody at once:

$rollout->deactivate('chat');

You may wish to disable features programmatically if monitoring tools detect unusually high error rates for example.

Remove a Feature (added in 2.0.0)

After a feature becomes mainstream or a failed experiment, you may want to remove the feature definition from rollout.

$rollout->remove('chat');

Note: If there is still code referencing the feature, it will be recreated with default settings.

Symfony2 Bundle

A Symfony2 bundle is available to integrate rollout into Symfony2 projects. It can be found at http://github.com/opensoft/OpensoftRolloutBundle.

Zend Framework 2 Module

A Zend Framework 2 module is availabile to intergrate rollout into Zend Framwork 2 projects. It can be found at https://github.com/adlogix/zf2-opensoft-rollout.

Implementations in other languages

Copyright

Copyright © 2017 James Golick, BitLove, Inc. See LICENSE for details.

rollout's People

Contributors

richardfullmer avatar shadowhand avatar snags88 avatar timwattenberg avatar tonivdv avatar filipgolonka avatar zorato avatar 4rthem avatar baldurrensch avatar securingsincity avatar mattclements avatar oxicode avatar scrutinizer-auto-fixer avatar trivoallan avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.