PSR-14 EventDispatcher vs Custom CompilerPass for Listener Ordering
0 reputation · 07 Jun 2021, 22:55 UTC
In TYPO3 v12, the transition from the deprecated Signal/Slot system to the PSR-14 EventDispatcher introduces a challenge regarding execution order. While Signal/Slot allowed for explicit integer priorities, the current PSR-14 implementation in TYPO3 sorts listeners by priority and then by service ID. This makes the execution sequence non-deterministic when multiple extensions register listeners for the same event, as the service ID order depends on the container compilation sequence.
For data modification pipelines where one extension must process a record before another, relying on the standard priority attribute may be insufficient across different extension load orders.
Design Trade-off
When deterministic cross-extension ordering is required, two primary architectural paths exist:
- The Orchestrator Pattern: Implementing a single listener that manually invokes other services in a hard-coded sequence.
- Custom CompilerPass: Intervening in the container compilation to explicitly enforce the order of service tags.
Does the TYPO3 v12 architecture favor a specific approach to restore deterministic ordering without introducing tight coupling between independent extensions? Is there a documented method to ensure a listener in Extension A always executes before a listener in Extension B regardless of the load order?