Giter Site home page Giter Site logo

laravel-feature-toggle's Introduction

Laravel Feature Toggle

This package allows for easy and efficient feature flag managment in Laravel. Features include:

  • Definition of feature toggles per environment (e.g. local, dev, stage, production).
  • Managable way to keep flags in source control without becomming overwhelming.
  • Creation of a default setting per feature that will be used if the environment specific setting is not found.
  • Ability to easily request the status of a feature and automatically get the correct setting based on the current environment the application is running on.
  • Ability to tag features as eligable for Javascript export.
  • A helper method to easily export Javascript eligable feature flags and pass them along to your front-end framework.

Installation

Add the package to your project:

composer require kirschbaum/laravel-feature-flag

Add the following service provider:

// config/app.php

'providers' => [
    ...
    Kirschbaum\LaravelFeatureFlag\ServiceProvider::class,
    ...
];

This package also comes with a facade, making it easy to retrieve the correct flags for the environment you are in:

// config/app.php

'aliases' => [
    ...
    'FeatureFlag' => Kirschbaum\LaravelFeatureFlag\Facades\FeatureFlag::class,
    ...
]

Publish the config file using the arisan command:

php artisan vendor:publish --provider="Kirschbaum\LaravelFeatureFlag\ServiceProvider"

The configuration looks like this:

<?php

return [

    'feature-1' => [
        'environments' => [
            'default'  => false,
            'local'    => true,
            'dev'      => false,
            'stage'    => false
        ],
        'js_export'    => true,
    ],

    'feature-2' => [
        'environments'   => [
            'default'    => false,
            'production' => true,
        ],
        'js_export'      => true,
    ],

];

Usage

General PHP use:

if(FeatureFlag::isEnabled('feature-1'))
{
    // Only do stuff if feature is enabled.
}

If you need to pass your feature flags to a front-end JS framework like Angular or Vue.js, you can do so by using the getJavascriptFlags() method:

$js->put(
            [
                'pusher_public_key' => env('PUSHER_PUBLIC'),
                'feature_flags'     => FeatureFlag::getJavascriptFlags()
            ]
        );

Because not all feature flags should be passed to the front-end, only features with the setting 'js_export = true' will be included. The end result is a simple array of features with the correct flags for the environment:

array:2 [▼
  "feature-1" => true
  "feature-2" => false
]

laravel-feature-toggle's People

Contributors

kirschbaum avatar

Stargazers

James Anelay avatar Peter Brinck avatar Tautvydas avatar Chris Baigorri avatar Alessandro Del Gobbo avatar suvilicious avatar Mark Thompson avatar Luis Gonzalez avatar John Baird avatar

Watchers

James Cloos avatar  avatar

Forkers

espadav8

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.