Skip to content

2.2.7

Compare
Choose a tag to compare
@ilvalerione ilvalerione released this 17 Sep 07:54
· 30 commits to 2.x since this release

Typed Workflow State

This release supports the ability to use custom workflow state class, so you can work with strictly typed properties.

Create your state class extending the default WorkflowState:

use NeuronAI\Workflow\WorkflowState;

class CustomState extends WorkflowState
{
    public string $custom = 'custom property';
}

Use this custom state as input type of the nodes __invoke mthod:

class MyNode extends Node 
{
    public function __invoke(StartEvent $event, CustomState $state): StopEvent
    {
        echo $state->custom;

        return new StopEvent();
    }
}

Finally start the Workflow passing the custom state instance. It will be propagated through the nodes:

$workflow = Workflow::make(new CustomState())->addNode($node);
$state = $workflow->start()->getResult();