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": "405a4e47-46c0-4ea7-a977-1e8a8989bc9c",
    "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": {
        "125915bc-bba2-42cd-941a-7a5efe64dc54": {
            "id": "125915bc-bba2-42cd-941a-7a5efe64dc54",
            "weight": 1,
            "async": false,
            "active": true,
            "schema": "http:\/\/pvm.forma-pro.com\/schemas\/Transition.json",
            "to": "a_task"
        },
        "872374de-5095-4691-8840-dc289eb92795": {
            "id": "872374de-5095-4691-8840-dc289eb92795",
            "weight": 1,
            "async": false,
            "active": true,
            "schema": "http:\/\/pvm.forma-pro.com\/schemas\/Transition.json",
            "from": "a_task",
            "to": "b_task"
        }
    },
    "inTransitions": {
        "a_task": [
            "125915bc-bba2-42cd-941a-7a5efe64dc54"
        ],
        "b_task": [
            "872374de-5095-4691-8840-dc289eb92795"
        ]
    },
    "outTransitions": {
        "a_task": [
            "872374de-5095-4691-8840-dc289eb92795"
        ]
    }
}