-
-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow indexed non-empty arrays being valid parameter values #106
Allow indexed non-empty arrays being valid parameter values #106
Conversation
Thanks for that work, still I'm conflicted: indeed, that's a problem that we can't define arrays for now. But this solution is only partial: it works only for non-indexed and non-empty arrays. So there's confusion with that solution, because users might think that it's possible to define arrays, whereas it's very restricted. Anyway that's a fundamental problem, your solution could be merged for a 3.x version. For 4.0, I'd like to fix this definitely (don't know yet what's the best solution for that). |
I prefer this one to be honest:
In 3.x it's possible to create method like Container without arrays is very restricted for me. For instance, I cannot define list of emails for reports. Current format doesn't allow me to call some method twice. So I cannot define dependency neither $reportCommand->addEmail('bob@acme.example.com');
$reportCommand->addEmail('alice@acme.example.com'); nor $reportCommand->setEmailList(['bob@acme.example.com', 'alice@acme.example.com']); |
That's what I was thinking for 4.0. It's less "simple", but at least it will allow to offer 100% functionalities.
+1, totally right
Yes I'm facing the same limitations, that's why I want to move 4.0 forward. So to sum up, OK to merge this feature in 3.4 while waiting for a better solution for 4.0. I'll do it later I can't right now. Thanks |
This is now merged in the 3.4 branch (manually merged), thank you for updating the docs too. |
FYI v3.4 is now published (http://mnapoli.fr/PHP-DI/news/04-php-di-3-4), thanks again |
There is a typo: "Note that the arrays have to be non-indexed", you wanted to say "indexed non-empty". |
Right I forgot about non-empty. However they need to be "not (string) indexed" too, i.e.: foo:
bar: baz
bim: bam is not possible, whereas this works: foo:
- baz
- bam Maybe "non-indexed" is not really appropriate, do you see another way of putting it? |
Well, "indexed" means numeric keys for me, "string indexed" sounds weird. You can replace it with "list of values", for instance. |
Thanks I read the official doc and the proper terms are indexed VS associative array. So I edited the sentence to:
|
Currently, there is no way to store indexed arrays as values except direct call
$container->set(...)
:By the way, it's impossible to discern type of parameter (simple value or service) in case of empty array.
P.S. I didn't add this feature for
XmlDefinitionFileLoader
, anyway it looks not fully supported at this moment.