Giter VIP home page Giter VIP logo

laravel-unleash's Introduction

Laravel Unleash

Codacy Badge Packagist Build Status codecov

An Unleash client for Laravel.

Installation

composer require mikefrancis/laravel-unleash

Export package config:

php artisan vendor:publish --provider="MikeFrancis\LaravelUnleash\ServiceProvider"

Configuration

Documentation for configuration can be found in config/unleash.php.

Usage

use \MikeFrancis\LaravelUnleash\Unleash;

$unleash = app(Unleash::class);

if ($unleash->isFeatureEnabled('myAwesomeFeature')) {
  // Congratulations, you can see this awesome feature!
}

if ($unleash->isFeatureDisabled('myAwesomeFeature')) {
  // Check back later for more features!
}

$feature = $unleash->getFeature('myAwesomeFeature');

$allFeatures = $unleash->getFeatures();

Facades

You can use the Unleash facade:

use Unleash;

if (Unleash::isFeatureEnabled('myAwesomeFeature')) {
  // Congratulations, you can see this awesome feature!
}

if (Unleash::isFeatureDisabled('myAwesomeFeature')) {
  // Check back later for more features!
}

$feature = Unleash::getFeature('myAwesomeFeature');

$allFeatures = Unleash::getFeatures();

or use the generically named Feature facade:

use Feature;

if (Feature::enabled('myAwesomeFeature')) {
  // Congratulations, you can see this awesome feature!
}

if (Feature::disabled('myAwesomeFeature')) {
  // Check back later for more features!
}

$feature = Feature::get('myAwesomeFeature');

$allFeatures = Feature::all();

Dynamic Arguments

If your strategy relies on dynamic data at runtime, you can pass additional arguments to the feature check functions:

use \MikeFrancis\LaravelUnleash\Unleash;
use Config;

$unleash = app(Unleash::class);

$allowList = config('app.allow_list');

if ($unleash->isFeatureEnabled('myAwesomeFeature', $allowList)) {
  // Congratulations, you can see this awesome feature!
}

if ($unleash->isFeatureDisabled('myAwesomeFeature', $allowList)) {
  // Check back later for more features!
}

Blade

Blade directive for checking if a feature is enabled:

@featureEnabled('myAwesomeFeature')
Congratulations, you can see this awesome feature!
@endfeatureEnabled

Or if a feature is disabled:

@featureDisabled('myAwesomeFeature')
Check back later for more features!
@endfeatureDisabled

You cannot currently use dynamic strategy arguments with Blade template directives.

Middleware

This package includes middleware that will deny routes depending on whether a feature is enabled or not.

To use the middle, add the following to your app/Http/Kernel.php:

protected $routeMiddleware = [
    // other middleware
    'feature.enabled' => \MikeFrancis\LaravelUnleash\Middleware\FeatureEnabled::class,
    'feature.disabled' => \MikeFrancis\LaravelUnleash\Middleware\FeatureDisabled::class,
];

You can then use the middleware in your routes:

Route::get('/new-feature-path', function () {
    //
})->middleware('feature.enabled:myAwesomeFeature');

Route::get('/terrible-legacy-path', function () {
    //
})->middleware('feature.disabled:myAwesomeFeature');

or in your controllers like so:

class ExampleController extends Controller
{
    public function __construct()
    {
        $this->middleware('feature.enabled:myAwesomeFeature');
        // or
        $this->middleware('feature.disabled:myAwesomeFeature');
    }
}

You cannot currently use dynamic strategy arguments with Middleware.

laravel-unleash's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

laravel-unleash's Issues

Feature flags during test execution

Is there any way to override all feature flags to be enabled during (offline) test execution? Currently, when laravel-unleash is set to disabled, everything acts like all flags are disabled which leads to failing tests.

Transfer ownership

Quick checklist of things to do after transferring this repo to an org:

  • Remove myself from namespace and do a breaking change
  • Check Packagist

Anything else?

Incompatible with Pest pestphp/pest (v1.20)

Having this package installed seems to throw the following exception for us when we run our test suite via ./vendor/bin.pest:

In TestSuite.php line 196: Object of class Illuminate\Foundation\Application could not be converted to string

PHP 8.0.11
laravel/framwork v.8.65.0
pestphp/pest v1.20

idea: reload cache when its about to expire in __destruct()

Currently when the cache is expired (every 15 sec), unleash needs to repopulate it.
In our case this causes a 200-300 ms delay on the total request.
Also on high traffic websites its possible that multiple users are making the same request at (almost) the same time.

I've tested with a simple mechanism that sets an "expires_at" timestamp, and a few seconds before the timestamp is reached it will refresh the cache with new data.
Because the refresh happens in the __destruct(), the user that triggers the refresh does not notice any delays.

Would you accept a PR for such a mechanism?

Target [GuzzleHttp\ClientInterface] is not instantiable

Hi I am trying to use unleash following the instructions given. Installed via composer and publish the config with artisan. However, I am running an error when trying to use the unleash class:

$unleash = app(Unleash::class); $features = $unleash->getFeatures();

This is the error I run to

Target [GuzzleHttp\ClientInterface] is not instantiable while building [MikeFrancis\LaravelUnleash\Unleash].

I am running laravel "v5.8.37".

Would you help point out what I'm doing wrong? please kindly help :)

Allow versions of Laravel 8

Follow by installation guidelines and then getting an error. Please update to support Laravel 8. Thank you so much. <3

image

Update for laravel framework ^7

I am trying to install the unleash but I am running into errors with the composer require mikefrancis/laravel-unleash. The application I am integrating with is using laravel framekwork ^7 in the composer.json. Unfortunately I am not able to downgrade this web app to use ^6 of laravel as it will cause a lot of issues.

More specifically I am getting the error below.

Would you be able to update this to be compatible with laravel ^7?

Using version ^0.2.2 for mikefrancis/laravel-unleash
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for mikefrancis/laravel-unleash ^0.2.2 -> satisfiable by mikefrancis/laravel-unleash[v0.2.2].
    - Conclusion: remove laravel/framework v7.17.2
    - Conclusion: don't install laravel/framework v7.17.2
    - mikefrancis/laravel-unleash v0.2.2 requires illuminate/http ^5.8|^6 -> satisfiable by laravel/framework[6.x-dev], illuminate/http[5.8.x-dev, 6.x-dev, v5.8.0, v5.8.11, v5.8.12, v5.8.14, v5.8.15, v5.8.17, v5.8.18, v5.8.19, v5.8.2, v5.8.20, v5.8.22, v5.8.24, v5.8.27, v5.8.28, v5.8.29, v5.8.3, v5.8.30, v5.8.31, v5.8.32, v5.8.33, v5.8.34, v5.8.35, v5.8.36, v5.8.4, v5.8.8, v5.8.9, v6.0.0, v6.0.1, v6.0.2, v6.0.3, v6.0.4, v6.1.0, v6.10.0, v6.11.0, v6.12.0, v6.13.0, v6.13.1, v6.14.0, v6.15.0, v6.15.1, v6.16.0, v6.17.0, v6.17.1, v6.18.0, v6.18.1, v6.18.10, v6.18.11, v6.18.12, v6.18.13, v6.18.14, v6.18.15, v6.18.16, v6.18.17, v6.18.18, v6.18.19, v6.18.2, v6.18.20, v6.18.21, v6.18.22, v6.18.3, v6.18.4, v6.18.5, v6.18.6, v6.18.7, v6.18.8, v6.18.9, v6.2.0, v6.3.0, v6.4.1, v6.5.0, v6.5.1, v6.5.2, v6.6.0, v6.6.1, v6.6.2, v6.7.0, v6.8.0].
    - Can only install one of: laravel/framework[6.x-dev, v7.17.2].
    - don't install illuminate/http 5.8.x-dev|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.0|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.11|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.12|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.14|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.15|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.17|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.18|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.19|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.2|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.20|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.22|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.24|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.27|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.28|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.29|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.3|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.30|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.31|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.32|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.33|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.34|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.35|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.36|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.4|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.8|don't install laravel/framework v7.17.2
    - don't install illuminate/http v5.8.9|don't install laravel/framework v7.17.2
    - don't install illuminate/http 6.x-dev|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.0.0|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.0.1|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.0.2|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.0.3|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.0.4|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.1.0|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.10.0|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.11.0|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.12.0|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.13.0|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.13.1|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.14.0|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.15.0|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.15.1|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.16.0|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.17.0|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.17.1|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.0|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.1|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.10|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.11|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.12|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.13|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.14|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.15|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.16|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.17|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.18|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.19|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.2|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.20|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.21|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.22|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.3|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.4|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.5|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.6|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.7|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.8|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.18.9|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.2.0|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.3.0|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.4.1|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.5.0|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.5.1|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.5.2|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.6.0|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.6.1|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.6.2|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.7.0|don't install laravel/framework v7.17.2
    - don't install illuminate/http v6.8.0|don't install laravel/framework v7.17.2
    - Installation request for laravel/framework (locked at v7.17.2, required as ^7) -> satisfiable by laravel/framework[v7.17.2].

Cannot find JsonException (laravel 7)

I've freshly installed Unleash on Laravel 7 and looking to use gitlab's featureFlagging.

Following https://github.com/mikefrancis/laravel-unleash

With the following implementation:

<?php

namespace App\Http\Controllers;

use MikeFrancis\LaravelUnleash\Facades\Unleash;

class FeatureFlagController extends Controller
{
    /**
     * @return mixed
     */
    public function __invoke()
    {
        return ['features' => Unleash::getFeatures()];
    }
}

I get the following error:

Class 'Symfony\Component\HttpFoundation\Exception\JsonException' not found at /var/www/my-site/vendor/mikefrancis/laravel-unleash/src/Unleash.php:135)

if I edit src/Unleash.php and replace with:

use JsonException;

I no longer get the error but dont see any features either.

I've found the the following issue: https://gitlab.com/gitlab-org/gitlab/-/issues/260612 which mentions about passing in app_name but can't see how to do this within laravel implementation.

Any pointers would be appreciated.

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.