Skip to content

Fix: event setup to initialize with an empty array#6

Open
mhucik wants to merge 2 commits intomasterfrom
fix/nette-di-compatibility
Open

Fix: event setup to initialize with an empty array#6
mhucik wants to merge 2 commits intomasterfrom
fix/nette-di-compatibility

Conversation

@mhucik
Copy link

@mhucik mhucik commented Feb 7, 2026

No description provided.

Copilot AI review requested due to automatic review settings February 7, 2026 14:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR modifies how EventsExtension::bindEventProperties() wires Nette-style onXxx event properties during DI container compilation.

Changes:

  • Adjusts the DI setup expression for autowired event properties from assigning to the property to appending to it ($onXxx$onXxx[]).
Comments suppressed due to low confidence (1)

src/Events/DI/EventsExtension.php:415

  • Changing the setup target from $onX to $onX[] no longer replaces the Nette event property with a Kdyby\Events\Event instance; it appends the created Event into the existing array/ArrayAccess instead. This breaks the documented/covered behavior where $service->onSomething is expected to be an Event (see tests/KdybyTests/Events/ExtensionTest.phpt assertions like $app->onStartup instanceof Event). It also changes listener ordering semantics and can introduce recursion/ordering issues.

If the goal is to avoid accessing an uninitialized typed property when passing defaults, keep the assignment to $onX and make the defaults argument safe via isset($service->onX) ? $service->onX : [] (or an equivalent approach that doesn’t read an uninitialized property).

			$def->addSetup('$' . $name . '[]', [
				new Statement($this->prefix('@manager') . '::createEvent', [
					[$class->getName(), $name],
					new PhpLiteral('$service->' . $name),
					NULL,
					$dispatchAnnotation ?? $this->loadedConfig['globalDispatchFirst'],

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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