From 0c755d8a21b4a28af759f4f79ce8d6c8654c2519 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Thu, 7 Dec 2023 10:57:16 +1100 Subject: [PATCH] Fixes support with Laravel 10.30 --- src/Events/EventServiceProvider.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Events/EventServiceProvider.php b/src/Events/EventServiceProvider.php index 23b62dd19..116e1c710 100644 --- a/src/Events/EventServiceProvider.php +++ b/src/Events/EventServiceProvider.php @@ -18,9 +18,30 @@ class EventServiceProvider extends ServiceProvider public function register() { $this->app->singleton('events', function ($app) { - return (new Dispatcher($app))->setQueueResolver(function () use ($app) { + // return (new Dispatcher($app))->setQueueResolver(function () use ($app) { + // return $app->make(QueueFactoryContract::class); + // })->setTransactionManagerResolver(function () use ($app) { + // return $app->bound('db.transactions') + // ? $app->make('db.transactions') + // : null; + // }); + + // The following adds support for Laravel 10.30 when a transaction manager resolver + // was included as part of the dispatcher. Detect its presence and set it as needed + // @deprecated remove reflection and use code above in v4 (Laravel 11) + $dispatcher = (new Dispatcher($app))->setQueueResolver(function () use ($app) { return $app->make(QueueFactoryContract::class); }); + + if (method_exists($dispatcher, 'setTransactionManagerResolver')) { + $dispatcher->setTransactionManagerResolver(function () use ($app) { + return $app->bound('db.transactions') + ? $app->make('db.transactions') + : null; + }); + } + + return $dispatcher; }); $this->app->singleton('events.priority', function ($app) {