-
-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Support for Illuminate Pipelines #279
Comments
// -- AsAction.php
trait AsAction
{
use AsActionBase;
public function asPipeline(...$args): void
{
if (count($args) === 0) {
throw new \Exception('No arguments provided to asPipeline method.');
}
if (!(last($args) instanceof \Closure)) {
throw new \Exception('Last argument must be a closure.');
}
$closure = array_pop($args);
$closure($this->handle(...$args));
}
}
// later...
app(Pipeline::class)->send('content')->via('asPipeline')->through([ ModerateContent::class ])->thenReturn(); Would there be any shortcomings to this approach? |
I love this approach! |
You have a PR @h-sigma ? I was about to write this myself in my project but glad I'm not the only one looking for it. Seems like it would be handy for others. |
I was actually looking in the documentation to see if this was a feature and am glad I found this post. I would love this, good approach! Maybe we can work on something together? |
@h-sigma have you been exercising this solution in a production project since proposing here? Does it seem to work well? I am looking for Pipeline support in this package as well and it seems like you might have a solid, and straightforward, approach that would warrant a PR here. Nice work! |
I've been using it in a couple of smaller production projects. It works fine. I don't have a PR in the works right now. What does the maintainer think about adding this as a part of the library? I do not want to bloat it with rarely used features (which pipelines are imo), and it might be better to add it as a tip or advice in the documentation with this code example instead? |
Relevant Article: https://martinjoo.dev/laravel-pipelines
Illuminate pipelines look like:
In the example above, the
string $content
variable "travels" the pipeline. The signature of each class that it travels through needs to beAs you can see, the syntax is fairly similar to the existing Laravel Actions handler. In fact, all I need to do is change the signature to
?Closure $next = null
to adapt it for both usages. However, it would be quite neat if Actions could support this directly (the return value of the handler function would be passed to$next
in this case).The text was updated successfully, but these errors were encountered: