jtrw/feature-flags

功能标志或功能开关

dev-master / 1.0.x-dev 2021-03-17 13:07 UTC

This package is auto-updated.

Last update: 2024-09-17 20:50:33 UTC


README

用于实施功能标志的组件

选项

环境

environments 中指定环境列表,在匿名函数中可以指定对应环境的检查规则

仓库

预计实现功能标志的历史逻辑。例如,如果某个标志被关闭或打开时间过长,将设置规则进行通知。

defaultEnvironments

默认使用的环境

功能

直接所有存在的开启或关闭的功能

OptionsInterface

预计在 Feature::init(OptionsInterface) 的输入中传递一个 OptionsInterface 类的实例。在这个例子中,我们将选项作为 ArrayOptions 数组传递,但在实际应用中,预计选项将来自数据库或 xml、json、yml。

$options = [
    'environments' => [
        'dev'  => static function() {
            return true;
        },
        'test' => static function() {
            return true;
        },
        'prod' => static function() {
            return true;
        }
    ],
    'repository' => new FileRepository(
        ['path' => __DIR__.'/tmp']
    ),
    'defaultEnvironments' => 'dev',
    'features' => [
        'test_feature' => true,
        'new_popup'    => true,
        'logs'         => false
    ]
];

Feature::init(new ArrayOptions($options));

if (Feature::isEnabled('test_feature')) {
    echo "test_feature";
}

if (Feature::isEnabled('new_popup')) {
    echo "new_popup";
}

if (Feature::isEnabled('logs')) {
    echo "logs";
}