Download the PHP package em411/feature-flag-bundle without Composer
On this page you can find all versions of the php package em411/feature-flag-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download em411/feature-flag-bundle
More information about em411/feature-flag-bundle
Files in em411/feature-flag-bundle
Package feature-flag-bundle
Short Description Provides a feature flag mechanism (Symfony 4.4 / PHP 7.4 backport)
License MIT
Homepage https://github.com/em411/feature-flag-bundle
Informations about the package feature-flag-bundle
FeatureFlag Bundle
The FeatureFlag Bundle allows you to split the code execution flow by enabling features depending on context.
It provides a service that checks if a feature is enabled. Each feature is defined by a callable function that returns a value. The feature is enabled if the value matches the expected one (mostly a boolean but not limited to).
This bundle code has been borrowed from https://github.com/symfony/symfony/pull/53213.
Symfony 4.4 / PHP 7.4 backport. This is a fork of ajgarlag/feature-flag-bundle refactored to run on Symfony 4.4 and PHP 7.4.
Which package should I use?
- Running Symfony 6+ / PHP 8.1+? Use the upstream
ajgarlag/feature-flag-bundle— it targets modern Symfony and uses native PHP 8 attributes. - Stuck on Symfony 4.4 / PHP 7.4? Use this fork. It exists because the upstream cannot run on legacy stacks. The public API is intentionally kept compatible with the upstream so migration is a namespace-free drop-in.
Note on the namespace. The Composer package is
em411/feature-flag-bundlebut the PHP namespace remainsAjgarlag\FeatureFlagBundle\on purpose, so code written against the upstream works here unchanged. Imports and the bundle class reference (Ajgarlag\FeatureFlagBundle\FeatureFlagBundle::class) stay the same.
🚀 Getting Started
Follow these steps to install and use the bundle in your Symfony application.
Step 1: Download the bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
Step 2: Enable the bundle (for non-Flex applications)
Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php file of your project:
✨ Declaring features with annotations
You can declare features using the @AsFeature annotation. This allows you to autoconfigure your features as services.
On a class
You can use the annotation on an invokable class:
The feature will be named xmas. If you don't provide a name, the FQCN of the class will be used.
You can also use the method property of the annotation to specify a method to call on the service.
On a method
You can also use the annotation on a method of a service. The method must be public.
Note: Unlike PHP 8 attributes, a Doctrine annotation cannot be repeated on the same class or method. To declare multiple features on one class, use the
ajgarlag.feature_flag.featureservice tag.
Gating routes by a feature
Symfony 4.4 cannot evaluate services inside route condition expressions, so
route-level feature gating is done in the controller (or a kernel.controller
listener). Inject FeatureCheckerInterface and throw a 404 when the feature is
off:
🧩 Providers
Providers are responsible for returning the feature callables. You can create your own provider by implementing the
ProviderInterface.
Any service that implements ProviderInterface is automatically registered as a provider. The bundle comes with a
ChainProvider that allows you to combine multiple providers. The first provider that returns a feature wins.
The ProviderInterface
To create your own provider, you need to implement the ProviderInterface.
The get method must return a callable if the provider has the feature, or null otherwise.
Doctrine example
Gitlab example
First, declare a service to interact with the [Unleash](https://www.getunleash.io/) API.Priority
You can control the order of the providers in the chain using the priority attribute of the
ajgarlag.feature_flag.provider tag.
Set the priority on the service tag in your configuration:
Providers with a higher priority will be checked first.
🎨 Twig extension
The bundle provides two functions to use in Twig templates: feature_is_enabled and feature_get_value.
All versions of feature-flag-bundle with dependencies
doctrine/annotations Version ^1.13
psr/container Version ^1.0
symfony/config Version ^4.4
symfony/dependency-injection Version ^4.4
symfony/http-kernel Version ^4.4
symfony/service-contracts Version ^1.1|^2.0