3

I have been coding in SYmfony since last 6 months now. And after completing a couple of projects, I started exploring symfony in greater details. While exploring i came accross, TreeBuilder component. Now, i understood the concept TreeBuilder very well. Its basically used to dump config files in YML. But, the question is, why would one use TreeBUilder when you can directly modify the condig yml files.? Is there any other better use case where one should use TreeBUilder specificaly.? Could you please help me understand any use case. This will give me a better understanding.

1 Answer 1

2

According to documentation Tree builder is a component which can/should be used to validate configuration provided by end user.

Configuration values are usually expected to show some kind of hierarchy. Also, values should be of a certain type, be restricted in number or be one of a given set of values. For example, the following configuration (in YAML) shows a clear hierarchy and some validation rules that should be applied to it (like: "the value for auto_connect must be a boolean value")

So basically you can make a set of requirements to configuration of your bundle like

  • required
  • default value
  • type constraint

For complete reference check documentation

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Thomaz, pretty well understood. So that does that mean the TreeBuilder component has nothing to do while developing regular applications. TreeBuilder component should be used only when you are allowing your enduser to modify/provide a configuration directive. Simple use case may be : multi-tennant site or a image hosting site where an enduser has to specify his/her own configuration settings. I am right?
not really - your end-user does not have access or possibility to change values stored in config.yml. More common use case would be creating open source bundle which can be used by other developers - tree builder allows you to control developers - not end-users (www users so to speak)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.