Skip to content

[Config] Purpose and Misusage of Component #20011

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

Closed
chr-hertel opened this issue Jul 2, 2024 · 8 comments · Fixed by #20012
Closed

[Config] Purpose and Misusage of Component #20011

chr-hertel opened this issue Jul 2, 2024 · 8 comments · Fixed by #20012
Labels
Config hasPR A Pull Request has already been submitted for this issue.

Comments

@chr-hertel
Copy link
Contributor

Hi there,

over the last years I came across multiple occasions where I felt like the config component being misused for application config and I wonder if that's only me, if you feel like this is an issue we should address in the docs of the component or if the best practices address it enough in an indirect manner. Maybe I missed a part in the docs, that already clarify - or I'm simply wrong here.

My understanding:
The config component provides a solution for defining a configuration contract between two parties, e.g. a bundle provider and a bundle consumer.

It is not meant to define an applications configuration, but this is what I sometimes see - developers going an extra mile defining and validating their applications configuration. Do you consider this a bad practice? should we point this out here or is it me?

Thanks already for your feedback!

@fabpot
Copy link
Member

fabpot commented Jul 2, 2024

Using the Config component for userland configuration is a valid use case even if probably overkill most of the time.
The main use case for the Config component is to be able to validate the configuration, so it makes sense if the config is going to be reused multiple times.

@derrabus
Copy link
Member

derrabus commented Jul 2, 2024

Hello Christopher,

thank you for raising this topic.

the config component being misused for application config

I'm having trouble with the term "misuse" in that context. You totally can use the config component for application configuration. It's just not how the component is used in new Symfony applications out of the box. And in many scenarios, the Config component might simply be a bad fit for application configuration.

My understanding:
The config component provides a solution for defining a configuration contract between two parties, e.g. a bundle provider and a bundle consumer.

💯

And those two parties could as well be the vendor of an application and the integrator of said application. Imagine you develop an COTS application that your customers can install on their own systems. Whoever conducts the installation (lets call them integrator) has probably no idea what a bundle is or even that your application uses Symfony as an application framework. They simply want to set up your application for themselves or their users.

In this context, it might make sense to establish a well-defined configuration file format (e.g. in YAML or XML), and the config component gives you all the tools you need to validate and process such a configuration. Apart from that, you're pretty much on your own. You will probably need to translate that application configuration into a framework configuration or implement other means of caching because processing configuration is expensive and you don't want to do that e.g. on each request.

What I've outlined here is one of multiple valid solutions to a problem that only a few applications built with Symfony need to solve. The goal of the best practice guide however is to provide very broad and general advice for developing Symfony applications in a somewhat beginner-friendly way. It should be read as, "follow those practices unless you have a good reason not to". The guide is certainly not a one-size-fits-all solution simply because there are just so many different types of applications that you can build with a general-purpose application framework like Symfony.

In that light, I'm very much happy with the current recommendation of using parameters for application configuration. In most applications, you might not even need any application configuration at all. And even if you do, using the Config component might be overkill.

@wouterj
Copy link
Member

wouterj commented Jul 2, 2024

The Config component is great in validating and merging multiple sources of configuration (and also loading different formats). So the use-case of application configuration is not necessarily "misuse", although it will be overkill for most.

The section you linked is already talking a lot about using parameters for application configuration, but maybe we can be more explicit about it vs the Config component (it's currently focusing on env vars vs container parameters): #20012

@javiereguiluz javiereguiluz added the hasPR A Pull Request has already been submitted for this issue. label Jul 2, 2024
@chr-hertel
Copy link
Contributor Author

Thanks everyone for answering and yes, misuse is maybe too strong of an Assessment, but Overkill in a sense of introducing too much complexity for something that could be solved differently.

Also pointing out that merging feature is a good one - and we also have the use-case of a monolithic system with multiple teams around one central configuration.

Thanks @wouterj for directly acting on it ❤️

Would you agree on main features being:

  • Defining a config structure, incl. validation, defaults & docs
  • Supporting different config formats
  • Merging different files into unified config

Maybe as an addon for the component docs?

@OskarStark
Copy link
Contributor

Would you agree on main features being

Yes 👍

@derrabus
Copy link
Member

derrabus commented Jul 9, 2024

Would you agree on main features being:

  • Defining a config structure, incl. validation, defaults & docs
  • Supporting different config formats
  • Merging different files into unified config

Sounds about right.

@javiereguiluz
Copy link
Member

javiereguiluz commented Jul 16, 2024

@chr-hertel I think that #20012 doesn't fully solve your concerns ... so I propose #20044 to better clarify the purpose of the Config component. Thanks.

@chr-hertel
Copy link
Contributor Author

Would be a great addition to address that topic IMO 👍

javiereguiluz added a commit that referenced this issue Jul 17, 2024
…viereguiluz)

This PR was merged into the 5.4 branch.

Discussion
----------

[Config] Clarify the purpose of the Config component

Fixes #20011.

Commits
-------

0b4c378 Clarify the purpose of the Config component
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Config hasPR A Pull Request has already been submitted for this issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants