How to deep merge arrayPrototype in SymfonyConfiguration

I have following configuration:

        $treeBuilder = new TreeBuilder('rest_api');
        $treeBuilder->getRootNode()
            ->addDefaultsIfNotSet()
            ->children()
                ->arrayNode('exceptions')
                    ->defaultValue([])
                    ->arrayPrototype()
                        ->scalarPrototype()
                        ->end()
                    ->end()
                ->end()
            ->end();

And following 2 files in 2 different bundles:

rest_api:
  exceptions:
    404:
      - UserNotFoundException
    400:
      - InvalidCredentailsException
rest_api:
  exceptions:
    404:
      - NotFoundHttpException
    400:
      - SomeRandomException
      - OtherRandomException

I wanted the result to look like this:

^ array:1 [
  "exceptions" => array:4 [
    404 => array:1 [
      0 => "NotFoundHttpException"
      1 => "UserNotFoundException"
    ]
    400 => array:2 [
      0 => "SomeRandomException"
      1 => "OtherRandomException"
       => "InvalidCredentailsException"
    ]
  ]
]

But instead I get this:

^ array:1 [
  "exceptions" => array:4 [
    404 => array:1 [
      0 => "NotFoundHttpException"
    ]
    400 => array:2 [
      0 => "SomeRandomException"
      1 => "OtherRandomException"
    ]
    405 => array:1 [
      0 => "UserNotFoundException"
    ]
    406 => array:1 [
      0 => "InvalidCredentailsException"
    ]
  ]
]

How can I enable deep merging of arrayPrototypes?

I tried with both using integers and strings as key names, changing keys to something non numeric: c404, c400, as well as both settings from documentation: performNoDeepMerging and cannotBeOverwritten but none seem to work.

What I need is something like performDeepMerging option or something similar, but I dont see it anywhere.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *