vespolina/workflow

Vespolina library for handling workflow

dev-master 2015-05-22 00:48 UTC

This package is auto-updated.

Last update: 2024-11-18 21:15:59 UTC


README

Build Status Total Downloads Latest Stable Version SensioLabsInsight Scrutinizer Quality Score Code Coverage Dependency Status

Workflow is a library that lets you first build a graph with places and transactions interconnecting them with arcs. And then lets you traverse the created workflow for any number of runs each identifiable via a token. The traversing starts on an input place node and ends in an output place node for a given workflow. Workflow uses a logger to log the flow traversing details.

The tokenable nodes can execute custom implementations. These custom implementations can be used to carry out flows on processes of a web application or other process based systems.

Install

composer require vespolina/workflow dev-master

Usage

Suppose we want a workflow like this:


  O -> [A] -> O -> [B] -> O
 in          p1          out

The code that implements and runs down on it would look like:

 <?php

use Vespolina\Workflow\Task\Automatic;
use Vespolina\Workflow\Place;
use Vespolina\Workflow\Workflow;
use Vespolina\Workflow\Token;
use Vespolina\Workflow\TokenInterface;
use Monolog\Logger;

class NodeA extends Automatic
{
    public function execute(TokenInterface $token)
    {
        if ($token->getData('autoB')) {
            return false;
        }
        $token->setData('autoA', true);

        return true;
    }
}

class NodeB extends Automatic
{
    public function execute(TokenInterface $token)
    {
        if (!$token->getData('autoA')) {
            return false;
        }
        $token->setData('autoB', true);

        return true;
    }
}

$logger = new Logger('test');
$workflow = new Workflow($logger);

// create sequence
$a = new NodeA();
$b = new NodeB();
$place = new Place();
$place->setWorkflow($workflow, $logger);

$workflow->addNode($a, 'a');
$workflow->addNode($place, 'p1');
$workflow->addNode($b, 'b');

$workflow->connectToStart('a');
$workflow->connect('a', 'p1');
$workflow->connect('p1', 'b');
$workflow->connectToFinish('b');

$workflow->accept(new Token());

And we will see the traversing in our logs:

... test.INFO: Token accepted into workflow {"token":"[object] (Vespolina\\Workflow\\Token: {})"} []
... test.INFO: Token advanced into workflow.start {"token":"[object] (Vespolina\\Workflow\\Token: {})"} []
... test.INFO: Token advanced into a {"token":"[object] (Vespolina\\Workflow\\Token: {})"} []
... test.INFO: Token advanced into p1 {"token":"[object] (Vespolina\\Workflow\\Token: {})"} []
... test.INFO: Token advanced into b {"token":"[object] (Vespolina\\Workflow\\Token: {})"} []
... test.INFO: Token advanced into workflow.finish {"token":"[object] (Vespolina\\Workflow\\Token: {})"} []