Symfony event-dispatcher update in Nextcloud Server 28 / Breaking changes

Hello fellow developers,

the new symfony/event-dispatcher update (4.4 to 5.4) is nearing and the preparations in server have been completed: fix(deps)!: Upgrade symfony/event-dispatcher to supported version 5.4.26 by nickvergessen 路 Pull Request #38546 路 nextcloud/server 路 GitHub
It was unavoidable to remove some internals of Symfony (because they removed them or will remove them in the step 2 update to the next major (5.4 to 6.4) we need to do for PHP 8.3 support).

Most of the affected APIs have been deprecated since quite some time already, but are still used in various places:

  • getEventDispatcher() was to be removed because one of the two functions we all used from it (dispatch), had its parameters switched in order. get(\OCP\EventDispatcher\IEventDispatcher) (or proper DI) is the go to replacement for it
  • Same applies for Symfony\Component\EventDispatcher\EventDispatcherInterface
  • Symfony鈥檚 GenericEvent class is deprecated and will be removed in the 6.4 update (which we will also include in Nextcloud 28). This meant we had to convert all usages to proper actual custom events. Those new events all extend the public \OCP\EventDispatcher\Event class and are dispatched as typed events (event class === event name).

Due to the complexity of the event handling and being unable to detect if you are being called from a typed event or legacy event, subscribing to both events (depending on the context) can be okay or problematic. So you will have to judge that yourself, if it is problematic for you, you can simply bump the required version to 28 and only listen to the new events, or you wrap the listener registration with a version check and either subscribe to typed or legacy.

In case of questions feel free to reply.
Have a nice weekend