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": "6c7069f4-e7cb-487b-8d11-9c6b6b63e438",
    "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": {
        "e9c41e5b-e9d6-4e73-85b5-1814dbe5f366": {
            "id": "e9c41e5b-e9d6-4e73-85b5-1814dbe5f366",
            "weight": 1,
            "async": false,
            "active": true,
            "schema": "http:\/\/pvm.forma-pro.com\/schemas\/Transition.json",
            "to": "a_task"
        },
        "17935b14-c990-49b7-bd5a-45b036e1e227": {
            "id": "17935b14-c990-49b7-bd5a-45b036e1e227",
            "weight": 1,
            "async": false,
            "active": true,
            "schema": "http:\/\/pvm.forma-pro.com\/schemas\/Transition.json",
            "from": "a_task",
            "to": "b_task"
        }
    },
    "inTransitions": {
        "a_task": [
            "e9c41e5b-e9d6-4e73-85b5-1814dbe5f366"
        ],
        "b_task": [
            "17935b14-c990-49b7-bd5a-45b036e1e227"
        ]
    },
    "outTransitions": {
        "a_task": [
            "17935b14-c990-49b7-bd5a-45b036e1e227"
        ]
    }
}