# Workflow

The Workflow component provides the ability to define a runtime execution based on the workflow pattern (opens new window). It allows to define a series of individual interconnected steps with goal to describe and execute a sequential procedure.

# Step

The Step component define an Action with arguments to pass.

use Chevere\Components\Workflow\Step;

new Step(action: 'SomeActionClass');

The argument passed must be a class name implementing the ActionInterface.

# Step Parameters

Parameters for the step are defined in the Action Parameters.

# Step Arguments

Arguments can be passed on constructor using named arguments.

use Chevere\Components\Workflow\Step;

new Step(
    'SomeActionClass'
    firstName: 'Rodolfo',
    lastName: 'Berrios'
);

For the code above, arguments Rodolfo and Berrios will be passed to SomeActionClass when running the Workflow. These arguments will be matched against the Parameters defined at the Action.

The withArguments method can be used to modify the step arguments.

# Creating a Workflow

To create a workflow pass the Workflow named steps:

use Chevere\Components\Workflow\Workflow;

$workflow = new Workflow(
    fetch: new Step(
        'FetchAction',
        payload: '${payload}'
    ),
);

For the code above, ${payload} is declared as a reference, the actual value for it should be provided by the WorkflowRunner.

# References

Referenced arguments can be used to bind arguments against Workflow variables or responses returned by any previous existing Step.

Expression Meaning
${var} A Workflow variable
${step:key} The response value at key for a previous Step

# Adding Steps

The withAdded method allows to add steps to a existing Workflow.

For the code below, steps validate and insert are using references for the expected response keys at fetch Step.

use Chevere\Components\Workflow\Step;

$workflow = $workflow
    ->withAdded(
        validate: new Step(
            'ValidateAction',
            email: '${fetch:email}',
            username: '${fetch:username}',
        ),
        insert: new Step(
            'InsertAction',
            email: '${fetch:email}',
            username: '${fetch:username}',
        )
    );

# Adding Steps Before and After

The withAddedBefore and withAddedAfter methods allows to add steps before/after another step.

For example, consider this existing flow:

  • Fetch
  • Validate
  • Insert

Requiring to extend to something like this:

  • +Logging
  • Fetch
  • Validate
  • +ValidateMore
  • Insert
  • +Caching
use Chevere\Components\Workflow\Step;

$workflow = $workflow
    ->withAddedBefore(
        'fetch',
        logging: new Step(
            'LoggingAction',
            device: '${logDevice}'
        )
    )
    ->withAddedAfter(
        'validate',
        validateMore: new Step(
            'ValidateMoreAction',
            payload: '${payload}'
        )
    )
    ->withAddedAfter(
        'insert',
        caching: new Step(
            'CachingAction',
            userId: '${insert:userId}'
        )
    );

# Workflow Dependencies

Workflow is aware of actions implementing the DependentInterface. All Action dependencies will be collected by the Workflow.

Use the method dependencies to get access to the dependencies for a given Workflow.

$workflow->dependencies();

🚧 Work in progress

  • WorkflowRun
  • Workflow provider