Skip to content
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

[DependencyInjection] Should be able to ignore missing parameter #15578

Closed
Taluu opened this issue Aug 19, 2015 · 2 comments
Closed

[DependencyInjection] Should be able to ignore missing parameter #15578

Taluu opened this issue Aug 19, 2015 · 2 comments

Comments

@Taluu
Copy link
Contributor

Taluu commented Aug 19, 2015

Like in the service container, we should be able to specify on a missing parameter (such in the use of <argument on-invalid="ignore">) that if it doesn't exist, it should be ignored (given a null value).

Basically, this is adding a new parameter to the get method of the ParameterBag (in https://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php#L89), and messing with the dumpers so that if there is the right attribute (on-invalid ?), it should be able to be ignored.

To keep BC, and also to have a default mechanism, like in the service container, it should throw the exception if it is missing.

@linaori
Copy link
Contributor

linaori commented Aug 20, 2015

I don't agree with this. Services can be missing due to optional dependencies, but parameters should never be relied on if they come from a third party package. If you want to expose parameters, make sure they are always define, but (e.g) setting arguments of service constructors should be done by config and dependency injection rather than injecting a parameter.

When it comes to your AppBundle, you can just define the parameters yourself and make sure they always exist. Personally I only define them in parameters.yml if they differ per environment.

@jakzal
Copy link
Contributor

jakzal commented Sep 16, 2015

I agree with @iltar on this. You can always provide defaults for your parameters, or use semantic configuration. It's much easier to understand what's going on this way.

Anyway, adding an argument to a method annotated with @api is not allowed (see our BC promise), so I'll need to close this one.

@jakzal jakzal closed this as completed Sep 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants