dev-master / 0.x-dev 2016-01-12 15:18 UTC


Build Status

Service provider

Register the FeatureTogglesProvider with your Silex application. $featureToggleConfiguration should be an array with the toggle configuration. You can for example retrieve this from a configuration file, but how to handle that is up to your application.

    new \TwoDotsTwice\SilexFeatureToggles\FeatureTogglesProvider(

At 2dotstwice, we've been successfully using this together with DerAlex's YamlConfigServiceProvider.

$app->register(new \DerAlex\Silex\YamlConfigServiceProvider(__DIR__ . '/config.yml'));

    new \TwoDotsTwice\SilexFeatureToggles\FeatureTogglesProvider(

The contents of config.yml might look like this:

    name: profile-date-of-birth
    conditions: {}
    status: always-active
    name: remember-password-option
    conditions: {}
    status: inactive

For details on the configuration semantics, consult the documentation of Qandidate's (Toggle library){https://github.com/qandidate-labs/qandidate-toggle].


Additionally, you can add a small REST API which exposes the state of the toggles by mounting the FeatureTogglesControllerProvider in your Silex application. This might be useful for manual inspection, or when the state of the toggles is needed on a decoupled front-end.

$app->mount('/', new \TwoDotsTwice\SilexFeatureToggles\FeatureTogglesControllerProvider());

A request to /toggles will return a JSON response. An example of a response body:

    "profile-date-of-birth": true,
    "remember-password-option": false

true means the toggle is currently ON, false means it is OFF.