Feature toggling lets you turn features on and off by changing a configuration setting. This library allows simple Boolean feature toggles, feature toggles based on the result of a function, and feature toggles based on the current environment.
Checkout the code to your library directory:
cd libraries
git clone https://github.com/michaeltwofish/li3_features.git
Include the library in in your /app/config/bootstrap/libraries.php
Libraries::add('li3_features');
Add feature detectors to your app in config/bootstrap/features.php
(or
somewhere that makes sense for you).
Named features are added using Features::add()
along with their detector,
which decides whether the feature should be active for the current request.
Features can be turned on or off with a simple Boolean detector, calculated in
some way with a closure detector, or be sensitive to the current environment by
passing an array of environment and detector pairs.
// `config/bootstrap/features.php`
Features::add('new_ui', true);
// `controllers/Main.php`
if (Features::check('new_ui')) {
$template = 'add_new_ui';
} else {
$template = 'add';
}
$this->render(compact('template'));
// `config/bootstrap/features.php`
Features::add('new_ui', function() {
// Logic here to decide if the feature should be enabled.
// Return true to enable and false to disable.
}
);
// `config/bootstrap/features.php`
Features::add('new_ui', array(
'production' => false,
'development' => true,
'staging' => function() {
// Logic here to decide if the feature should be enabled.
}
));
The original author of this library.
Github: michaeltwofish
Website: Twofish Creative