https://github.com/byjg/php-featureflag
Allows you to enable or disable features in your application and dispatch the proper code based on the flags
https://github.com/byjg/php-featureflag
Last synced: 7 months ago
JSON representation
Allows you to enable or disable features in your application and dispatch the proper code based on the flags
- Host: GitHub
- URL: https://github.com/byjg/php-featureflag
- Owner: byjg
- License: mit
- Created: 2024-11-29T19:53:42.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2024-12-29T23:56:39.000Z (9 months ago)
- Last Synced: 2025-03-19T13:48:46.609Z (7 months ago)
- Language: PHP
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# FeatureFlag Dispatcher
[](https://github.com/byjg/php-featureflag/actions/workflows/phpunit.yml)
[](https://opensource.byjg.com)
[](https://github.com/byjg/php-featureflag/)
[](https://opensource.byjg.com/opensource/licensing.html)
[](https://github.com/byjg/php-featureflag/releases/)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
```php
// 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
- [Callables](docs/callable-dispatchers.md)
- [Attributes](docs/attribute-dispatchers.md)## Advanced Usage
- [Search Order](docs/search-order.md)
- [Passing Arguments](docs/passing-arguments.md)## Install
```bash
composer require "byjg/featureflag"
```## Unit tests
```bash
vendor/bin/phpunit
```## Dependencies
```mermaid
flowchart TD
byjg/featureflag --> php
```----
[Open source ByJG](https://opensource.byjg.com)