Skip to content

Instantly share code, notes, and snippets.

@Potherca
Last active January 17, 2024 00:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Potherca/45d8cc8e2d955a865ed0f03b86c070dd to your computer and use it in GitHub Desktop.
Save Potherca/45d8cc8e2d955a865ed0f03b86c070dd to your computer and use it in GitHub Desktop.
Feature Toggles in PHP

If you look on Packagist, the most popular packages for Feature toggles are:

  1. qandidate/toggle "Feature toggling for your PHP application." (⬇️ 496.754 / ⭐ 362)
  2. opensoft/rollout "Feature switches or flags for PHP" (⬇️ 354.269 / ⭐ 215)
  3. flagception/flagception "Feature toggle on steroids." (⬇️ 139 265 / ⭐ 24)
  4. joshuaestes/feature-toggle "Provides feature toggle functionality" (⬇️ 61.736 / ⭐ 32)
  5. zumba/swivel "Strategy driven feature toggles" (⬇️ 49.954 / ⭐ 211)

Downloads Stars

Class API

These packages have the following class API:

qandidate/toggle

https://github.com/qandidate-labs/qandidate-toggle

$manager = new ToggleManager($features);
$manager->add(new Toggle('my_feature', $condition));

$manager->active('my_feature', $context)

opensoft/rollout

https://github.com/opensoft/rollout

$toggle = new Rollout($features);

$toggle->isActive('my_feature');
$toggle->isActive('my_feature', $context);

flagception/flagception

https://github.com/bestit/flagception-sdk

$manager = new FeatureManager($features);

$manager->isActive('my_feature');
$manager->isActive('my_feature', (new Context())->add('my_feature', $context));

joshuaestes/feature-toggle

https://github.com/JoshuaEstes/FeatureToggle

$manager = new FeatureContainer();
$manager->addFeature(FeatureBuilder::create('my_feature')->getFeature());

$manager->hasFeature('my_feature')->isEnabled();

zumba/swivel

https://github.com/zumba/swivel

$manager = new Manager(new Config($features, $bucket));
$manager->forFeature('my_feature');

Bonus!

Because it was one of the first, I'll also add etsy/feature

https://github.com/etsy/feature

Feature::isEnabled('my_feature')
Feature::variant('my_feature')
Feature::isEnabledFor('my_feature', $context)
Feature::variantFor('my_feature', $context)

Commonalities

The most common patterns seem to be to have either a FeatureToggle or Collection/Manager of FeatureToggles. Either of which can be asked for a specific feature to be active, optionally given a specific context. (Variants and Buckets are not in scope of this comparison yet).

The following are all more or less synonimous:

  • active
  • isActive
  • isEnabled

Comparing these (either by stars or downloads) "active" seem to be the winner over "feature.

Downloads Stars

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment