Simple feature toggle handling with Symfony
Today I released me first Symfony bundel on GitHub: FeatureToggleBundle. With this bundle, you can handle simple feature toggles very easy on the backend and also via twig extension.
You can basically setup your feature toggles on the config.yml file in your app:
# app/config/config.yml
kukulili_labs_feature_toggle:
feature_toggles:
feature_toggles_name: # change it to the name of your feature toggle
state: enabled # change to disabled for disable your feature toggle
description: # this option is optional and will be used later
You can use the service on the controller like this:
if ($this->get('kukulili_labs_feature_toggle.feature_toggles')->isEnabled('feature_toggles_name')) {
...
}
or on the template site with the twig extension:
{% if feature_toggle_is_enabled('feature_toggles_name') %}
...
{% endif %}
If you want to dis-/enable a specific feature toggle on a session (like for a test), you can use the service again:
$this->get('kukulili_labs_feature_toggle.feature_toggles')->disableForSession('feature_toggles_name');
$this->get('kukulili_labs_feature_toggle.feature_toggles')->enableForSession('feature_toggles_name');
Have fun!