Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/Illuminate/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ public function build($concrete)
// hand back the results of the functions, which allows functions to be
// used as resolvers for more fine-tuned resolution of these objects.
if ($concrete instanceof Closure) {
return $concrete($this, end($this->with));
return $concrete($this, $this->getLastParameterOverride());
}

$reflector = new ReflectionClass($concrete);
Expand Down Expand Up @@ -793,7 +793,7 @@ protected function resolveDependencies(array $dependencies)
*/
protected function hasParameterOverride($dependency)
{
return array_key_exists($dependency->name, end($this->with));
return array_key_exists($dependency->name, $this->getLastParameterOverride());
}

/**
Expand All @@ -804,7 +804,17 @@ protected function hasParameterOverride($dependency)
*/
protected function getParameterOverride($dependency)
{
return end($this->with)[$dependency->name];
return $this->getLastParameterOverride()[$dependency->name];
}

/**
* Get the last parameter override.
*
* @return array
*/
protected function getLastParameterOverride()
{
return count($this->with) ? end($this->with) : [];
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/Container/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,19 @@ public function testSingletonBindingsNotRespectedWithMakeParameters()
$this->assertEquals(['name' => 'taylor'], $container->makeWith('foo', ['name' => 'taylor']));
$this->assertEquals(['name' => 'abigail'], $container->makeWith('foo', ['name' => 'abigail']));
}

public function testCanBuildWithoutParameterStackWithNoConstructors()
{
$container = new Container;
$this->assertInstanceOf(ContainerConcreteStub::class, $container->build(ContainerConcreteStub::class));
}

public function testCanBuildWithoutParameterStackWithConstructors()
{
$container = new Container;
$container->bind('Illuminate\Tests\Container\IContainerContractStub', 'Illuminate\Tests\Container\ContainerImplementationStub');
$this->assertInstanceOf(ContainerDependentStub::class, $container->build(ContainerDependentStub::class));
}
}

class ContainerConcreteStub
Expand Down