Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add support for when@ in case bundle imports yaml configuration #63488

Copy link
Copy link
@jannes-io

Description

@jannes-io
Issue body actions

Description

It's currently very confusing and leads to frustration when certain features do not work depending on what context you are in.

For example, when you're in an application/userland, you can use when@<env> in any yaml configuration file to only load said configuration when running in that environment. But when you try and to that from a bundle, it doesn't work and you have to use packages/<env>/<config>.yaml

Given a bundle with a build method as such:

class MyBundle extends AbstractBundle
{
    public function build(ContainerBuilder $container): void
    {
        /** @var string $environment */
        $environment = $container->getParameter('kernel.environment');

        $configDir = $this->getConfigDir();
        $locator = new FileLocator($configDir);

        $resolver = new LoaderResolver([
            new YamlFileLoader($container, $locator),
            new GlobFileLoader($container, $locator),
            new DirectoryLoader($container, $locator),
            new ClosureLoader($container),
        ]);

        $configLoader = new DelegatingLoader($resolver);
        $configLoader->load("$configDir/{packages}/*.{yaml,yml,php}", 'glob');
        $configLoader->load("$configDir/{packages}/$environment/*.{yaml,yml,php}", 'glob');
    }

    protected function getConfigDir(): string
    {
        return $this->getPath() . '/config';
    }
}

You'd expect when@prod in the files found by this bundle to be respected, but in actuality, they're just silently ignored.

Example

Just being able to use the same yaml configuration including when@ keys when loading a config file from a bundle.

framework:
    cache:
        pools:
            cache.app:
                adapter: cache.adapter.system

when@prod:
    cache:
        framework:
            pools:
                cache.app:
                    adapters:
                        - cache.adapter.apcu
                        - cache.adapter.valkey
                    default_lifetime: 86400
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.