symfony-service-definition-validator
symfony-service-definition-validator copied to clipboard
add support for Parameter references
Hi,
There was missing support for use of the Parameter class, i.e creating services like this:
$definition = new Definition(new Parameter('app.service.class'));
$definition->addArgument(new Parameter('app.array'))
I couldn't see a way to put the fixing logic in one place. Possibley a refactor would make it cleaner.
Also I've not been able to really write a test for the array parameter fix, as your ArgumentValidatorTest only tests failure cases, unless you want a non failure test for this particular edge case.
Also, there is no check that the container actually has the parameter requested, so that's another edge case.
Let me know how what you think!
Thanks
Thanks! I'll try to look into this soon.
It seems that the Parameter class has been added in Symfony 2.7. Do you know how this works? For example, does class: %app.class% in Yaml get translated to new Definition(new Parameter('app.class'))? What about '%app.class%%some_other_parameter'? If that doesn't work/isn't allowed, your PR looks good to me :)
To add a test which covers your modification to ArgumentValidator you might also add a functional test, loading some Yaml which results in a definition with a Parameter object.
@matthiasnoback The class is present in Symfony 2.3 too: https://github.com/symfony/symfony/blob/2.3/src/Symfony/Component/DependencyInjection/Parameter.php
@xabbuh Interesting! Didn't know that.
This seems like something that would be useful to tackle. There was one open question from myself ("What about '%app.class%%some_other_parameter'?"). If any of you has time to look into this, please let me know if this is safe to merge. I think it is, but that's intuition ;)
@matthiasnoback For nested parameters you may want to take a look into the logic triggered by the resolve() method of the ParameterBag class.
It seems this is required for making this usable with Symfony 3.4.
Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
PHP Fatal error: Uncaught Matthias\SymfonyServiceDefinitionValidator\Exception\InvalidServiceDefinitionsException: Service definition validation errors (11):
- services_resetter: Type-hint "Traversable" requires this argument to be a reference to a service or an inline service definition
- session.storage.native: Argument of type "string" should have been an array
- security.role_hierarchy: Argument of type "string" should have been an array
- doctrine.dbal.connection_factory: Argument of type "string" should have been an array
- doctrine: Argument of type "string" should have been an array
at least for session.storage.native it seems that a parameter is used: https://github.com/symfony/symfony/blob/3.4/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml#L30 which is recognised as a string although it represents an array
Parameter actually exists since 2.0.0
FYI: I got the update to Symfony 3.4 working with this: https://github.com/zikula/symfony-service-definition-validator/compare/65868c8b0326e09c1f437c9ee1e53a9eb0237e6c...bdafa1be7c80bd8a69d860c7f9d586e61d1fb69e