2017 © Pedro Peláez
 

library laravel-feature-toggle

Simple feature toggles for Laravel PHP and Javascript

image

kirschbaum/laravel-feature-toggle

Simple feature toggles for Laravel PHP and Javascript

  • Thursday, February 25, 2016
  • by Kirschbaum
  • Repository
  • 1 Watchers
  • 5 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Laravel Feature Toggle

This package allows for easy and efficient feature flag managment in Laravel. Features include:, (*1)

  • 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:, (*2)

composer require kirschbaum/laravel-feature-flag

Add the following service provider:, (*3)

// 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:, (*4)

// config/app.php

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

Publish the config file using the arisan command:, (*5)

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

The configuration looks like this:, (*6)

<?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:, (*7)

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:, (*8)

$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:, (*9)

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

The Versions

25/02 2016

dev-master

9999999-dev

Simple feature toggles for Laravel PHP and Javascript

  Sources   Download

The Requires

 

The Development Requires

by Nathan Kirschbaum

feature-flags feature-toggles toggles