1. Go to this page and download the library: Download phputil/flags library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phputil / flags example snippets
use phputil\flags\FlagManager;
// By default, it uses a storage-based strategy with an in-memory storage
$flag = new FlagManager();
if ( $flag->isEnabled( 'my-cool-feature' ) ) {
echo 'Cool feature available!', PHP_EOL;
} else {
echo 'Not-so-cool feature here', PHP_EOL;
}
// ...
use phputil\flags\FlagVerificationStrategy;
$flag = new FlagManager();
$myLuckBasedStrategy = new class implements FlagVerificationStrategy {
function isEnabled( string $flag ): bool {
return rand( 1, 100 ) >= 50; // 50% chance
}
};
if ( $flag->isEnabled( 'my-cool-feature', [ $myLuckBasedStrategy ] ) ) {
echo 'Cool feature available!', PHP_EOL;
} else {
echo 'Not-so-cool feature here', PHP_EOL;
}
$flag = new FlagManager( null, [ $myLuckBasedStrategy ] );
if ( $flag->isEnabled( 'my-cool-feature' ) ) {
...