lundi 29 mai 2017

Laravel Events Dispatcher has empty listeners for some events

I am trying to debug a strange Events quirk in Laravel 5.1.46. The application is enhanced with some other OSS components such as Symfony DIC, but no change has been made to actual Event handling.

Some events during a request lifespan fail to find their listeners. Everything seems to be set up correctly (code excerpt from the DIC):

$instance = new \Illuminate\Events\Dispatcher($this->get('illuminate\contracts\foundation\application'));
$instance->listen('App\\Events\\FallbackPeopleAdded', 'App\\Listeners\\NotifyAboutNewFallbackRole');

However, NotifyAboutNewFallbackRole is never handled. I've setup some debugging calls in Illuminate\Events\Dispatcher, I print out name of the event and count($this->listeners) at the beginning of sortListeners method. It returns 13 for all but 2 events in the middle of the event list. The SPL object hash of the Dispatcher instance does not change, therefore it is the same object for all the events (list shortened).

"App\Auth\AuthServiceProvider" (31)
13
"router.before" (13)
13
"router.matched" (14)
13
"jwt.valid" (9)
0
"App\Events\FallbackPeopleAdded" (34)
0
"App\Events\BroadcastPayload" (31)
13
"router.after" (12)
13
"kernel.handled" (14)
13

The NotifyAboutNewFallbackRole listener is listed correctly in $listeners dump for all other events

There is nothing special about the events with no listeners

class FallbackPeopleAdded implements \Illuminate\Contracts\Queue\ShouldQueue
{

nor with their firing

$this->eventDispatcher->fire(
    new FallbackPeopleAdded(
        $newFallback,
        $brand->getId(),
        $originatingPerson->getId()
    )
);

The queue should not be the issue here, the error occurs despite that, and more, it occurs even for the textual jwt.valid event.

Has anybody else encountered this as well? I do not understand where the listeners from the protected property could be removed and how come they are back again for another 3 events.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire