loketid / rc-feature
本软件包最新版本(dev-master)没有可用的许可信息。
dev-master
2019-07-15 02:01 UTC
Requires (Dev)
- phpunit/phpunit: ^8.2@dev
This package is not auto-updated.
Last update: 2024-09-29 05:42:17 UTC
README
RC Feature(远程配置功能)是一个用于功能切换和从远程服务器获取配置的动态配置库。
依赖关系
- PHP 7.2
- PHPUnit 8.1.4
安装
使用 composer 将此库包含到您的项目中。
composer require loketid/rc-feature
如何测试
在项目文件夹中运行 phpunit
。
如何使用
构造函数
要创建一个新的实例对象,您可以使用以下构造函数
namespace RCFeature $featureManager = new FeatureManager(ConnectionDriver, DefaultConfig);
- ConnectionDriver 是我们用来持久化存储的对象
- DefaultConfig 是关联数组,如果持久化存储中找不到任何功能配置,则存储默认配置
$config = [ "feature-1" => 1, // 1 represent enabled feature "feature-2" => 0, // 0 represent disabled feature "feature-config" => "some string" ]
isEnabled
用于检查功能是否启用。
$featureManager->isEnabled("feature-1"); // return true or false
getRemoteConfiguration
用于获取存储在持久化中的配置。
$featureManager->getRemoteConfiguration("feature-config"); // return string
enable
用于启用特定功能。
$featureManager->enable("feature-1"); // return true if success
disable
用于禁用特定功能。
$featureManager->disable("feature-1"); // return true if success
update
用于同时更新多个功能配置/状态。
$featureConfig = [ "feature-1" => 1, "feature-2" => 0, "feature-config" => "some string", ] $featureManager->update($featureConfig); // return true if success
连接驱动程序
如上所述,此库需要通过构造函数传递连接驱动程序。
目前支持 redis,使用 phpredis 扩展。
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);
并将驱动程序对象传递给功能管理器构造函数。
$instance = new FeatureManager($driver, $defaultConfig);