Thanks @github.com/lootjs, I have seen Hub before, and I thought it did something else. I tried again, hoping that I missed something, but I don't think this is what I need here.
I think the idea of the Hub is that one can have multiple pipelines, with names, and that you can dispatch to those pipelines by name. In my example above, I have one pipeline and want to reuse that one pipeline. That does not match.
Example for how I think Hub works:
function prependFoo($thing, $next) {
return $next('foo' . $thing);
}
function appendBar($thing, $next) {
return $next($thing . 'bar');
}
$hub = new Illuminate\Pipeline\Hub();
$hub->defaults(function ($pipeline, $thing) {
return $pipeline->send($thing)
->through(['prependFoo', 'appendBar'])
->then(fn($n) => $n);
});
$hub->pipeline('only-foo', function ($pipeline, $thing) {
return $pipeline->send($thing)
->through(['prependFoo'])
->then(fn($n) => $n);
});
$hub->pipe('thing'); // "foothingbar"
$hub->pipe('thing', 'only-foo'); // "foothing"
Note that Hub does not it's Container to resolve Pipeline (just new
s it), and that it gives a new instance of Pipeline every time you call pipe()
on it, which is quite the opposite of what I want.
Hub also seems to be a bit forgotten: it is not used by the framework itself, is not documented and does not have tests. It feels like an experiment for Middleware groups that went nowhere? (But that's speculating, probably @taylorotwell knows.)
But most of all: no, I don't think that does what I mean.