<?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($str, Closure $pipe)
{
$str = $pipe($str);
return strtolower($str);
}
};
});
$container->bind('trim_str', function() {
return new class
{
public function handle($str, Closure $pipe)
{
$str = $pipe($str);
return trim($str);
}
};
});
$container->bind('remove_foo', function() {
return new class
{
public function handle($str, Closure $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_str', 'lcase']);
// Run sent value through pipeline
$result = $pipeline->then(function($str) {
return $str;
});
dump($result);