PHP code example of devhelp / procedure

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

    

devhelp / procedure example snippets




evhelp\Procedure\ProcedureRunner;
use Devhelp\Procedure\ArgumentResolver;
use Devhelp\Procedure\Interpreter\CallableInterpreter;
use Devhelp\Procedure\Model\Procedure;
use Devhelp\Procedure\Model\Step;
use Devhelp\Procedure\Model\Reference;

//example class
class Math
{
    public static function add($a, $b) {
        return $a + $b;
    }

    public static function mul($a, $b) {
        return $a * $b;
    }
}

/**
 * because we are using CallableInterpreter in the example, first argument
 * of step arguments is a callback
 */

$stepOne = new Step('add_1', array('Math::add', 1, 1));
//1 + 1 = 2 (store result as 'add_1')

$stepTwo = new Step('add_2', array('Math::add', 2, 2));
//2 + 2 = 4 (store result as 'add_2')

$stepThree = new Step('mul', array('Math::mul', new Reference('add_1'), new Reference('add_2')));
//2 * 4 = 8 (store result as 'mul')

$stepFour = new Step('dec2bin', array('decbin', new Reference('mul')));
//decbin(8) = '1000' (store result as 'dec2bin', but since this is last step it does not matter)

$procedure = new Procedure(array($stepOne, $stepTwo, $stepThree, $stepFour));


$argumentResolver = new ArgumentResolver();
$interpreter = new CallableInterpreter();

$runner = new ProcedureRunner();
$runner->setArgumentResolver($argumentResolver);
$runner->setInterpreter($interpreter);

echo $runner->follow($procedure), PHP_EOL; //returns result of last step ('1000')