Skip to content

Commit

Permalink
Merge pull request #279 from ray-di/remove_implicit_untarget_bindings
Browse files Browse the repository at this point in the history
Remove implicit untarget bindings
  • Loading branch information
koriym committed Dec 6, 2022
2 parents 416bc48 + 0b6dbdb commit 53bb56b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 45 deletions.
5 changes: 3 additions & 2 deletions src/di/AssistedInterceptor.php
Expand Up @@ -17,6 +17,7 @@
use function class_exists;
use function in_array;
use function interface_exists;
use function is_string;
use function parse_str;

/**
Expand Down Expand Up @@ -96,8 +97,8 @@ private function getName(ReflectionMethod $method, ReflectionParameter $paramete

parse_str($named->value, $names);
$paramName = $parameter->getName();
if (isset($names[$paramName])) {
return (string) $names[$paramName];
if (isset($names[$paramName]) && is_string($names[$paramName])) {
return $names[$paramName];
}

return Name::ANY;
Expand Down
4 changes: 0 additions & 4 deletions src/di/Untarget.php
Expand Up @@ -31,10 +31,6 @@ public function __invoke(Container $container, Bind $bind): void
$bound->setScope($this->scope);
$bind->setBound($bound);
$container->add($bind);
$constructor = $this->class->getConstructor();
if ($constructor) {
(new UntargetedBind())($container, $constructor);
}
}

public function setScope(string $scope): void
Expand Down
38 changes: 0 additions & 38 deletions src/di/UntargetedBind.php

This file was deleted.

7 changes: 6 additions & 1 deletion tests/di/InjectorTest.php
Expand Up @@ -152,7 +152,12 @@ public function testGetConcreteClass(): void

public function testGetConcreteHavingDependency(): void
{
$injector = new Injector();
$injector = new Injector(new class extends AbstractModule{
protected function configure()
{
$this->bind(FakeRobot::class);
}
});
$team = $injector->getInstance(FakeRobotTeam::class);
$this->assertInstanceOf(FakeRobotTeam::class, $team);
$this->assertInstanceOf(FakeRobot::class, $team->robot1);
Expand Down

0 comments on commit 53bb56b

Please sign in to comment.