Another thing we love about TYPO3 v10: the PSR-14 event dispatcher

Daniel Goerz

Until now, TYPO3 has used its own signals and hooks to allow developers to cleanly intercept core and third-party code. TYPO3 v10 implemented PSR-14, a standardized approach to dispatching events agreed upon by members of the PHP-FIG project. In this article, we’ll look at how this new method of event dispatching works and what that means for upgrading TYPO3 projects. It’s one of the 13 things we love about TYPO3 v10.

Modify code safely with events

Like TYPO’s custom hooks, and Extbase’s Signal/Slots, the PSR-14’s Event dispatcher allows the flow of code to be intercepted. Whenever a piece of code fires an event, third-party code can register some sort of listener and then alter, enhance, add to or simply observe (e.g. log) whatever has happened. It’s a clean way of allowing developers to extend code without hacking core, which would overwrite their changes the next time they update TYPO3. It also enables us to incorporate events provided by other frameworks or libraries that support PSR-14, making it easier to interface with them.

Read more about PSR-14 Events on my website UseTYPO3.com. This article includes examples of the implementation in TYPO3 core that you could apply to custom extensions.

PSR-14 standardizes event dispatching across PHP projects

The PHP Framework Interop Group makes recommendations for approaching shared challenges that many PHP projects face. Many roads lead to Rome, but if we agree to travel along the same one, we can share a car and save petrol at the same time.

PSR-14 harmonizes the many different concepts and approaches for this code extensibility, an example of which is TYPO3’s Hooks and Signal/Slots. Benni took part in drafting the recommendations to ensure it was suitable for TYPO3’s purposes.

Read more: An interview with Benni Mack, Improving Developer Adoption in TYPO3 on typo3.com 

The benefits of PSR-14 events for devs and agencies

TYPO3 is one of the first major PHP projects to implement PSR-14. Benni first presented them to the community in his talk at Developer Days 2019. Many people will benefit from adopting PSR-14, which is why we’re so enthusiastic about this improvement!

Seasoned TYPO3 developers can continue relying on tried-and-tested methods with TYPO3’s custom hooks Extbase’s Signal/Slots system however isalready deprecated and will be removed in TYPO3 v11. Meanwhile, TYPO3 starts to become easier to adopt for new developers who are familiar with other PHP frameworks. 

  • For developers it will be easier to learn TYPO3 if you’re already used to working with standardized events from other applications. It’s also easier to reuse other people’s code if they adopt the standard. Parts of TYPO3 are easier to maintain because we piggy-back on the work done by people in other open-source projects, and this includes documentation which is central to a great developer experience.
    Another benefit for developers is that PSR-14 Events allow to specify the intended API of an event because each Event is represented by a dedicated object and may offer methods to retrieve, alter or exchange the corresponding data. This is a mayor improvement compared to the concept of Hooks where data that was allowed to be changed had to be passed by reference.
  • The benefit for agencies is that their devs are more efficient, and it’s also easier to recruit and onboard staff because they don’t have to learn everything from scratch.

Developers can be more productive, which makes agencies more profitable. It’s win-win-win!

Save work later on by upgrading to TYPO3 v10 now

TYPO3 v10 still supports Signals and Hooks, however, we've started migrating as many of them as possible to PSR-14 Events in core. By TYPO3 v11, they will be deprecated so it’s better to update your code as soon as possible. This will save you putting more development work in the future when you have to upgrade what you’re working on today. There’s an overview of all PSR-14 events in the TYPO3 documentation, but many more are on the way and this is a great way for people to contribute to the project.

Adoption of PSR-14 really makes upgrading to TYPO3 v10 worthwhile because it’s an improvement of a basic concept that every extensible, customizable application needs. The specification provides for more powerful events than even before, while reducing complexity for devs, and helping them work efficiently—which is music to agencies’ ears!

Wondering how much does it cost to upgrade TYPO3?

Upgrading your TYPO3 site is probably not as expensive as you think!

Get a quote to find out.