Skip to content

Allow prepending extension config in DI Loader (XML/YAML) #52789

Closed
@solverat

Description

@solverat

Description

Given: A Bundle extension with an implemented PrependExtensionInterface

public function prepend(ContainerBuilder $container): void
{
    $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../config'));
 
    if ($specialConditionTriggers) {
        $loader->load('my_config_and_services.yaml');
    }
}

The Problem: The Loader (in this example, I'm using the YAML file loader) calls loadFromExtension, and so the configuration part gets appended:

$this->container->loadFromExtension($namespace, $values);
}

Adding a new argument to the loader methods load() is probably not the best solution regarding BC, but maybe we could add a second load method? For example:

public function prependLoad(mixed $resource, string $type = null) {}

For now, I need to split up those configuration / service files, then I also have to parse the configuration manually to finally use prependExtensionConfig in my extension. This feels a bit odd because there is a service that could actually do it for me. :)

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions