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 of Nette\DI\Statement.
If we have following .neon file configuration (real world example):
Implementation note the md5 hash can be fixed by using var_export or print_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 with Statement).
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
).