Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8569775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:24:55+00:00 2026-06-11T18:24:55+00:00

I created a Configuration class and build a tree that defines my configuration in

  • 0

I created a Configuration class and build a tree that defines my configuration in that class,but I guess it’s very ugly then my question is to find a solution to simplify my class?

<?php
  namespace Myapp\Mybundle\DependencyInjection;

  use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
  use Symfony\Component\Config\Definition\Builder\TreeBuilder;
  use Symfony\Component\Config\Definition\ConfigurationInterface;


class Configuration implements ConfigurationInterface
{
/**
 * {@inheritDoc}
 */

public function getConfigTreeBuilder()
{

    $treeBuilder = new TreeBuilder();
    $rootNode = $treeBuilder->root('em_profession');

    $rootNode
        ->children()
                 ->arrayNode('region')
         ->isRequired()
                 ->requiresAtLeastOneElement()
                 ->useAttributeAsKey('id')
                            ->prototype('array')
                                       ->children()
                                             ->scalarNode('label')
                                             ->isRequired()
                                             ->cannotBeEmpty()->defaultValue('em_profession_label')->end()
                                             ->arrayNode('childrens') 
                                             ->isRequired()
                                             ->requiresAtLeastOneElement()
                                             ->useAttributeAsKey('id')
                                                     ->prototype('array')
                                                           ->children()
                                                                 ->scalarNode('label')->end()
                                                                 ->arrayNode('childrens')
                                                                 ->isRequired()
                                                                 ->requiresAtLeastOneElement()
                                                                 ->useAttributeAsKey('id')
                                                                      ->prototype('array')
                                                                            ->children()
                                                                                 ->scalarNode('label')->end()
                                                                                 ->arrayNode('childrens')
                                                                                 ->isRequired()
                                                                                 ->requiresAtLeastOneElement()
                                                                                 ->useAttributeAsKey('id')
                                                                                      ->prototype('array')
                                                                                            ->children()
                                                                                                 ->scalarNode('label')->end()
                                                                                                 ->arrayNode('childrens')
                                                                                                 ->isRequired()
                                                                                                 ->requiresAtLeastOneElement()
                                                                                                 ->useAttributeAsKey('id')
                                                                                                     ->prototype('array')
                                                                                                           ->children()
                                                                                                                ->scalarNode('label')->end()
                                                                                                                ->arrayNode('childrens')
                                                                                                                ->isRequired()
                                                                                                                ->requiresAtLeastOneElement()
                                                                                                                ->useAttributeAsKey('id')
                                                                                                                      ->prototype('array')
                                                                                                                       ->end()
                                                                                                                ->end()
                                                                                                           ->end()

                                                                                                     ->end()

                                                                                                  ->end()
                                                                                            ->end()
                                                                                       ->end()
                                                                                 ->end()
                                                                            ->end()

                                                                       ->end()

                                                                  ->end()
                                                         ->end()

                                                     ->end()

                                             ->end()
            
                                      ->end()
                             ->end()
         ->end()
        ->end()
    ;

    return $treeBuilder;
}

My configuration works fine but it’s very big so I which to minimize it to simplify it and to stop the repetition of code.

edit

OK, I know this solution but I guess I can’t apply it in my configuration, for example in Twig configuration file they use a custom function in the end of class after "->end()" but in my configuration I use it inside "prototype()" also I have a lot of repetition of code but child inside child inside child… so it’s difficult to minimize it correctly…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:24:56+00:00Added an answer on June 11, 2026 at 6:24 pm

    Like Twig configuration file: using methods:

    $rootNode = $treeBuilder->root('em_profession');
    $this->addMyCustomSection($rootNode);
    

    Then in addMyCustomSection method:

    private function addMyCustomSection(ArrayNodeDefinition $rootNode)
    {
        // Continue modifying $rootNode
    }
    

    Reference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a Configuration class and I build a tree that defines my configuration
I am trying to build a tree structure that represents a parsed configuration file
I have created two Hudson String Parameters in my parametrized build configuration: svnRoot ,
I created a simple hello-wordish code using hibernate sf = new Configuration().configure().buildSessionFactory(); System.out.println(sessionFactory is
I need to pass configuration settings to an AddIn created using the Managed AddIn
I have created two DbContexts, one is for application configuration, the second is for
Has anyone got this configuration working? Latest Netbeans, latest Glassfish, I created an EJB
I just downloaded the Springsource Tool Suite, and I created a simple bean configuration
I am working on a Rails app that allows you to create a configuration
I'm trying to use a Spring context namespace to build some existing configuration objects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.