Skip to content

Commit 3754522

Browse files
committed
Imply needs from the tag passed to giveTags if not set
1 parent 2ab27cd commit 3754522

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Illuminate/Container/ContextualBindingBuilder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public function give($implementation)
7575
*/
7676
public function giveTagged($tag)
7777
{
78+
if (! $this->needs) {
79+
$this->needs = $tag;
80+
}
81+
7882
$this->give(function ($container) use ($tag) {
7983
$taggedServices = $container->tagged($tag);
8084

tests/Container/ContextualBindingTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,24 @@ public function testContextualBindingGivesTagsForVariadic()
359359
$this->assertInstanceOf(ContainerContextImplementationStub::class, $resolvedInstance->stubs[0]);
360360
$this->assertInstanceOf(ContainerContextImplementationStubTwo::class, $resolvedInstance->stubs[1]);
361361
}
362+
363+
public function testContextualBindingGivesTagsForVariadicNoNeeds()
364+
{
365+
$container = new Container;
366+
367+
$container->tag([
368+
ContainerContextImplementationStub::class,
369+
ContainerContextImplementationStubTwo::class,
370+
], [IContainerContextContractStub::class]);
371+
372+
$container->when(ContainerTestContextInjectVariadic::class)->giveTagged(IContainerContextContractStub::class);
373+
374+
$resolvedInstance = $container->make(ContainerTestContextInjectVariadic::class);
375+
376+
$this->assertCount(2, $resolvedInstance->stubs);
377+
$this->assertInstanceOf(ContainerContextImplementationStub::class, $resolvedInstance->stubs[0]);
378+
$this->assertInstanceOf(ContainerContextImplementationStubTwo::class, $resolvedInstance->stubs[1]);
379+
}
362380
}
363381

364382
interface IContainerContextContractStub

0 commit comments

Comments
 (0)