yuna/flow

Maintainers

Details

codeberg.org/yuna/flow

Installs: 32

Dependents: 2

Suggesters: 0

Security: 0

pkg:composer/yuna/flow

2.0.2 2025-11-17 22:55 UTC

This package is not auto-updated.

Last update: 2025-11-17 22:56:31 UTC


README

Pipeline Builder in PHP.

Features:

  • easy to use interfaces
  • simple to use
  • reusable
  • configurable
  • fully in PHP (no other extension is supported)

Installation

composer require yuna/flow:^1

Features showcase

Below we can see simple example of usage - how to create pipeline and run it.

<?php

use Yuna\Flow\Config;
use Yuna\Flow\Context;
use Yuna\Flow\Environment;
use Yuna\Flow\FlowBuilder;
use Yuna\Flow\InlineStep;
use Yuna\Flow\Logger;
use Yuna\Flow\Result;
use Yuna\Flow\StepRegistry;

require_once __DIR__ . '/vendor/autoload.php';

$config = new Config();
$context = new Context($config, new Environment($_ENV), new Logger());

$builder = new FlowBuilder(
    new StepRegistry([
        '@yuna/hello' => new InlineStep(function (Context $context) {
            $context->getLogger()?->info('something here');
            return new Result(true);
        }),
        '@yuna/world' => new InlineStep(function (Context $context) {
            $context->getLogger()?->info('will error');
            return new Result(false);
        })
    ]),
    $context
);

$exitCode = $builder
    ->create()
    ->run([
        'flow' => [
            'steps' => [
                'Hello' => [
                    'id' => '@yuna/hello',
                ],
                'World' => [
                    'id' => '@yuna/world',
                ]
            ]
        ]
    ]);

exit($exitCode);

Code above will output:

[INFO] Running "Hello"...
[INFO] something here
[INFO] Running "World"...
[INFO] will error

with exit code 1 (because result is false)

Steps requiring configuration

Below we can see example of step requiring configuration.

<?php

use Symfony\Component\OptionsResolver\OptionsResolver;
use Yuna\Flow\Config;
use Yuna\Flow\Context;
use Yuna\Flow\Environment;
use Yuna\Flow\FlowBuilder;
use Yuna\Flow\InlineStep;
use Yuna\Flow\Logger;
use Yuna\Flow\Result;
use Yuna\Flow\StepRegistry;

require_once __DIR__ . '/vendor/autoload.php';

$config = new Config();
$context = new Context($config, new Environment($_ENV), new Logger());

$builder = new FlowBuilder(
    new StepRegistry([
        '@yuna/require-options' => new InlineStep(
            function (Context $context, array $config) {
                $context->getLogger()?->info(sprintf('value: %s', $config['value']));
                return new Result(true);
            },
            function (OptionsResolver $resolver) {
                $resolver->setRequired('value');
                $resolver->setAllowedTypes('value', 'int');
            })
    ]),
    $context
);

$exitCode = $builder
    ->create()
    ->run([
        'flow' => [
            'steps' => [
                'Hello' => [
                    'id' => '@yuna/require-options',
                    'options' => [
                        'value' => 777
                    ]
                ]
            ]
        ]
    ]);

exit($exitCode);

Code above will output:

[INFO] Running "Hello"...
[INFO] value: 777

with exit code 0.

That's pretty much it, as you can see, we can pretty easily use different formats, not just PHP.

License

MIT