Autowiring and Annotations do not work for `DI\object()` inside arrays #343
Comments
Is DI\object inside an array a correct usage? I mean you're already using DI\object to create the resolvable |
Having only one item in an array may be not really a usecase. But how would you solve something like this without an array: $builder->addDefinitions([
'logappenders'=>[
DI\object(Logappender1::class),
DI\object(Logappender2::class),
DI\object(Logappender3::class),
]
]) and maybe with a second defintion: $builder->addDefinitions([
'logappenders'=>DI\add([
DI\object(Logappender4::class),
])
]) |
That's weird indeed, thanks for the great bug report. The usage seems valid to me and I think I can see why it's not working… After a very quick look I'm not sure what the best fix would be, I'll try to have a look at it soon. As a workaround (in the meantime): [
'test' => [get(A::class)],
A::class => object(A::class),
]; |
I got the same error here. Any plan to fix it? |
I know what causes the bug (ArrayDefinition doesn't trigger autowiring on sub-definitions) but from what I remember it's not an easy one to fix and I don't have a lot of time available to work on it at the moment (publishing the last Slim bridge should have been 2 weeks ago for example). For anyone wanting to have a look at it: ArrayDefinition should me made to implement |
Thanks for your quick response & detail guides on this |
Just a hack, sorry if it completely against your vision: https://github.com/PHP-DI/PHP-DI/pull/426/files |
Hi everyone, this issue has been indirectly fixed by the replacement of |
Example code:
Executing the code above gives the following output:
changing the definitions to
$builder->addDefinitions(['test'=>DI\object(A::class)]);
works as expected.The text was updated successfully, but these errors were encountered: