Clone and Modify

The example shows how one process could be cloned and adjusted.

Setup


mkdir ~/pvm-clone-and-modify
cd ~/pvm-clone-and-modify
composer req formapro/pvm:0.4.x-dev makasim/values:0.5.x-dev

# create such file with the code below
php clone-and-modify.php

Result

clone-and-modify.php


<?php
use Formapro\Pvm\ProcessBuilder;
use function 
Makasim\Values\clone_object;

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

$processToBeCloned = (new ProcessBuilder())
    ->
createNode('a_task''a_behavior')->end()
    ->
createStartTransition('a_task')->end()

    ->
getProcess()
;

$process clone_object($processToBeCloned);

(new 
ProcessBuilder($process))
    ->
createNode('b_task''a_behavior')->end()
    ->
createTransition('a_task''b_task')
;
{
    "schema": "http:\/\/pvm.forma-pro.com\/schemas\/Process.json",
    "id": "2b49c9a6-48b6-4ec0-b171-af965470b63d",
    "nodes": {
        "a_task": {
            "schema": "http:\/\/pvm.forma-pro.com\/schemas\/Node.json",
            "id": "a_task",
            "behavior": "a_behavior"
        },
        "b_task": {
            "schema": "http:\/\/pvm.forma-pro.com\/schemas\/Node.json",
            "id": "b_task",
            "behavior": "a_behavior"
        }
    },
    "transitions": {
        "608440ac-f4de-47e3-88f7-2a8fbb131d61": {
            "id": "608440ac-f4de-47e3-88f7-2a8fbb131d61",
            "weight": 1,
            "async": false,
            "active": true,
            "schema": "http:\/\/pvm.forma-pro.com\/schemas\/Transition.json",
            "to": "a_task"
        },
        "12349e9e-17d4-451c-a42b-fd0304d9eb5b": {
            "id": "12349e9e-17d4-451c-a42b-fd0304d9eb5b",
            "weight": 1,
            "async": false,
            "active": true,
            "schema": "http:\/\/pvm.forma-pro.com\/schemas\/Transition.json",
            "from": "a_task",
            "to": "b_task"
        }
    },
    "inTransitions": {
        "a_task": [
            "608440ac-f4de-47e3-88f7-2a8fbb131d61"
        ],
        "b_task": [
            "12349e9e-17d4-451c-a42b-fd0304d9eb5b"
        ]
    },
    "outTransitions": {
        "a_task": [
            "12349e9e-17d4-451c-a42b-fd0304d9eb5b"
        ]
    }
}