Giter Site home page Giter Site logo

ylsideas / feature-flags Goto Github PK

View Code? Open in Web Editor NEW
596.0 12.0 37.0 212 KB

A Laravel package for handling feature flags

Home Page: https://feature-flags.docs.ylsideas.co/

License: MIT License

PHP 99.93% Blade 0.07%
feature-flags hacktoberfest laravel php feature feature-toggles dark-launch dark-launching laravel-feature-flags flags

feature-flags's People

Contributors

aand18 avatar erictendian avatar nessimabadi avatar peterfox avatar pierrebateau avatar uintaam avatar

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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

feature-flags's Issues

[Bug]: Documented but not implemented method

What happened?

There is a definition of this method on the Features Facade (YlsIdeas\FeatureFlags\Facades\Features) documentation:

Neither the manager class (YlsIdeas\FeatureFlags\Manager) nor any gateway implements this method.

How to reproduce the bug

Call:

\YlsIdeas\FeatureFlags\Facades\Features::all();

Package Version

2.0.2

PHP Version

8.1

Laravel Version

9.25.1

Which operating systems does with happen with?

Windows

Notes

No response

UPGRADE.md doesn't mention what to do with routes and YlsIdeas\FeatureFlags\Middleware\FeatureFlagState

What happened?

Hello ๐Ÿ‘‹ ,

From the UPGRADE.md file it is not clear what we should do with YlsIdeas\FeatureFlags\Middleware\FeatureFlagState.

In v1, we added the following line within the $routeMiddleware array in app/Http/Kernel.php like this:

    protected $routeMiddleware = [
        ...
        'feature' => \YlsIdeas\FeatureFlags\Middleware\FeatureFlagState::class,
    ];

FeatureFlagState doesn't exist anymore in v2.
What should we do with it as part of the v2 upgrade? Can we just remove it?

And will all our routes defined like in the example below continue to work seamlessly?

// routes/web.php

...

Route::prefix('some-page')->name('some-page.')->middleware('feature:some-feature')->group(function () {
  ...

Thanks!

How to reproduce the bug

Package Version

2.4.0

PHP Version

8.0.0

Laravel Version

9.0.0

Which operating systems have you found this bug with?

No response

Notes

No response

Library doesn't work in the testing environment

Hi all
I am facing an issue using this Library in the testing environment (feature test) I'm getting the following error:-
Unresolvable dependency resolving [Parameter #0 [ array $config ]] in class YlsIdeas\FeatureFlags\Repositories\InMemoryRepository

env:-
ylsideas/feature-flags = 1.4
laravel/framework = 6.2
php = 7.4

please advice
thanks

An artisan command to create a feature

It will be nice to get an artisan command that creates a feature.
This could be either through the php artisan feature:on or php artisan feature:off command, that the user is asked to create the feature if it doesn't exist. It could also be through a fresh command like php artisan feature:new or something

[Bug]: Error in 2.1.0 when using barryvdh/laravel-ide-helper generate command

What happened?

The Features::fake() method in version 2.1.0 causes a problem with installations using the barryvdh/laravel-ide-helper developer package to generate facade autocompletion for IDEs. Given the popularity of both packages I figured I would report it here.

Everything installs correctly, no dependency problems. But during the post-update scripts (which is the recommended setup by the package) there is an error when running the ide-helper:generate command.

"post-update-cmd": [
    "Illuminate\\Foundation\\ComposerScripts::postUpdate",
    "@php artisan ide-helper:generate --ansi",
    "@php artisan ide-helper:meta --ansi",
],

How to reproduce the bug

sail composer require barryvdh/laravel-ide-helper --dev
sail composer require ylsideas/feature-flags

Then try to run the generate command:

sail artisan ide-helper:generate

ArgumentCountError

  Too few arguments to function YlsIdeas\FeatureFlags\Facades\Features::fake(), 0 passed in /var/www/html/vendor/barryvdh/laravel-ide-helper/src/Alias.php on line 220 and exactly 1 expected

  at vendor/ylsideas/feature-flags/src/Facades/Features.php:38
     34โ–•     /**
     35โ–•      * Replace the bound instance with a fake.
     36โ–•      * @param array<string, bool|array> $flagsToFake
     37โ–•      */
  โžœ  38โ–•     public static function fake(array $flagsToFake): FeatureFake
     39โ–•     {
     40โ–•         static::swap($fake = new FeatureFake(static::getFacadeRoot(), $flagsToFake));
     41โ–•
     42โ–•         return $fake;

      +19 vendor frames
  20  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

Package Version

2.1.0

PHP Version

8.1.10

Laravel Version

9.45.1

Which operating systems does with happen with?

Linux

Notes

No response

dynamic flags

I am using Laravel Spark and different plans come with different features. As such it would be nice to be able to use your solution to be able to enable those features via routes/middleware/blade etc but instead of globally enabling disabling features I would need to enable them dynamically based on the user's spark plan. Is this something that you think would be feasible to add as a customization. Do you maybe already have some extension points for this?

regresson in 1.5.0

Using 1.4.2 with the following config works fine:

<?php

return [
    /*
    |--------------------------------------------------------------------------
    | default
    |--------------------------------------------------------------------------
    |
    | The repository to use for establishing a feature's on/off state.
    |
    */

    'default' => 'config',

    /*
    |--------------------------------------------------------------------------
    | Config Feature Switches
    |--------------------------------------------------------------------------
    |
    | This is a set of features to load into the config features repository.
    |
    */

    'feature' => [
        'api' => false,
        'api_score' => false,
        'api_check' => false,
    ],

    /*
    |--------------------------------------------------------------------------
    | Repositories
    |--------------------------------------------------------------------------
    |
    | Configures the different repository options
    |
    */

    'repositories' => [
        'config' => [
            'key' => 'features.feature',
        ],
    ],
];

However on 1.5.0 it seems like the default for some reason ends up being file and not config, which in turn results in the fascade always returning false for any feature.

updateOnResolve in Chain driver does nothing

I was looking at using this package and found that the updateOnResolve config option in the config file does nothing. I see there is code in the ChainRepository for handling this feature but it never gets called because the FeatureFlagsServiceProvider register method does not pass the config value through to the ChainRepository on creation.

I tried to enable this feature by modifying the FeatureFlagsServiceProvider to pass the config value and I think I quickly found the reason why this is not enabled. If you use this updateOnResolve feature to update the attempted drivers but then call turnOff or turnOn again the different locations get out of sync.

My question is was this purposely left out and if so is it because of this issue? If so, was there a reason to not just modify the turnOn and turnOff to store the feature state in all levels of the chain if updateOnResolve is enabled?

One solution to this may be to just make the state config option an array instead of a single string so we could tell it to store the values in multiple locations, then updateOnResolve would not really be necessary.

The main reason I'm asking is that I'd like to use the chain driver because I would expect reading from redis would be faster but I'd like to have something a little more permanent like the database driver to fallback on.

[Bug]: Wrong error message for missing .features.php file

What happened?

Shouldn't the error message in this file be:

file could not be found.

throw new \RuntimeException(sprintf('`%s` file could be found.', $this->file));

?

How to reproduce the bug

Upgrade to v2.4.0 from v1.5.0 without updating the config/features.php configuration and without creating the .features.php file in the project's root for the in_memory gateway.

Package Version

2.4.0

PHP Version

8.0.0

Laravel Version

9.0.0

Which operating systems does with happen with?

No response

Notes

No response

Gradual rollout functionality

Love this package! Great work!

I think it would be good if it was possible to gradually release a feature to x% of users. Maybe by specifying it in the app service provider or a config file and base it on either sessions or users to make it more permanent by adding a column to the users table that stores a json of activated/deactivated features.

Thoughts?

FeatureFlagState middleware doesn't work well when state is off

when I tried Route::get('/some', 'SomeController@show')->middleware('feature:some-feature,off,404')->name('some');, and this feature flag made true, I want a response to back with 404. But it doesn't.

YlsIdeas\FeatureFlags\Middleware\FeatureFlagState middleware has check() function defined by YlsIdeas\FeatureFlags\Support\StateChecking trait. This check() function return boolean, but it always returns true.

return $state !== 'off' || true;

Is it must be like below?
return $state !== 'off';

ChainRepository: turnOn/turnOff only store one repository

When using chain repository, only the repository set in store property is updated when turnOn/turnOff, but that change is not reflected when doing ->accessible() because some upstream repository may return an old value.

I think that turnOn and turnOff actions should be replicated in every repository. I'm using the following chain:

  • redis: a read cache to improve database access
  • database: can override default values if they are present
  • config: default values

With this setup, and choosing database as repository to store changes, I get redis still returning the previous values if I turn on or off any feature.

RedisRepository: all() fails if empty

If redis cache is empty (flushed), all() method fails because redis mget fails with an empty array.

The fix would be to check for empty list of keys before getting the actual content:

if (empty($keys)) {
    return [];
}

Vendor:publish --tag=config in Lumen ^8.0 fails with `Unable to locate publishable resources.`

I'd like to use this package in a Lumen 8.0 project.

The initial installation appears to work just fine, but when I move to the next stop, vendor:publish, I'm shown an error. I'm working in a clean branch off master:

$ composer require ylsideas/feature-flags
Using version ^1.5 for ylsideas/feature-flags
./composer.json has been updated
Running composer update ylsideas/feature-flags
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking ylsideas/feature-flags (1.5.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
92 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> TechnologyAdvice\Api\Composer\ComposerScripts::postUpdate
$ php artisan vendor:publish --provider="YlsIdeas\FeatureFlags\FeatureFlagsServiceProvider" --tag=config

Unable to locate publishable resources.
Publishing complete.

I'm comfortable working in Laravel but most of my time has been spent with an existing codebase, rather than being the one installing and configuring new packages. Is there something I'm doing wrong?

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.