PHP code example of switchover / php-sdk

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

    

switchover / php-sdk example snippets


// create a client, per default the client will cache the toggles 60 seconds
$client = new SwitchoverClient('<SDK-KEY');

//get some toggle values
$featureValue = $client->toggleValue('<TOGGLE-NAME>', false);

//or with context if you have specific (user) conditions
$context = new Context();
$context->set('email', '[email protected]');

$isFeatureVisible = $client->toggleValue('<OTHER-FLAG>', false, $context);

if ($isFeatureVisible) {
    // ...do something
}

$ctx = new Context([
    "email" => "[email protected]"
]);

$isFeatureEnabled = $client->toggleValue('my-big-feature', false, $ctx);


/* Feature flag has rollout options so we must provide a uuid.
   Here we use the email */
$ctx = new Context([
    "uuid" => "[email protected]"
]);

$client = new SwitchoverClient('<SDK-KEY', [
    'cache.time' => 10,
    'http' => [
        'timeout' => '10',
        'proxy' => 'http://proxy.tld'
    ]
]);
bash
composer