Skip to content

Conversation

@sveneld
Copy link
Contributor

@sveneld sveneld commented Oct 19, 2025

…bles for enabled locales

Q A
Branch? 7.4
Bug fix? no
New feature? no
Deprecations? no
License MIT

This pull request is a result of discussion #61745
It gives a possibility to set enabledLocales via env variable.

@carsonbot carsonbot added this to the 7.4 milestone Oct 19, 2025
@sveneld sveneld force-pushed the enabled_locales_configuration branch 2 times, most recently from 17228a8 to 7e697a7 Compare October 19, 2025 14:07
@sveneld sveneld force-pushed the enabled_locales_configuration branch from 7e697a7 to 8fe1a87 Compare October 19, 2025 14:21
@sveneld
Copy link
Contributor Author

sveneld commented Oct 22, 2025

@GromNaN take a look, please.

@stof
Copy link
Member

stof commented Oct 22, 2025

Resolving env placeholders in a compiler pass and replacing the parameter value is not a way to make env placeholders supported, as it does not respect the expected semantic. You will now need to clear your cache so that the new value of the env variable is taken into account.

So -1 for this PR.

@sveneld
Copy link
Contributor Author

sveneld commented Oct 24, 2025

but currently is the same situation, if in config provided a list of enabledLocales, after adding a new one you should rebuild cache

@sveneld
Copy link
Contributor Author

sveneld commented Oct 26, 2025

@stof if I use configuration like env(json:AVAILABLE_LOCALES) and try to use $container->resolveEnvPlaceholders($enabledLocales, true) i get an error

Symfony\Component\DependencyInjection\Exception\RuntimeException : Using a cast in "env(json:AVAILABLE_LOCALES)" is incompatible with resolution at compile time in "Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension". The logic in the extension should be moved to a compiler pass, or an env parameter with no cast should be used instead.

Do you have an alternative proposition for solving this situation?

Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without major changes to the router, it isn't possible to accept an environment variable in the routes configuration.

Sorry for giving you the wrong direction, I hadn't thought of everything.

}

private function registerTranslatorConfiguration(array $config, ContainerBuilder $container, LoaderInterface $loader, string $defaultLocale, array $enabledLocales): void
private function registerTranslatorConfiguration(array $config, ContainerBuilder $container, LoaderInterface $loader, string $defaultLocale): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the translator, there is only this type to modify to accept a parameter. The default.translator service car receive an %env(...)% value that is resolved by the DIC at runtime.

Suggested change
private function registerTranslatorConfiguration(array $config, ContainerBuilder $container, LoaderInterface $loader, string $defaultLocale): void
private function registerTranslatorConfiguration(array $config, ContainerBuilder $container, LoaderInterface $loader, string $defaultLocale, array|string $enabledLocales): void

But it needs a bit of refactoring to merge the lists from enabled locales and providers at runtime in the commands.

}

private function registerRouterConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader, array $enabledLocales = []): void
private function registerRouterConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepting environment variables in the router isn't possible. The values are dumped in the routing cache, in a big regex for the url matcher.

The expression language is the only way we have currently to match parts of the request with env var.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants