Closed denfil closed 5 years ago
Try
$di->params[Test::class]['items'][] = 'one';
$di->params[Test::class]['items'][] = 'two';
or
$di->params[Test::class]['items'] = [ 'one' ,'two'];
@harikt it's not the same behaviour I want to get, because
__construct(...$items)
is not the same as __construct(array $items)
You see, in my example constructor should get two parameters of type string
new Test('one', 'two')
,
but in your solution it will get one parameter of type array
new Test(['one', 'two'])
I get you now. If you can send a patch I ll look into it. On Feb 19, 2018 4:29 PM, "Denis Filimonov" notifications@github.com wrote:
@harikt https://github.com/harikt it's not the same behaviour I want to get, because construct(...$items) is not the same as construct(array $items)
You see, in my example constructor should get two parameters of type string new Test('one', 'two'), but in your solution it will get one parameter of type array new Test(['one', 'two'])
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/auraphp/Aura.Di/issues/164#issuecomment-366655770, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHWht09MC6VlOA7qRBnzk-ngyU6MxmAks5tWVQigaJpZM4R26uA .
I've also experienced this issue, so I decided to create a patch. The approach I've taken is to treat the parameter as an array, then to expand it just before object instantiation using the (cached) reflection info.
Please consider applying this patch to the main branch soon, so I can avoid having to maintain a custom fork. Thanks.
Hey @marcusjhdon ,
Could you send a PR, it may be helpful.
Thank you.
Fixed in https://github.com/auraphp/Aura.Di/pull/167 . Will shortly push the new tag.
Sorry the issue looks not fixed yet. So re-opening it.
Resolver::resolve
method.I would suggest that this functionality can be achieved by using a mutation as in PR #176 or by using factory and that the library should not resolve variadic arguments for setters.
Since #176 is merged into master, one can choose to mutate an object and therefore call methods with multiple arguments and/or variadic arguments.
Here is the code example:
Expected output is
Array ( [0] => one [1] => two )
but actual output isArray ( [0] => one )