PHP code example of mr-rijal / laravel-pipeline

1. Go to this page and download the library: Download mr-rijal/laravel-pipeline library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mr-rijal / laravel-pipeline example snippets


use MrRijal\LaravelPipeline\Facades\LaravelPipeline;
use MrRijal\LaravelPipeline\DTO\LaravelPipelineContext;

LaravelPipeline::steps([
    fn (LaravelPipelineContext $ctx) => $ctx->set('foo', 'bar'),
    fn (LaravelPipelineContext $ctx) => $ctx->get('foo'), // returns 'bar'
])->run();

$results = LaravelPipeline::flow([
    fn() => true,
    fn() => false, // continue even if fails
    fn() => true
]);

$results = LaravelPipeline::parallel([
    StepOne::class,
    StepTwo::class,
]);

$pipeline = LaravelPipeline::steps([
    StepOne::class,
    StepTwo::class,
])->with(['user_id' => 5]);

$pipeline->run(); // or wrap in try/catch if steps may throw
$results = $pipeline->getResults();

foreach ($results as $step) {
    echo "{$step->name}: " . ($step->success ? '✔' : '✘') . " ({$step->time}ms)\n";
}

LaravelPipeline::parallel([
    StepOne::class,
    StepTwo::class
], queue: true); // Dispatches steps to Laravel queue

LaravelPipeline::steps([
    fn (LaravelPipelineContext $ctx) => $ctx->set('user_id', 123),
    fn (LaravelPipelineContext $ctx) => $ctx->get('user_id'), // 123
])->run();

fn (LaravelPipelineContext $ctx) => true

class StepOne
{
    public function handle(LaravelPipelineContext $ctx): bool
    {
        return true;
    }
}

true // simple pass/fail (e.g. in flow())