Repository navigation
2.3.0
This release supports @Assisted injection.
It is possible to inject dependencies directly in the invoke method parameter(s). When doing this, add the dependency to the end of the arguments and set the default value to null, it is also required to annotate the method using @assisted.
module
class FooModule extends AbstractModule
{
protected function configure()
{
$this->bind(RobotInterface::class)->to(Robot::class);
$this->bind()->annotatedWith('one')->toInstance(1);
}
}dependent
class AssistedConsumer
{
/**
* @Assisted({"robot"})
*/
public function foo(RobotInterface $robot)
{
return $robot;
}
/**
* @Assisted({"var1"})
* @Named("var1=one")
*/
public function bar($a, $var1)
{
return $var1;
}
/**
* @Assisted({"var2", "robot"})
* @Named("var2=one")
*/
public function baz($var2, FakeRobotInterface $robot)
{
return [$var2 , $robot];
}
}
$consumer->foo(); // Robot
$consumer->bar(0); // 1
$consumer->baz(); // [1, Robot]