FeatureFlag Dispatcher
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