Bugfix: anonymous commands can't have same argument sequence #45
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When we register commands as anonymous services with parameters, they get registered in container with name "command(md5hash)". The MD5 is constructed from
json_encode
, which encodes instance ofNette\DI\Statement
.If we have following
.neon
file configuration (real world example):The second command fails to register with message
Service 'console.command.b84a00605660d460bba12d52a02bf1d8' has already been added.
This is because the md5 hash actually hashes only public properties of the
Statement
- which does not contain the class name.Test code in ConsoleExtension.php:78
Test output
Effectively, all anonymous commands with constructor-inject, were hashed solely based on their parameter sequence.
Fixed debug code:
Fixed debug output:
Implementation note the md5 hash can be fixed by usingvar_export
orprint_r($entity, true)
instead of JSON. Since JSON has been selected originally, I tried to stick with something compact & human-readable (thus prepending the name if working withStatement
).