How to listen to events triggered by Laminas Event Manager?

Hi,

I’m unable to listen to events triggered by Laminas’s Event Manager. The event triggered by this code in this section is not being listened to by the aggregate listener shown in this post. Thanks!

Uff, there is a lot of custom code, but where is this service used or how is this custom “event provider” known / registered to the application?

Hi @froschdesign,

I don’t know how it got registered but it did just like Laminas Navigation View helper. I can’t listen to the isAllowed method of navigation as well. So, can you help in that regard? Thanks!

Hi @froschdesign,

This is working fine. It was my mistake. As for your question

Correct me if I’m wrong. You’re asking about the actual code. So, please see the GitHub link. The factory set the service manager here.

I’m sorry, I do not use the module and therefore do not know it. I only know that you are working on LmcAdmin, so I assumed you also know this module better than I do.

Thanks for your assumption and for having me put alongside the greats of the PHP community Like the Roave people. But I’m no way near their stature. I know how to use it and can do minor fixes. If possible can you share some code to trigger lazy listeners and listen to them? I’ll check the doc of the module may be I’m missing something. Thanks! For the people who are looking to do something with Laminas Navigation Helper generated event. They need to add the line below which is shown in the documentation.

<?php
// works on PHP 7.4

namespace Application\Listener;

use Exception;
use Laminas\EventManager\AbstractListenerAggregate;
use Laminas\EventManager\EventManagerInterface;
use Laminas\Mvc\MvcEvent;

class NavigationListner extends AbstractListenerAggregate {
    public function attach(EventManagerInterface $events, $priority = 1): void
    {
        $this->listeners[] = $events->getSharedManager()->attach(
            'Laminas\View\Helper\Navigation\Menu', 'isAllowed',
            [$this, 'onMenuIsAllowed']
        );
    }

    public function onMenuIsAllowed($event){
        $menu = $e->getTarget();
    }
}

Thanks!

Hi @froschdesign,

I’m sorry for taking your time. Now all events are firing and can be logged. I don’t know what caused them to stop firing. But now everything is working. It happened after your comment about me being as great as you and others in the LmcAdmin original contribution list. Thanks!