laravel / pennant

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

[1.x] Add ability to resolve feature instance. #118

Closed timacdonald closed 1 month ago

timacdonald commented 1 month ago

This PR gives the ability to resolve the implementation of the feature.

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

    // ...
}

Feature::define(MyFeature::class);

$instance = Feature::instance('my-feature');
$instance = Feature::instance(MyFeature::class);

The instance method will return either an instance of the feature class, a lottery, or a closure. The tests give a good rundown of when each of these might occur.