loketid / rc-feature
Installs: 1 012
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires (Dev)
- phpunit/phpunit: ^8.2@dev
This package is not auto-updated.
Last update: 2024-06-23 04:24:52 UTC
README
RC Feature
RC Feature (Remote Configuration Feature) is a dynamic configuration library for feature toggle and configuration fetch from remote server.
Dependencies
- PHP 7.2
- PHPUnit 8.1.4
Installation
Use composer to include this library to your project.
composer require loketid/rc-feature
How to Test
Run phpunit
inside project folder.
How to Use
Constructor
To create a new instance object, you can use these constructor:
namespace RCFeature $featureManager = new FeatureManager(ConnectionDriver, DefaultConfig);
- ConnectionDriver is object that we use to persist storage
- DefaultConfig is associative array that store default configuration if any feature config not found on persistence storage
$config = [ "feature-1" => 1, // 1 represent enabled feature "feature-2" => 0, // 0 represent disabled feature "feature-config" => "some string" ]
isEnabled
Used to check whether feature is enabled.
$featureManager->isEnabled("feature-1"); // return true or false
getRemoteConfiguration
Used to get configuration that stored in persistence.
$featureManager->getRemoteConfiguration("feature-config"); // return string
enable
Used to enable specific feature.
$featureManager->enable("feature-1"); // return true if success
disable
Used to disable specific feature.
$featureManager->disable("feature-1"); // return true if success
update
Used to update multiple feature configuration / state at same time.
$featureConfig = [ "feature-1" => 1, "feature-2" => 0, "feature-config" => "some string", ] $featureManager->update($featureConfig); // return true if success
Connection Driver
As mentioned above, this library need connection driver to passed within constructor.
Currently support redis, using phpredis extension.
RedisConnectionDriver
use RCFeature/Driver; $driverConfig = [ "hostname" => "127.0.0.1", "port" => "4567", "timeout" => 1000, "prefix" => "string", // optional custom prefix ] $appName = "your-app-name" $driver = new RedisConnectionDriver($driverConfig, $appName);
and pass the driver object to feature manager constructor.
$instance = new FeatureManager($driver, $defaultConfig);