mongodb / laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
https://www.mongodb.com/docs/drivers/php/laravel-mongodb/
MIT License
7.02k stars 1.43k forks source link

PHPORM-222 Register the `BusServiceProvider` when `BatchRepository` is built #3071

Closed GromNaN closed 3 months ago

GromNaN commented 3 months ago

Fix PHPORM-222 Fix #3060

MongoDBBusServiceProvider is not the provider of BatchRepository. I could not reproduce the issue described in #3060, but it looks like this change should fix it.

Checklist

degecko commented 3 months ago

Correct me if I'm wrong, but doesn't this fix render the code from the register method useless?

If I'm correct in assuming that the idea was to extend the BatchRepository service provider for the case where the queue batching driver was set to mongodb, then the proposed solution will invalidate that solution.

It's also true that the way the BatchRepository resolver has been extended never actually worked. I think that's the actual bug that needs fixing.

GromNaN commented 3 months ago

Ok, I think I've found how this should be done.

Illuminate\Bus\BusServiceProvider is a DeferrableProvider. It's registered only when one of the services it provides is requested. But by extending this service in my provider, I replace the service provider that is registered. I with Laravel would call every providers that provide a given service, but there is only one. I need to explicitly register the Illuminate\Bus\BusServiceProvider when my provider is registered.

GromNaN commented 3 months ago

Ideally that could be solved in Laravel: https://github.com/laravel/framework/discussions/52251