Skip to content

Pass the whole native payload to a lone array #[On] parameter - #508

Closed
ngunyimacharia wants to merge 1 commit into
NativePHP:mainfrom
ngunyimacharia:fix/on-listener-whole-payload
Closed

ngunyimacharia wants to merge 1 commit into
NativePHP:mainfrom
ngunyimacharia:fix/on-listener-whole-payload

Conversation

@ngunyimacharia

Copy link
Copy Markdown
Contributor

Problem

A native event listener like this crashes with BindingResolutionException:

#[On('chat-stream:delta')]
public function onDelta(array $payload): void

Named binding looks for a payload key called payload. It finds none, and the container can't resolve a bare array.

Fix

When a listener has exactly one array parameter and the payload has no key with that name, the listener gets the whole payload.

A matching key still binds by name as before. So onItems(array $items) with ['items' => [...]] still gets just $items.

Tests

tests/Feature/Edge/NativeEventPayloadBindingTest.php covers both cases.

This works on its own and also merges cleanly with #505. Together they let nested components use this listener shape.

@ngunyimacharia

Copy link
Copy Markdown
Contributor Author

Superseded by #510, which does this explicitly through a typed NativeEventPayload parameter instead of guessing from a missing key name.

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