kleytonsantos/pipeline-bundle

A symfony package to handle a pipeline structure

dev-main 2025-03-09 22:11 UTC

This package is auto-updated.

Last update: 2025-06-09 22:45:42 UTC


README

PipelineBundle is a Symfony component that allows you to create and execute data processing pipelines in a flexible and dynamic way.

📦 Instalação

Installing the bundle with Composer, run the following command:

composer require kleytonsantos/pipeline-bundle
// config/bundles.php
return [
    KleytonSantos\Pipeline\PipelineBundle::class => ['all' => true],
];

🚀 Uso Básico

1️⃣ Create a Pipeline Configuration

Adding a pipeline configuration to config/packages/pipeline.yaml:

# config/packages/pipeline.yaml
pipeline:
    pipelines:
        my_pipeline:
            - my_pipe1
            - my_pipe2

2️⃣ Custom Pipes

<?php

declare(strict_types=1);

namespace App\Pipe;

class TrimPipe implements PipelineInterface
{
    public function handle(mixed $passable, \Closure $next): mixed
    {
        return $next(trim($passable));
    }
}

3️⃣ Execute the Pipeline

3.1 using through method to manually pass the pipes

$result = $pipeline
    ->send($passable)
    ->through([
        App\Pipe\CustomPipe1::class,
        App\Pipe\CustomPipe2::class,
    ])
    ->thenReturn();

3.2 using withConfig method to use config from pipeline.yaml

$result = $pipeline
    ->send($passable)
    ->withConfig('my_pipeline')
    ->thenReturn();

📄 Methods Summary

Methods Description
send(mixed $passable): static Defines the data to be processed in the pipeline.
withConfig(string $configName): static Use config from pipeline.yaml.
through(array $pipes): static Pass the pipes manually.
then(Closure $destination): mixed Process the pipeline and execute a final function.
thenReturn(): mixed Process the pipeline and return the final result.