lorisleiva / laravel-actions

⚡️ Laravel components that take care of one specific task
https://laravelactions.com
MIT License
2.41k stars 117 forks source link

Allow overriding the job decorator classes #224

Closed ksassnowski closed 1 year ago

ksassnowski commented 1 year ago

This is related to #145

I'd like to create a PR that allows users to override which decorator classes should be used when using actions as jobs. This would allow a package like Venture, for example, to provide first-party integration with Laravel Actions without the user having to change their actions in any way.

The API could be similar to what Cashier–and for that matter, Venture itself–does to allow users to provide custom models. Here's a suggestion of what this might look like:

// in some service provider

ActionManager::useJobDecorator(MyCustomJobDecorator::class);
ActionManager::useUniqueJobDecorator(MyCustomUniqueJobDecorator::class);

Venture could then provide a Venture::useLaravelActions() method to register the necessary decorators in order to make the two packages compatible with each other. Users should then be able to use actions from this package as jobs in their workflows without any other changes.

The only thing that really needs to change as far as Laravel Actions is concerned, is replacing the hardcoded references to JobDecorator and UniqueJobDecorator with something like ActionManager::$jobDecoratorClass.

Let me know if this works for you and I can submit a PR for this!

Wulfheart commented 1 year ago

To me this looks very interesting and promising. I would definitely be open to merge this but @lorisleiva has the final saying on this.

lorisleiva commented 1 year ago

Hiya! I like that approach a lot. Flexible yet transparent to the package. Looking forward to your PR. 🍺

lorisleiva commented 1 year ago

Published as v2.5.1. Thanks again! 🎉