2017 © Pedro Peláez
 

lib flagception

Feature toggle on steroids.

image

flagception/flagception

Feature toggle on steroids.

  • Tuesday, July 10, 2018
  • by bestit
  • Repository
  • 4 Watchers
  • 6 Stars
  • 13,147 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 9 Versions
  • 226 % Grown

The README.md

Flagception

Flagception is a simple and powerful feature toggle library. Only a few lines of configuration necessary - and still very flexible and expandable., (*1)

Latest Stable Version Coverage Status Build Status Total Downloads License, (*2)

SensioLabsInsight, (*3)

Download the library

Open a command console, enter your project directory and execute the following command to download the latest stable version of this library:, (*4)

$ composer require flagception/flagception

Quick example

Just create a FeatureManager instance and pass your activator to start with feature toggling., (*5)

// MyClass.php
class MyClass
{
    public function doSomething()
    {
        // The activator decide if the feature is active or not
        // You can use your own activator if you implement the interface
        $activator = new ArrayActivator();

        $manager = new FeatureManager($activator);

        if ($manager->isActive('your_feature_name')) {
            // do something
        }
    }
}

The activator is the most important class and decide if the given feature is active or not. The ArrayActivator needs an array with active feature names as constructor argument. If the requested feature is in array, it will return true otherwise false. Example:, (*6)

// MyClass.php
class MyClass
{
    public function doSomething()
    {
        $activator = new ArrayActivator([
            'feature_abc',
            'feature_def',
            'feature_ghi'
        ]);

        $manager = new FeatureManager($activator);

        // Will return true
        if ($manager->isActive('feature_def')) {
            // do something
        }

        // Will return false
        if ($manager->isActive('feature_wxy')) {
            // do something
        }
    }
}

This library ships an ArrayActivator, a ConstraintActivator, a EnvironmentActivator, CookieActivator and a ChainActivator., (*7)

In most cases you will create your own activator (eg. for doctrine). Just implement the FeatureActivatorInterface., (*8)

You can use a CacheActivator if you want to cache the result from some time intensive activators., (*9)

Advanced example

Sometimes your activator needs more context for deciding if a feature is active or not. You can optionally add a context object as second argument to the manager and check the context data in your activator., (*10)

Example:, (*11)

// MyClass.php
class MyClass
{
    public function doSomething(User $user)
    {
        $activator = new YourCustomDoctrineActivator();

        $manager = new FeatureManager($activator);
        $context = new Context();
        $context->add('user_id', $user->getId());

        // Check the feature with context
        if ($manager->isActive('feature_def', $context)) {
            // do something
        }

         // Check the feature without context (result may differ from above)
         if ($manager->isActive('feature_def')) {
             // do something
         }
    }
}

// YourCustomDoctrineActivator.php
class YourCustomDoctrineActivator implements FeatureActivatorInterface
{
    public function isActive($name, Context $context)
    {
        return $context->get('user_id') === 12;
    }
}

You can also add the context data globally instead of adding the context to each feature request. Just pass a class which implement the ContextDecoratorInterface as second argument for the feature manager constructor:, (*12)

// MyClass.php
class MyClass
{
    public function doSomething(User $user)
    {
        $activator = new YourCustomDoctrineActivator();
        $decorator = new ArrayDecorator([
            'user_id' => $user->getId()
        ]);

        $manager = new FeatureManager($activator, $decorator);

        // Check the feature with the global defined context         
        if ($manager->isActive('feature_def')) {
            // do something
        }
    }
}

//YourCustomDoctrineActivator.php
class YourCustomDoctrineActivator implements FeatureActivatorInterface
{
    public function isActive($name, Context $context)
    {
        return $context->get('user_id') === 12;
    }
}

You can also mix both variants:, (*13)

// MyClass.php
class MyClass
{
    public function doSomething(User $user)
    {
        $activator = new YourCustomDoctrineActivator();
        $decorator = new ArrayDecorator([
            'user_id' => $user->getId()
        ]);

        $manager = new FeatureManager($activator, $decorator);

        $context = new Context();
        $context->add('user_name', $user->getUsername());

        // Check the feature with the global defined context         
        if ($manager->isActive('feature_def', $context)) {
            // do something
        }
    }
}

This library ships an ArrayDecorator and a ChainDecorator., (*14)

The Versions

10/07 2018

dev-master

9999999-dev

Feature toggle on steroids.

  Sources   Download

MIT

The Requires

 

The Development Requires

testing flags feature feature-flags toggle rollout feature-toggle flagception

10/07 2018

1.3.0

1.3.0.0

Feature toggle on steroids.

  Sources   Download

MIT

The Requires

 

The Development Requires

testing flags feature feature-flags toggle rollout feature-toggle flagception

07/07 2018

dev-feature/add-database-suggest

dev-feature/add-database-suggest

Feature toggle on steroids.

  Sources   Download

MIT

The Requires

 

The Development Requires

testing flags feature feature-flags toggle rollout feature-toggle flagception

29/06 2018

1.2.0

1.2.0.0

Feature toggle on steroids.

  Sources   Download

MIT

The Requires

 

The Development Requires

testing flags feature feature-flags toggle rollout feature-toggle flagception

25/05 2018

dev-feature/caching

dev-feature/caching

Feature toggle on steroids.

  Sources   Download

MIT

The Requires

 

The Development Requires

testing flags feature feature-flags toggle rollout feature-toggle flagception

06/04 2018

dev-feature/cookie-activator

dev-feature/cookie-activator

Feature toggle on steroids.

  Sources   Download

MIT

The Requires

 

The Development Requires

testing flags feature feature-flags toggle rollout feature-toggle flagception

11/02 2018

dev-feature/caching-profiling

dev-feature/caching-profiling

Feature toggle on steroids.

  Sources   Download

MIT

The Requires

 

The Development Requires

testing flags feature feature-flags toggle rollout feature-toggle flagception

01/02 2018

1.1.0

1.1.0.0

Feature toggle on steroids.

  Sources   Download

MIT

The Requires

 

The Development Requires

testing flags feature feature-flags toggle rollout feature-toggle flagception

30/12 2017

1.0.0

1.0.0.0

Feature toggle on steroids.

  Sources   Download

MIT

The Requires

 

The Development Requires

testing flags feature feature-flags toggle rollout feature-toggle flagception