Skip to content

This package aims to provide a fully-featured, yet simple feature flag configuration through environment variables for Laravel 8+

License

Notifications You must be signed in to change notification settings

rescaled/simple-feature

Repository files navigation

Simple Feature

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Simple Feature allows you to define feature flags via environment variables and check for their state within your Laravel application. It also provides pre-defined middleware you can utilize for this use case.

Installation

You can install the package via composer:

composer require rescaled/simple-feature

Usage

Define feature flags

Feature flags are defined in your environment file. They must be defined in snake case as well as being prefixed with FEATURE_.

FEATURE_FIRST_TEST=true
FEATURE_SECOND_TEST=true

FEATURE_THIRD_TEST=false
FEATURE_FOURTH_TEST=false

Direct usage

You can directly access the package's methods as following.

SimpleFeature::enabled('firstTest') // true
SimpleFeature::disabled('firstTest') // false
SimpleFeature::allEnabled(['firstTest', 'secondTest']) // true
SimpleFeature::allDisabled(['thirdTest', 'fourthTest']) // true
SimpleFeature::allEnabled(['firstTest', 'thirdTest']) // false
SimpleFeature::allDisabled(['firstTest', 'thirdTest']) // false

Middleware

The package comes with two middlewares that allow to check whether a given set of features is enabled or disabled.

// FEATURE_REGISTRATION=true
// FEATURE_ON_PREMISE=true

Route::get('/register', [RegistrationController::class, 'create'])->middleware('feature.enabled:registration');
Route::get('/billing', [BillingController, 'show'])->middleware('feature.disabled:onPremise');

If the feature hasn't the desired state the middleware will abort the request with a 404.

Blade

Furthermore, you can use conditional Blade directives to render content based on the state of a given feature flag.

@feature('registration')
    <a href="/register">Register</a>
@endfeature
@unlessfeature('onPremise')
...
@endunlessfeature

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

This package aims to provide a fully-featured, yet simple feature flag configuration through environment variables for Laravel 8+

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Languages