Skip to content

[4.x] Explain why getSubscribedEvents() is static and must not depend on runtime state - #59

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-subscriber-static-docs
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-subscriber-static-docs

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

SubscriberInterface::getSubscribedEvents() only documents the array format. It does not explain why the method is static, so subscriber authors put conditional logic there (checking configuration, the current user, …). Applications that register subscribers lazily or cache the map of listeners (as the CMS does) call the method without an instance, so the mapping must not depend on runtime state.

The docblock now states that the method is static because it can be called without an instance, that it must not depend on runtime state and must always return the same mapping, and that conditional logic belongs in the handler methods. This is the wording of #32, reapplied to the current, space-indented file (#32 uses tabs and a trailing space and no longer applies) and extended with the reason.

Testing Instructions

Docblock and documentation only; review the text.

Documentation Changes Required

docs/overview.md, "Event Subscribers": added the same explanation.

Supersedes #32

🤖 Generated with Claude Code

Subscribers can be registered before they are instantiated, for example
by applications that load them lazily or cache the listener map, so
getSubscribedEvents() must return the same mapping regardless of runtime
state. Say so in the interface docblock and the docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Hackwar

Hackwar commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

CI fails in "Install PHP dependencies" before any check runs, independent of this change: joomla/console (require-dev) requires joomla/event ^4.0, but the checked-out root package gets a dev-<branch|sha> version that does not satisfy it ("joomla/event dev-… is the root package and cannot be modified"). The scheduled runs on 4.x-dev fail the same way (every run since at least 2026-08-31). Locally, with COMPOSER_ROOT_VERSION=4.0.x-dev, phpunit, phpcs (src) and phpstan pass. Fixing it needs a root version in CI (e.g. COMPOSER_ROOT_VERSION in the shared workflow, or a branch-alias plus enough git history for Composer to guess the version), which is outside the scope of this PR.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant