Skip to content

[Config] Support for dynamic array node definitions #17436

Closed
@sandrokeil

Description

@sandrokeil

To increase the interoperability it would be useful to have an option for dynamic array definitions in the configuration node builder. Framework agnostic libraries validates the configuration in the factory classes, so there is no need to redefine it for Symfony.

It exists a Symfony Interop Bundle which has support for dynamic array nodes. But this is not needed if we add an option to disable the exception and create a new ArrayNode instead like in the Symfony Interop Bundle.

Here is an example (useDynmicArray()):

class Configuration implements ConfigurationInterface
{
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();

        $rootNode = $treeBuilder->root('prooph');

        // our factories handles validation and we are flexible with keys
        $rootNode->ignoreExtraKeys(false);

        $rootNode->useDynamicArray(); // <-- new functionality

        return $treeBuilder;
    }
}

Activity

xabbuh

xabbuh commented on Jan 19, 2016

@xabbuh
Member

Can you explain what configuration I would be able to do with that new option I wasn't able to create before? I am not sure I understand what you would like to solve.

sandrokeil

sandrokeil commented on Jan 19, 2016

@sandrokeil
Author

If I provide a default configuration, in this case a PHP array, in the bundle and I want to override or extend the bundle configuration in the application config.yml I get the exception message merge() expects a normalized config array..

Instead of throwing an exception, I need to create a new instance of ArrayNode, so the config could be merged. Or do I miss something? Note, that I don't want to define the whole config structure with the tree builder.

For a test case, you can use a Symonfy demo app and add the prooph Symfony bundle and then put the example YAML configuration to your config.yml file and with the debug:config console command you should get the exception message if you change this line to array instead of dynamicArray.

carsonbot

carsonbot commented on Dec 20, 2020

@carsonbot

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @javiereguiluz@xabbuh@sandrokeil@carsonbot

        Issue actions

          [Config] Support for dynamic array node definitions · Issue #17436 · symfony/symfony