laravel / pennant

A simple, lightweight library for managing feature flags.
https://laravel.com/docs/pennant
MIT License
482 stars 49 forks source link

[1.x] Ensure values returns feature name #107

Closed timacdonald closed 5 months ago

timacdonald commented 5 months ago

fixes https://github.com/laravel/pennant/issues/106

There is an inconsistency when retrieving a list of specific values with Pennant.

When you have a class-based feature that has a name, e.g, $name = 'my-feature';, the Feature::values function will inconstantly return the name and the feature's classname.

Given the following class...

namespace App\Features;

class MyFeature
{
    public $name = 'my-feature';

    // ...
}

We see the inconsistency in the last call to Feature::values:

Feature::all();

// ✅
// 
// [
//     'my-feature' => true,
// ]

Feature::values(['my-feature']);

// ✅
// 
// [
//     'my-feature' => true,
// ]

Feature::values([Myfeature::class]);

// ❌
// 
// [
//     'App\Features\MyFeature' => true,
// ]

Given the main usecase for the Feature::values function is to pass features to the front end...

<script>
const features = @js(Feature::values(['feature-1', 'feature-2']))
</script>

<div v-if="features['feature-1']>
    <!-- ... -->
</div>

...and the main usecase for the $name is to decouple the database and front end from the back end implementation, this feels like a bug that we should address.

github-actions[bot] commented 5 months ago

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.