Laminas_EventManager listener attachment creates excessive notifications for non‑critical events
0 reputation · 08 Mar 2020, 16:11 UTC
0 reputation · 08 Mar 2020, 16:11 UTC
Multiple modules attach listeners to the same Laminas_EventManager event, causing a flood of notifications for non‑critical occurrences.
The framework supports listener priorities and the stopPropagation flag, yet the execution order and interaction with global error handling remain unclear, and no built‑in severity taxonomy exists.
How can listener priorities and stopPropagation be configured to ensure critical listeners run first while low‑priority listeners are suppressed? Can a global filter be defined to allow only high‑severity events?
37275 reputation · 08 Mar 2020, 22:45 UTC
Use listener priority for ordering and stopPropagation(true) to suppress later listeners. Attach critical listeners with a higher integer priority than low-priority listeners, then place a suppression guard between them. Laminas EventManager has no built-in severity taxonomy or global high-severity-only filter, so a true global filter requires decorating EventManager::trigger() or short-circuiting before listeners run.
attach('event.name', $listener, $priority): higher integer priority runs first; do not rely on order among equal priorities.stopPropagation(true) prevents listeners registered after the stopping listener from running for that trigger. Responses from listeners that already ran remain in the ResponseCollection.trigger(); EventManager does not handle them as log events. Wrap listener bodies or configure global error handling separately.Assumes laminas-eventmanager 2.x or 3.x; older Zend\\EventManager may differ. Severity handling is a design gap, not a missing configuration option.
composer show laminas/laminas-eventmanager.200.100. In the guard, inspect the event; if it is non-critical, call $event->stopPropagation(true) and return.0 or a negative value.trigger() to return an empty ResponseCollection for events whose severity is not high before any listener is invoked.$events->attach('order.placed', $criticalListener, 200);
$events->attach('order.placed', $suppressionGuard, 100);
$events->attach('order.placed', $lowPriorityListener, 0);
$suppressionGuard = function ($event) {
if ($event->getParam('severity') !== 'high') {
$event->stopPropagation(true);
}
};
If some lower-priority listeners must still run for non-critical events, stopPropagation is too broad; use separate event names or conditional listener logic instead.
Do triggered events carry a severity property on the event object? If not, use an event-name allowlist or add a custom event prototype/parameter before applying severity-based suppression; this determines whether $event->getParam('severity') will work.
stopPropagation(true) prevents a lower-priority listener from running while earlier listeners still have responses.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.