Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Aug 7, 2024
Merged

Conversation

timacdonald
Copy link
Member

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.

@timacdonald timacdonald changed the title [11.x] Feature map [11.x] Add ability to resolve feature instance. Aug 6, 2024
@crynobone crynobone changed the title [11.x] Add ability to resolve feature instance. [1.x] Add ability to resolve feature instance. Aug 7, 2024
{
$feature = $this->nameMap[$name] ?? $name;

if (is_string($feature) && class_exists($feature)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be amazing if we could add an enum check here as well 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would that do, @cosmastech?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I misunderstood this, disregard:

Would love to have the ability to call Feature::define(FeatureFlagEnum::NewFeature, fn() => false), but maybe that's not really what this PR is aiming for.

@taylorotwell taylorotwell merged commit 07884ea into 1.x Aug 7, 2024
7 checks passed
@taylorotwell taylorotwell deleted the feature-map branch August 7, 2024 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants