PHP code example of featureswitches / featureswitches-php

1. Go to this page and download the library: Download featureswitches/featureswitches-php 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/ */

    

featureswitches / featureswitches-php example snippets




// Create a new FSClient with your customer and environment API key's
$featureswitches = new FeatureSwitches\FSClient('customer_api_key', 'environment_api_key', array('options'));

// Ensure that the API credentials are valid
$result = $featureswitches->authenticate();  # result will be true/false to indicate success

// Sync feature state
$featureswitches->sync();

// Add a user
$result = $featureswitches->addUser('user_identifier', 'optional_customer_identifier', 'optional_name', 'optional_email');

// Check if a feature is enabled
$result = $featureswitches->isEnabled('feature_key', 'optional_user_identifier', default(true/false, default=false));

if ($result == true) {
    // Feature enabled, do something
} else {
    // Feature disabled, do something else
}

array(
    'cache_timeout' => SECONDS, // optional, defaults to 300 seconds
)
bash
php composer.phar