mohamedahmed01/feature-flag

easily switch on and off features using a simple command

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

This package is auto-updated.

Last update: 2024-09-03 16:54:35 UTC


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 :

Methods :

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.