fntneves / laravel-transactional-events

Transaction-aware Event Dispatcher for Laravel
MIT License
313 stars 28 forks source link

Wrong parameter to TransactionalDispatcher constructor #21

Closed ibrunotome closed 5 years ago

ibrunotome commented 5 years ago

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.

fntneves commented 5 years ago

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.

ibrunotome commented 5 years ago

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 (https://github.com/hhxsv5/laravel-s/issues/129#issuecomment-476914604).

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

fntneves commented 5 years ago

I am following the discussion on https://github.com/hhxsv5/laravel-s/issues/129

Hopefully, we get this working.

ibrunotome commented 5 years ago

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