Add support for when@ in case bundle imports yaml configuration #63489
-
DescriptionIt'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 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 ExampleJust 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 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment · 1 reply
-
|
It doesn't work because you don't pass all necessary arguments to the loaders, see then $env one esp. |
Beta Was this translation helpful? Give feedback.
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.