-
-
Notifications
You must be signed in to change notification settings - Fork 324
Autowiring and Annotations do not work for DI\object() inside arrays #343
Copy link
Copy link
Closed
Description
Example code:
<?php
require 'vendor/autoload.php';
class A {
public function __construct(B $b) {}
}
class B {
/**
* @Inject
*/
public function test() {
echo "Autowiring and Annotations work.";
}
}
$builder=new DI\ContainerBuilder();
$builder->useAnnotations(true);
$builder->addDefinitions([
'test'=>[DI\object(A::class)]
]);
$container=$builder->build();
try {
$container->get('test');
}
catch (Exception $e)
{
echo $e->getMessage();
}Executing the code above gives the following output:
Error while resolving test[0]. Entry cannot be resolved: The parameter 'b' of A::__construct has no value defined or guessable
Full definition:
Object (
class = A
scope = singleton
lazy = false
)
changing the definitions to $builder->addDefinitions(['test'=>DI\object(A::class)]); works as expected.
Reactions are currently unavailable