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
Circular definitions #816
Comments
Wow, and sorry for starting with a complaint. I really enjoyed setting up a VM using Vagrant on my private and available machine in the last hour, then trying to run your code to see what would happen. There are plenty of syntax errors in it. So instead of (after providing a reasonable environment for it) copy-and-paste your example and immediately see your problem, I am now having to fix the syntax problems first. I can't really blame you because it seems you tried to create a reasonable example on the fly, but still that's something I would put as your responsibility: Use working code to describe your problem, making it as easy as possible for anyone trying to figure out your problem what you did and experienced. So after fixing the various errors, and especially removing the
No error, but a reasonable return value based on the fact that your example code is duplicating the "settings" key, i.e. you are supposed to work on the single value that is identified by the key "settings", which is just the array "acme", and you should return any changes to that, not duplicate "settings" again. So your current report, in my view, is invalid as is. Please go back and illustrate it with a working example. I can imagine that maybe if your code uses the DI container again to fetch more dependencies, when fetching dependencies on decorated elements that require fetching again, you'd end up with a circular exception. |
Hi, Like I explained above, 2 files with 'settings' works fine, but not more than 2 files - if my way of doing it is wrong then all combinations of below will produce an error, unless its an implicit restriction to decorate the same entry more than once, which from a practical strategy point makes sense?: This works fine:
But this produces an error:
Thank you. |
Well, if you change your code to
then it does work with more than two files for me (using PHP-DI 6.3.5 during my tests after downgrading from 6.4.0, on PHP 8.0). Note that if you pass an array, this is seen as a single parameter, which has to contain definitions. The Regarding your decorating code: Remember that you'll
is returning
And if you want to ask the database for the value, you can do that as well. But consider avoiding unnecessary work. PHP-DI will probably decorate multiple times because if you add for example a caching layer and then another layer around an object, you'll expect both layers. So in your case where only one scalar result is returned, it is useless to ask the database if the last decorator is overwriting the result anyways. I assume your original situation is different, but still I feel this should be mentioned. |
Thank you very much for the time spent on this, I will give it a try. |
Did not have time to play with this again until now... I tried new clean basic implementations from the official docs etc. and the short story is: |
I am using Slim Framework 4 and adding multiple definition files, but getting Circular Errors when I try to decorate() an existing definition from another file.
/var/www/vendor/php-di/php-di/src/Container.php: line 384
if (isset($this->entriesBeingResolved[$entryName])) {
throw new DependencyException("Circular dependency detected while trying to resolve entry '$entryName'");
}
All the below files returns an array of definitions, and works fine when I remove definitions_b.php or definitions_c.php, meaning it works fine when there are not more than 2 files trying to define and/or alter the same definition.
file definitions_a.php
file definitions_b.php
file definitions_c.php
I do understand the non-related problem of order-of-adding, but would please like your advice on the above.
The text was updated successfully, but these errors were encountered: