PHP code example of sepiariver / binliner-php

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

    

sepiariver / binliner-php example snippets


use SepiaRiver\Binliner;

class Bob
{
    // define bob
};
$bob = new Bob();
$ofAge = ($bob->age > 20);               // Postiion 0 in the sequence
$needsRetest = ($bob->age > 65);         // Position 1
$validLicense = ($bob->license.valid);   // Position 2
$passedTest = ($bob->test.results > 60); // Position 3

/**
 * Truth table
 * ofAge | needsRetest | validLicense | passedTest
 * 1 | 0 | 1 | 0 // of age, valid license, test result irrelevant
 * 1 | 0 | 1 | 1 // of age, valid license, test result irrelevant
 * 1 | 1 | 1 | 1 // of age, valid license, passed test
 *
 * ALL OTHER STATES ARE INVALID 
 */

$config = [
    'size' => 4,
    'validation' => ['1010', '1011', '1111'],
];
$binliner = new Binliner(
    $config,
    $ofAge,
    $needsRetest,
    $validLicense,
    $passedTest
);

if (!$binliner->isValid()) {
    // Reject
    throw new Exception('Invalid state!');
}
// Just for convenience you can reason about intval((string)$binliner, 2);
if ($binliner->toInt() < 12) {
    // Accept
    return true;
}
// The only remaining valid state is '1111'
return handlePassedRetest($bob);
cli
composer