Skip to content

Add mount dependency injection - #340

Closed
shanerbaner82 wants to merge 1 commit into
mainfrom
feature/di
Closed

Add mount dependency injection#340
shanerbaner82 wants to merge 1 commit into
mainfrom
feature/di

Conversation

@shanerbaner82

Copy link
Copy Markdown
Contributor

What changed

  • add a Native component lifecycle dispatcher that hydrates matching public route properties before calling mount()
  • resolve Eloquent/UrlRoutable models and backed enums from route parameters
  • inject ordinary class dependencies through Laravel's container
  • update router, standalone, nested-component, and testing mount call sites
  • add regression coverage for model binding, public-property binding, primitive parameters, container services, backed enums, and missing models

Why

NativeComponent declared a parameterless mount(): void, so PHP rejected component hooks such as mount(Click $click) as incompatible overrides. Native components also received raw route values rather than Livewire-style implicit bindings.

The base class now exposes an internal mountComponent() dispatcher and deliberately leaves mount() undeclared, allowing application components to use Livewire-compatible hook signatures.

Impact

Native routes such as /counter/{click} can now either hydrate public Click $click directly or inject the model through mount(Click $click). Components may combine route-bound values with services resolved from Laravel's container.

Validation

  • focused dependency-injection tests: 4 tests, 26 assertions
  • full Pest suite passed with 3,039 assertions (existing PHP 8.5 deprecation/risky notices remain)
  • PHPStan: no errors in the affected framework classes
  • Pint: clean
  • validated end-to-end with a real Eloquent Click model in the Native scratchpad app

@shanerbaner82
shanerbaner82 marked this pull request as ready for review August 15, 2026 17:14
@shanerbaner82 shanerbaner82 self-assigned this Aug 15, 2026
@shanerbaner82 shanerbaner82 changed the title Add Livewire-style mount dependency injection Add mount dependency injection Aug 16, 2026

@simonhamp simonhamp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ship it

@shanerbaner82

Copy link
Copy Markdown
Contributor Author

Superseded by #343 (same mount DI, via ComponentMethodInvoker instead of ImplicitlyBoundMethod). Closing so we don't land two implementations.

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.

2 participants