fntneves / laravel-transactional-events

Transaction-aware Event Dispatcher for Laravel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong parameter to TransactionalDispatcher constructor

ibrunotome opened this issue · comments

Sometimes I'm getting this error:

[27-Mar-2019 00:36:04 UTC] PHP Fatal error: Uncaught TypeError: Argument 2 passed to Neves\Events\TransactionalDispatcher::__construct() must be an instance of Illuminate\Events\Dispatcher, instance of Neves\Events\TransactionalDispatcher given, called in /app/vendor/fntneves/laravel-transactional-events/src/Neves/Events/EventServiceProvider.php on line 29 and defined in /app/vendor/fntneves/laravel-transactional-events/src/Neves/Events/TransactionalDispatcher.php:69

If I remove the EventDispatcher type on constructor, it works, so I print a log to test:

/**
 * Create a new transactional event dispatcher instance.
 *
 * @param  \Illuminate\Database\ConnectionResolverInterface $connectionResolver
 * @param  \Illuminate\Contracts\Events\Dispatcher          $eventDispatcher
 */
public function __construct(ConnectionResolverInterface $connectionResolver, $eventDispatcher)
{
    Log::debug(get_class($eventDispatcher));

    $this->connectionResolver = $connectionResolver;
    $this->dispatcher = $eventDispatcher;
    $this->setUpListeners();
}

And got this:

[2019-03-27 11:33:03] local.DEBUG: Illuminate\Events\Dispatcher  
[2019-03-27 11:33:08] local.DEBUG: Illuminate\Events\Dispatcher  
[2019-03-27 11:33:33] local.DEBUG: Illuminate\Events\Dispatcher  
[2019-03-27 11:33:33] local.DEBUG: Illuminate\Events\Dispatcher  
[2019-03-27 11:33:40] local.DEBUG: Illuminate\Events\Dispatcher  
[2019-03-27 11:33:40] local.DEBUG: Illuminate\Events\Dispatcher  
[2019-03-27 11:33:40] local.DEBUG: Illuminate\Events\Dispatcher  
[2019-03-27 11:33:40] local.DEBUG: Illuminate\Events\Dispatcher  
[2019-03-27 11:33:40] local.DEBUG: Illuminate\Events\Dispatcher  
[2019-03-27 11:33:40] local.DEBUG: Illuminate\Events\Dispatcher  
[2019-03-27 11:33:40] local.DEBUG: Illuminate\Events\Dispatcher  
[2019-03-27 11:33:40] local.DEBUG: Illuminate\Events\Dispatcher  
[2019-03-27 11:33:40] local.DEBUG: Illuminate\Events\Dispatcher  
[2019-03-27 11:33:42] local.DEBUG: Illuminate\Events\Dispatcher  
[2019-03-27 11:33:42] local.DEBUG: Illuminate\Events\Dispatcher  
[2019-03-27 11:33:44] local.DEBUG: Neves\Events\TransactionalDispatcher  
[2019-03-27 11:33:44] local.DEBUG: Neves\Events\TransactionalDispatcher  
[2019-03-27 11:33:44] local.DEBUG: Neves\Events\TransactionalDispatcher  
[2019-03-27 11:33:44] local.DEBUG: Neves\Events\TransactionalDispatcher  
[2019-03-27 11:33:44] local.DEBUG: Neves\Events\TransactionalDispatcher  
[2019-03-27 11:33:44] local.DEBUG: Neves\Events\TransactionalDispatcher  
[2019-03-27 11:33:44] local.DEBUG: Neves\Events\TransactionalDispatcher  
[2019-03-27 11:33:44] local.DEBUG: Neves\Events\TransactionalDispatcher  
[2019-03-27 11:33:44] local.DEBUG: Neves\Events\TransactionalDispatcher  
[2019-03-27 11:34:00] local.DEBUG: Illuminate\Events\Dispatcher  
[2019-03-27 11:34:00] local.DEBUG: Illuminate\Events\Dispatcher  
[2019-03-27 11:34:00] local.DEBUG: Illuminate\Events\Dispatcher  

Can we do something about this? The most quickly solution is remove the EventDispatcher type from constructor, but I don't know if is the best solution.

Hi @ibrunotome ,

Thank you for opening this issue.

Could you please tell me which version of Laravel and TransactionalDispatcher are you using?

I see that __construct() of TransactionalDispatcher is already receiving an instance of TransactionalDispatcher. I suspect you're registering the TransactionalDispatcher twice.

Hi @fntneves, as you can see below, I'm using swoole with hhxsv5/laravel-s (for async and speed purposes). And the problem starts after the version v3.4.1 of his package.

Screen Shot 2019-03-27 at 10 09 30

I explain the problem to him too (hhxsv5/laravel-s#129 (comment)).

Also, I'm using the last version of your package (1.8.0)

I am following the discussion on hhxsv5/laravel-s#129

Hopefully, we get this working.

I've switched back to swooletw/laravel-swoole and your package is working normally. Closing the issue.