PHP code example of guanguans / pipeline

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

    

guanguans / pipeline example snippets



Guanguans\Pipeline\Pipeline;

(new Pipeline())
    ->send('passable')
    ->through(
        function ($passable, Closure $next){
            echo '1. Before apply first middleware.'.PHP_EOL;
            $next($passable);
            echo '7. After apply first middleware.'.PHP_EOL;
        },
        function ($passable, Closure $next){
            echo '2. Before apply second middleware.'.PHP_EOL;
            $next($passable);
            echo '6. After apply second middleware.'.PHP_EOL;
        },
        function ($passable, Closure $next){
            echo '3. Before apply third middleware.'.PHP_EOL;
            $next($passable);
            echo '5. After apply third middleware.'.PHP_EOL;
        }
    )
    // ->via('differentMethod')
    // ->thenReturn()
    ->then(function ($passable){
        echo '4. Middleware is finished.'.PHP_EOL;

        return $passable;
    });