Skip to content

docs(dev/events): modernize / expand event system docs#13957

Open
joshtrichards wants to merge 13 commits intomasterfrom
jtr/docs-dev-events-modernize
Open

docs(dev/events): modernize / expand event system docs#13957
joshtrichards wants to merge 13 commits intomasterfrom
jtr/docs-dev-events-modernize

Conversation

@joshtrichards
Copy link
Member

@joshtrichards joshtrichards commented Dec 29, 2025

☑️ Resolves

The existing Events chapter was showing its age and in need of a refactor.

It was a bit confusing in some spots, wasn't up-to-date with current best practices, and lacked coverage of the dispatcher.

This PR modernizes and expands the documentation for Nextcloud Events:

  • adds emission/dispatch coverage
  • clarifies listener registration / instantiation / handler execution lifecycle
  • aligns docs/examples with current best practices - e.g.,
    • use the OCP Event Dispatcher and IBootstrap patterns
    • current PHP best practices
  • adds additional code examples:
    • e.g., defining events, registering listeners, and emitting/dispatching events, usage of event payloads, and DI
  • improves coverage of event payloads
  • de-emphasize legacy approaches, referencing them only for migration purposes
    • e.g., hooks, public emitters, pre-IBootstrap listener patterns
  • improves clarity throughout the documentation
    • e.g., correcting typos, clarifying ambiguous statements, and removing (most - ahem) informal phrasing
  • new table of contents

These changes ensure app authors have clear, up-to-date, and actionable guidance for both consuming and producing events in Nextcloud apps.

🖼️ Screenshots

image

…examples, clarify listener lifecycle

Expanded the events documentation w/ detailed explanations, examples, and deprecated hooks and emitters sections.

Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
@joshtrichards joshtrichards changed the title docs(dev/events): modernize event system docs, add emission/dispatch examples, clarify listener lifecycle docs(dev/events): modernize / expand event system docs Dec 29, 2025
@joshtrichards joshtrichards added this to the Nextcloud 33 milestone Dec 29, 2025
@joshtrichards joshtrichards marked this pull request as ready for review December 29, 2025 14:09
@susnux susnux requested a review from come-nc January 5, 2026 21:13
@blizzz blizzz modified the milestones: Nextcloud 33, Nextcloud 34 Feb 16, 2026
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
…nstantiation

Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Signed-off-by: Josh <josh.t.richards@gmail.com>
Also added new subsections for stopping, blocking, and broadcasting. And updated deprecated section: added GenericEvent and re-organized.

Signed-off-by: Josh <josh.t.richards@gmail.com>
@joshtrichards
Copy link
Member Author

Revised further:

  • clarified various confusing bits
  • fixed some inaccurate spots
  • fixed some broken examples
  • integrated earlier review feedback
  • added some additional events and scenarios

Signed-off-by: Josh Richards <josh.t.richards@gmail.com>
.. tip::
Don't get too hung up regarding data transportation at the moment if you're unfamiliar with
the topic. We'll return to the ``UserCreatedEvent`` and DTO in the context of a fuller example
later on. For now, let's return to the simpler ``AddEvent``, which merely fires ("this happened"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You renamed AddEvent as SomethingHappenedEvent but you still refer to AddEvent here (and maybe in other places, did not check)

Comment on lines +132 to +135
.. note::
The base ``Event`` class has an empty constructor that was added as a compatibility shim.
Calling ``parent::__construct()`` is safe and many core event classes still do so by convention,
but it is not strictly required. Omitting or including it will not affect behavior.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this note, it looks more confusing that anything else.
Calling parent::__construct is always safe and recommended, people can read Event code and see that the constructor is empty and not call it if they want.

Comment on lines +159 to +175
class AddTwoListener implements IEventListener {

// The logic triggered in response to an event
public function handle(Event $event): void {
if (!($event instanceof AddEvent)) {
return;
}

$event->addToCounter(2);
}
}

The listener is registered during app bootstrap and is lazily instantiated by the upstream DI container the first time the corresponding event fires. During the listener's existence, the handler (``handle()``) within it is called whenever an ``AddEvent`` is fired. The listener's handler implements the business logic (i.e. does the
interesting thing). If the event fires again within the same request, the same listener instance is reused.

.. note::
PHP parameter type hints cannot be more specific than those on the interface, so you can't type-hint ``AddEvent`` in the method signature; instead use instanceof inside the handler method.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More AddEvent references here. I would rename the example back to AddEvent at the beginning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants