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": "cb6deac3-782f-4938-ab64-335332d7dc54",
    "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": {
        "263a8674-a7d2-4b65-a67e-e25f97aa1a95": {
            "id": "263a8674-a7d2-4b65-a67e-e25f97aa1a95",
            "weight": 1,
            "async": false,
            "active": true,
            "schema": "http:\/\/pvm.forma-pro.com\/schemas\/Transition.json",
            "to": "a_task"
        },
        "b0e09819-059c-4efa-acf9-2578cecae471": {
            "id": "b0e09819-059c-4efa-acf9-2578cecae471",
            "weight": 1,
            "async": false,
            "active": true,
            "schema": "http:\/\/pvm.forma-pro.com\/schemas\/Transition.json",
            "from": "a_task",
            "to": "b_task"
        }
    },
    "inTransitions": {
        "a_task": [
            "263a8674-a7d2-4b65-a67e-e25f97aa1a95"
        ],
        "b_task": [
            "b0e09819-059c-4efa-acf9-2578cecae471"
        ]
    },
    "outTransitions": {
        "a_task": [
            "b0e09819-059c-4efa-acf9-2578cecae471"
        ]
    }
}