Skip to content

Conversation

@calebdw
Copy link
Contributor

@calebdw calebdw commented Mar 19, 2025

Hello!

Closes #53522 (comment)

This allows using contextual binds during the resolution of class dependencies, from the linked discussion:

This seems to have introduced an issue with contextual bindings for optional dependencies. Previously they were resolved but are now ignored (and thus null) following this change.

For example:

class Foo
{
    public function __construct(
        public ?Carbon $date = null,
    ) {}
}

app()->when(Foo::class)
  ->needs(Carbon::class)
  ->give(fn() => Carbon::now());

$foo = app()->make(Foo::class);
$foo->date; // NULL

I'd expect a contextual binding to count as an explicit binding in the context of the original change.

CC: @jonnyynnoj

Thanks!

@calebdw calebdw force-pushed the container_binding branch from d62f217 to 035b08f Compare March 19, 2025 20:33
@taylorotwell
Copy link
Member

taylorotwell commented Mar 19, 2025

Tests failing on this one. Can you also provide an example of what this solves? Thanks!

@taylorotwell taylorotwell marked this pull request as draft March 19, 2025 20:37
@calebdw calebdw force-pushed the container_binding branch from 035b08f to de8e737 Compare March 19, 2025 20:49
@calebdw calebdw marked this pull request as ready for review March 19, 2025 20:54
@calebdw
Copy link
Contributor Author

calebdw commented Mar 19, 2025

@taylorotwell, done---I updated the PR description

@taylorotwell taylorotwell merged commit 12dfad8 into laravel:12.x Mar 22, 2025
39 checks passed
@calebdw calebdw deleted the container_binding branch March 22, 2025 18:00
@calebdw
Copy link
Contributor Author

calebdw commented Mar 22, 2025

Thank you sir!

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