The Pipeline pattern in Laravel

Code
<?php

use Illuminate\Pipeline\Pipeline;
use 
Illuminate\Container\Container;

// Build container and services
$container = new Container();

$container->bind('lcase', function() {
    return new class
    {
        public function 
handle($strClosure $pipe)
        {
            
$str $pipe($str);
            return 
strtolower($str);
        }
    };
});
$container->bind('trim', function() {
    return new class
    {
        public function 
handle($strClosure $pipe)
        {
            
$str $pipe($str);
            return 
trim($str);
        }
    };
});
$container->bind('remove_foo', function() {
    return new class
    {
        public function 
handle($strClosure $pipe)
        {
            
$str $pipe($str);
            return 
str_replace('foo'''$str);
        }
    };
});

// create Pipeline
$pipeline = new Pipeline($container);
// The value that will be send through every pipe
$pipeline->send('  barFoo  ');
// An array of pipes (service ids)
$pipeline->through(['remove_foo''trim''lcase']);

// Run sent value through pipeline
$result $pipeline->then(function($str) {
    return 
$str;
});

dump($result);
Result
"bar"
Used Versions
PHP 7.1, Zend 3.0, Symfony 3.2, Laravel 5.2, PHPUnit 5.6, Doctrine 2.6