定制 mohamedahmed01/feature-flag 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mohamedahmed01/feature-flag

最新稳定版本:v1.0.2

Composer 安装命令:

composer require mohamedahmed01/feature-flag

包简介

easily switch on and off features using a simple command

README 文档

README

Feature Flag

Build Status Latest Stable Version License

Introduction

Feature Flag is the easiest way to enable and disable features on your different Laravel enviroments it also enable you to do A/B testing and supporting your users with different features sets.

Installtion

  • Adding the package using composer
    composer require mohamedahmed01/feature-flag
  • publishing configuration
    php artisan vendor:publish --provider="Mohamedahmed01\FeatureFlag\FeatureFlagServiceProvider" --tag="config"
  • Facade is automatically loaded using composer unless you have laravel version < 5.4 you will need to add the facade manually in config/app.php
   'FeatureFlag'=> Mohamedahmed01\FeatureFlag\FeatureFlagFacade::class

Usage

    //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}

Configuration :

Config Name Description
FEATURE_FLAG_DRIVER Allow you to change the backend driver currently support eleqount
FEATURE_FLAG_FINISH_DATE_ACTION Choose What to do when a date based feature flag expires options "exception,notification"
FEATURE_FLAG_NOTIFICATION_EMAIL set the email to receive on notifications in case you used notification option

Methods :

Method Description
getName() getthe name of the flag
getDescription() get the description of the flag
setEnabled(bool) enable the flag or disable it depending on the value
isEnabled() check if the flag is enabled or not
Targted() check if the flag has specific audience
setAudience(array) set the flag audience by sending array of user's id's i.e [1,2,3,4]
getAudience() get the audience id's of the users for this flag
isEnabledForUser($user) check random user for falling within the percentage

Contributing

Thank you for considering contributing to Feature-Flag! You can read the contribution guide here.

Testing

composer test

Security

If you discover any security related issues, please email mohamedabdelmenem01@gmail.com instead of using the issue tracker.

License

Feature-Flag is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 105
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-21