PHP code example of corbosman / laravel-pipeline-passable

1. Go to this page and download the library: Download corbosman/laravel-pipeline-passable 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/ */

    

corbosman / laravel-pipeline-passable example snippets


use CorBosman\Pipeline\Passable;

class MyPipeline extends Passable
{
    public string $username;
    public array $output;

    public function return() : array
    {
        return $this->output;
    }
}

$output = (new MyPipeline(['username' => $foo, 'output' => []])->pipeline([
    PipeClass1::class,
    PipeClass2::class
    ...
]);

use CorBosman\Pipeline\Passable;

class MyPipeline extends Passable
{
    public string $username;
    public Output $output;
    
    public static function factory($username) : self
    {
        return new self([
            'username' => $username,
            'output'   => new Output
        ]);
    }

    public function return() : array
    {
        return $this->output->toArray();
    }
}

$output = MyPipeline::factory($username)->pipeline([
    PipeClass1::class,
    PipeClass2::class
    ...
]);

class Uppercase
{
    public function handle(MyPipeline $passable, $next)
    {
        $passable->output = strtoupper($passable->username);

        return $next($passable);
    }
}

class Uppercase
{
    public function __invoke(MyPipeline $passable, $next)
    {
        $passable->output = strtoupper($passable->username);

        return $next($passable);
    }
}

$uppercase = new Uppercase;
$result = MyPipeline::factory($input)->pipeline([$uppercase]);

$result = MyPipeline::factory($input)->pipeline([...], 'filter');