PHP code example of deseretdigital / knobby

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

    

deseretdigital / knobby example snippets




$config = array(
    array(
        'name' => 'exampleOn',
        'on' => true,
        'type' => 'lever',
    ),
    array(
        'name' => 'exampleOff',
        'on' => false,
        'type' => 'lever',
    ),
);

$knobby = new \DDM\Knobby\Knobby();
$knobby->loadConfigArray($config);

if ($knobby->test('exampleOn')) {
    /*
    feature code here will run as the lever is on
    */
}

if ($knobby->test('exampleOff')) {
    /*
    feature code here will not run as the lever is off
    */
}



$config = array(
    array(
        'name' => 'testKnob',
        'type' => 'knob',
        'value' => 15,
    ),
);

$knobby = new \DDM\Knobby\Knobby($config);

$userValue = 20;
if ($knobby->test('testKnob', $userValue)) {
    /*
    feature code here will not run, since the
    user value is greater than the allowed value
    */
}



$config = array(
    array(
        'name' => 'testKnob',
        'type' => 'knob',
        'min' => '10',
        'max' => '50',
        'value' => 15,
    ),
);

$knobby = new \DDM\Knobby\Knobby($config);

if ($knobby->test('testKnob')) {
    /*
    feature code here may or may not run depending on the value of the randomly
    generated test value between 10 and 50.
    */
}