Skip to content

Commit

Permalink
Allow passing object instances regardless of the parameter name to me…
Browse files Browse the repository at this point in the history
…thod injection (#24234)
  • Loading branch information
mpociot authored and taylorotwell committed May 24, 2018
1 parent de7455a commit 49549b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Container/BoundMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ protected static function addDependencyForCallParameter($container, $parameter,
$dependencies[] = $parameters[$parameter->name];

unset($parameters[$parameter->name]);
} elseif ($parameter->getClass() && array_key_exists($parameter->getClass()->name, $parameters)) {
$dependencies[] = $parameters[$parameter->getClass()->name];

unset($parameters[$parameter->getClass()->name]);
} elseif ($parameter->getClass()) {
$dependencies[] = $container->make($parameter->getClass()->name);
} elseif ($parameter->isDefaultValueAvailable()) {
Expand Down
8 changes: 8 additions & 0 deletions tests/Container/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,14 @@ public function testCallWithDependencies()
$this->assertInstanceOf('stdClass', $result[0]);
$this->assertEquals('taylor', $result[1]);

$stub = new ContainerConcreteStub;
$result = $container->call(function (stdClass $foo, ContainerConcreteStub $bar) {
return func_get_args();
}, [ContainerConcreteStub::class => $stub]);

$this->assertInstanceOf('stdClass', $result[0]);
$this->assertSame($stub, $result[1]);

/*
* Wrap a function...
*/
Expand Down

0 comments on commit 49549b7

Please sign in to comment.