2dotstwice / silex-feature-toggles-provider

dev-master / 0.x-dev 2017-07-03 14:15 UTC

This package is auto-updated.

Last update: 2024-08-29 04:14:31 UTC


README

Build Status

安装

服务提供者

FeatureTogglesProvider 注册到您的 Silex 应用程序中。 $featureToggleConfiguration 应该是一个包含开关配置的数组。例如,您可以从配置文件中检索它,但如何处理取决于您的应用程序。

$app->register(
    new \TwoDotsTwice\SilexFeatureToggles\FeatureTogglesProvider(
        $featureToggleConfiguration
    )
);

在 2dotstwice,我们成功地将它与 DerAlex 的 YamlConfigServiceProvider 一起使用。

$app->register(new \DerAlex\Silex\YamlConfigServiceProvider(__DIR__ . '/config.yml'));

$app->register(
    new \TwoDotsTwice\SilexFeatureToggles\FeatureTogglesProvider(
        $app['config']['toggles']
    )
);

config.yml 的内容可能如下所示

toggles:
  profile-date-of-birth:
    name: profile-date-of-birth
    conditions: {}
    status: always-active
  remember-password-option:
    name: remember-password-option
    conditions: {}
    status: inactive

有关配置语义的详细信息,请参阅 Qandidate 的 Toggle 库 文档。

小型 REST API

此外,您可以在 Silex 应用程序中挂载 FeatureTogglesControllerProvider 以添加一个小型 REST API,该 API 通过挂载暴露开关的状态。这可能对于手动检查或当需要解耦的前端上的开关状态时非常有用。

$app->mount('/', new \TwoDotsTwice\SilexFeatureToggles\FeatureTogglesControllerProvider());

对 /toggles 的请求将返回一个 JSON 响应。以下是响应体的一个示例

{
    "profile-date-of-birth": true,
    "remember-password-option": false
}

true 表示开关当前处于开启状态,false 表示处于关闭状态。