PHP code example of digital-gravy / feature-flag

1. Go to this page and download the library: Download digital-gravy/feature-flag 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/ */

    

digital-gravy / feature-flag example snippets


use DigitalGravy\FeatureFlag\FeatureFlagStore;
use DigitalGravy\FeatureFlag\Storage\KeyedArray;

// Create a feature flag store with array storage
$flags = new KeyedArray([
    'dark_mode' => 'on',
    'beta_feature' => 'off'
]);

$store = new FeatureFlagStore($flags->get_flags());

// Check if a feature is enabled
if ($store->is_on('dark_mode')) {
    // Dark mode is enabled
}

use DigitalGravy\FeatureFlag\Storage\JsonFile;

$flags = new JsonFile('/path/to/flags.json');
$store = new FeatureFlagStore($flags->get_flags());

use DigitalGravy\FeatureFlag\Storage\PHPConstant;

define('DARK_MODE', true);
define('BETA_FEATURE', 'off');

$flags = new PHPConstant(['DARK_MODE', 'BETA_FEATURE']);
$store = new FeatureFlagStore($flags->get_flags());

$store = new FeatureFlagStore(
    $jsonFlags->get_flags(),
    $constantFlags->get_flags(),
    $arrayFlags->get_flags()
);

use DigitalGravy\FeatureFlag\Storage\FlagStorageInterface;

class CustomStorage implements FlagStorageInterface {
    public function get_flags(): array {
        // Return array of FeatureFlag objects
    }
}