byjg/featureflag

There is no license information available for the latest version (dev-master) of this package.

Allows you to enable or disable features in your application and dispatch the proper code based on the flags.

Fund package maintenance!
byjg

dev-master 2024-11-29 19:55 UTC

This package is auto-updated.

Last update: 2024-11-29 20:01:31 UTC


README

Build Status Opensource ByJG GitHub source GitHub license GitHub release

A simple feature flag dispatcher.

It allows you to define a list of features and dispatch the request to the proper handler based on the enabled feature flag.

Basic Usage

// Initialize the enabled features
FeatureFlags::addFlag('flag1', 'value1');
FeatureFlags::addFlag('flag2', 'value2');
FeatureFlags::addFlag('flag3');

// Create a Dispatcher
$dispatcher = new FeatureFlagDispatcher();

// Add a feature flag handler
$dispatcher->add(FeatureFlagSelector::whenFlagIs('flag2', 'value1', function () {/** function1 */}));
$dispatcher->add(FeatureFlagSelector::whenFlagIs('flag2', 'value2', function () {/** function2 */}));
$dispatcher->add(FeatureFlagSelector::whenFlagIs('flag2', 'value3', [Someclass::class, 'method1']));

// Dispatch the request    
$dispatcher->dispatch();

// Since there is a feature flag 'flag2' with value 'value2' the function2 will be executed

Note that if one or more feature flags matches the condition, all of them will be executed in the order they were added.

Adding Dispatchers

Advanced Usage

Install

composer require "byjg/featureflag"

Unit tests

vendor/bin/phpunit

Dependencies

Open source ByJG