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
Discussion options

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
You must be logged in to vote

It doesn't work because you don't pass all necessary arguments to the loaders, see then $env one esp.
Also: the snippet you give here looks like bad practice: a bundle should have a fixed set of config files.
Sniffing around with a glob pattern fits apps, but the best practice for bundles is to use only the php format also.

Replies: 1 comment · 1 reply

Comment options

It doesn't work because you don't pass all necessary arguments to the loaders, see then $env one esp.
Also: the snippet you give here looks like bad practice: a bundle should have a fixed set of config files.
Sniffing around with a glob pattern fits apps, but the best practice for bundles is to use only the php format also.

You must be logged in to vote
1 reply
@jannes-io
Comment options

Oh awesome, seems like we were just missing the $env parameter.

I personally do not see the difference between us explicitly calling load on every file we want to add, or just using a glob pattern to automatically grab all files.

I largely distaste the "best practices" guides when they go 2 separate ways for apps and for bundles. The main point we always hammer about in our industry when it comes to code style is standardisation and consistency. Many have told me in the past that this "isn't best practice". But it works, it's fully supported, it's exactly the way we'd do it in apps, and it produces exactly the same result as configuring each file individually or directly in the build function. Additionally, this is all done on build time, so no performance issues. Up until this day, nobody has been able to give us a good argument besides "it's not best practice".

We're also not the typical bundle. Our bundle is a full "platform" or "subframework". We don't expect users to install our bundle alongside other Symfony bundles (besides those we listed as dependencies) or in a standard Symfony application. We use it more like Shopware, with Symfony as the backbone for wiring it all together. Our custom flex repo is highly customised and rips out most of the standard framework configuration so we can provide it through our bundle instead.

Answer selected by jannes-io
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #63488 on February 25, 2026 08:11.

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