2017 © Pedro Peláez
 

library procedure

introduces mechanism that allows you to define steps with its arguments that are going to be interpreted in order they are defined in the procedure

image

devhelp/procedure

introduces mechanism that allows you to define steps with its arguments that are going to be interpreted in order they are defined in the procedure

  • Thursday, September 25, 2014
  • by devhelp
  • Repository
  • 3 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Build Status SensioLabsInsight, (*1)

Installation

Composer is preferred to install devhelp/procedure, please check composer website for more information., (*2)

$ composer require 'devhelp/procedure:dev-master'

Purpose

devhelp/procedure introduces mechanism that allows you to define steps with its arguments that are going to be interpreted(*) in order they are defined in the procedure., (*3)

"interpreted" can mean, for example, "called" if such interpreter will be set to interpret the steps., (*4)

devhelp/procedure is shipped with CallableInterpreter, example usage is shown below., (*5)

Usage

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use Devhelp\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')

FAQ

How can I change interpretation

You can write own interpreter class and set it in ProcedureRunner. It has to implement Devhelp\Procedure\Interpreter\InterpreterInterface., (*6)

<?php

namespace Acme\Demo\Interpreter;


use Devhelp\Procedure\Model\Step;
use Devhelp\Procedure\Exception\StepInterpretationException;
use Devhelp\Procedure\Interpreter\InterpreterInterface;

class MyCustomInterpreter implements InterpreterInterface
{
    /**
     * {@inheritdoc}
     */
    public function interpret(Step $step, array $arguments)
    {
        /**
         * my custom logic that interprets the step
         */
    }
}

Credits

Brought to you by : Devhelp.pl (http://devhelp.pl), (*7)

The Versions

25/09 2014

dev-master

9999999-dev http://devhelp.pl

introduces mechanism that allows you to define steps with its arguments that are going to be interpreted in order they are defined in the procedure

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Paweł Barański
by devhelp.pl

25/09 2014

1.0

1.0.0.0 http://devhelp.pl

introduces mechanism that allows you to define steps with its arguments that are going to be interpreted in order they are defined in the procedure

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Paweł Barański
by devhelp.pl