mohamedahmed01/feature-flag

使用简单命令轻松开启和关闭功能

v1.0.2 2023-04-22 21:56 UTC

This package is auto-updated.

Last update: 2024-10-03 17:03:21 UTC


README

Feature Flag

Build Status Latest Stable Version License

简介

功能标志 是在您的不同 Laravel 环境中启用和禁用功能的最简单方式,它还允许您进行 A/B 测试,并支持具有 不同 功能集的 用户

安装

  • 使用 composer 添加包
    composer require mohamedahmed01/feature-flag
  • 发布配置
    php artisan vendor:publish --provider="Mohamedahmed01\FeatureFlag\FeatureFlagServiceProvider" --tag="config"
  • 在 Laravel 版本 < 5.4 的情况下,您需要手动在 config/app.php 中添加 facade,因为 facade 将自动通过 composer 加载
   'FeatureFlag'=> Mohamedahmed01\FeatureFlag\FeatureFlagFacade::class

使用

    //Feature Flagging can be simple done by creating the flag
    $featureFlag = new FeatureFlag([
            'name' => 'test',
            'description' => 'Test feature flag',
        ]);
    $featureFlag->save();
    
    //using the flag to scope your your code using if condition or any other way you like
    if ($featureFlag->isEnabled()) {
        // Implement the feature for the user
    }

    //or you can use the method Targted and checking the audience to match to specific audience
    if($featureFlag->isTargeted() && in_array($user->id, $featureFlag->getAudience())) {
        // Implement the feature for the user
    }

    //Feature Flagging can be also used to target users based on percentage
    $featureFlag = new FeatureFlag([
            'name' => 'test',
            'description' => 'Test feature flag',
            'percentage'=>50
        ]);
    $featureFlag->save();
    // you can use the method isEnabledForUser and checking the audience to match to specific audience i.e 50%
    if($featureFlag->isEnabledForUser($user)) {
        // Implement the feature for the user
    }
    //Feature Flagging can be also used to flag based on datetime 
    $featureFlag = new FeatureFlag([
            'name' => 'test flag',
            'finish_date' => '01/04/2023',
            'enabled' => true,
        ]);
    $featureFlag->save();
    // you can use the env either to throw an exception or send a notification when flag expires
    if($featureFlag->isEnabled()) {
        // Implement the feature for the user
    }
    //then simply call feature-flag:manage followed by the name of your flag to enable Or disable it 
    php artisan feature-flag:manage {flag : The name of the feature flag} 
    {--enable : Enable the feature flag} {--disable : Disable the feature flag}

配置

方法

贡献

感谢您考虑为 Feature-Flag 贡献!您可以在 这里 阅读贡献指南。

测试

composer test

安全性

如果您发现任何与安全性相关的问题,请通过电子邮件 mohamedabdelmenem01@gmail.com 联系,而不是使用问题跟踪器。

许可证

Feature-Flag 是开源软件,使用 MIT 许可证 许可。