I'm stuck with this for a while. I have a service for each entity when i trigger various events
Eg in ArticleService saveArticle method
$this->triggerEvent('articleSaved', ['saved' => $entity]);
Then i create an individual listener like below
class ArticleSavedListener implements ListenerAggregateInterface
{
// ...
public function attach(EventManagerInterface $events, $priority = 100)
{
$this->listeners[] = $events->attach(
Events::ARTICLE_SAVED,
[$this, 'onSaved'],
$priority
);
}
public function onSaved($event)
{
//logic here
}
}
And the registration in Module.php
class Module
{
public function onBootstrap()
{
$application = $e->getApplication();
$serviceManager = $application->getServiceManager();
$eventManager = $application->getEventManager();
$articleService = $serviceManager->get(ArticleService::class);
$articleSavedListener = $serviceManager->get(ArticleSavedListener::class);
$articleSavedListener->attach($articleService->getEventManager());
}
}
The point is i need to create a generic class (listener) listening all list of specific events with a very low priority. But for what i read since i declared them private i can't listen to them outside the registered class scope.
Help needed please.