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’s
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).- The new events are listed in the changelog docs: Upgrade to Nextcloud 28 — Nextcloud latest Developer Manual latest documentation
- Due to the hard removal in the upstream library, we were forced to also remove the old events directly. All have a replacement available, you can see them in Upgrade to Nextcloud 28 — Nextcloud latest Developer Manual latest documentation
- Some events where already dispatched as typed event as well as legacy event (event class !== event name), in cases where it was possible, the legacy event was kept and has been marked as deprecated Upgrade to Nextcloud 28 — Nextcloud latest Developer Manual latest documentation
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