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": "a3f60b12-e23d-4c60-b1c6-855c686b1621",
    "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": {
        "4b53d2a0-b24a-45ce-a2e8-5b89e5139e41": {
            "id": "4b53d2a0-b24a-45ce-a2e8-5b89e5139e41",
            "weight": 1,
            "async": false,
            "active": true,
            "schema": "http:\/\/pvm.forma-pro.com\/schemas\/Transition.json",
            "to": "a_task"
        },
        "5ac6dc7c-653e-48f8-8f3c-90cfeb6106ca": {
            "id": "5ac6dc7c-653e-48f8-8f3c-90cfeb6106ca",
            "weight": 1,
            "async": false,
            "active": true,
            "schema": "http:\/\/pvm.forma-pro.com\/schemas\/Transition.json",
            "from": "a_task",
            "to": "b_task"
        }
    },
    "inTransitions": {
        "a_task": [
            "4b53d2a0-b24a-45ce-a2e8-5b89e5139e41"
        ],
        "b_task": [
            "5ac6dc7c-653e-48f8-8f3c-90cfeb6106ca"
        ]
    },
    "outTransitions": {
        "a_task": [
            "5ac6dc7c-653e-48f8-8f3c-90cfeb6106ca"
        ]
    }
}