symfony-service-definition-validator icon indicating copy to clipboard operation
symfony-service-definition-validator copied to clipboard

add support for Parameter references

Open bendavies opened this issue 9 years ago • 9 comments

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

bendavies avatar Jan 21 '16 14:01 bendavies

Thanks! I'll try to look into this soon.

matthiasnoback avatar Jan 22 '16 09:01 matthiasnoback

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 avatar Feb 18 '16 22:02 matthiasnoback

@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 avatar Feb 19 '16 10:02 xabbuh

@xabbuh Interesting! Didn't know that.

matthiasnoback avatar Feb 21 '16 20:02 matthiasnoback

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 avatar Feb 08 '17 11:02 matthiasnoback

@matthiasnoback For nested parameters you may want to take a look into the logic triggered by the resolve() method of the ParameterBag class.

xabbuh avatar Feb 08 '17 11:02 xabbuh

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

Guite avatar Dec 01 '17 09:12 Guite

Parameter actually exists since 2.0.0

stof avatar Dec 01 '17 12:12 stof

FYI: I got the update to Symfony 3.4 working with this: https://github.com/zikula/symfony-service-definition-validator/compare/65868c8b0326e09c1f437c9ee1e53a9eb0237e6c...bdafa1be7c80bd8a69d860c7f9d586e61d1fb69e

Guite avatar Dec 13 '17 17:12 Guite