-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[FrameworkBundle] Add EnabledLocalesPass to process environment varia… #62108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 8.1
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Symfony package. | ||
| * | ||
| * (c) Fabien Potencier <fabien@symfony.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; | ||
|
|
||
| use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
| use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
| class EnabledLocalesPass implements CompilerPassInterface | ||
| { | ||
| public function process(ContainerBuilder $container): void | ||
| { | ||
| $enabledLocales = $container->resolveEnvPlaceholders($container->getParameter('kernel.enabled_locales'), true); | ||
| $container->setParameter('kernel.enabled_locales', $enabledLocales); | ||
|
|
||
| if ($container->hasDefinition('translator.default')) { | ||
| $translator = $container->findDefinition('translator.default'); | ||
| $translator->setArgument(5, $enabledLocales); | ||
| } | ||
| if ($container->hasDefinition('routing.loader')) { | ||
| $routing = $container->findDefinition('routing.loader'); | ||
| if ($enabledLocales) { | ||
| $routingEnabledLocales = implode('|', array_map('preg_quote', $enabledLocales)); | ||
|
Check failure on line 34 in src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/EnabledLocalesPass.php
|
||
| $routing->replaceArgument(2, ['_locale' => $routingEnabledLocales]); | ||
| } | ||
| } | ||
|
|
||
| $providerDefinitions = [ | ||
| 'translation.provider_collection_factory' => 1, | ||
| 'console.command.translation_pull' => 5, | ||
| 'console.command.translation_push' => 3, | ||
| ]; | ||
|
|
||
| $locales = $enabledLocales; | ||
|
|
||
| foreach ($providerDefinitions as $definitionId => $argumentIndex) { | ||
| if ($container->hasDefinition($definitionId)) { | ||
| $definition = $container->getDefinition($definitionId); | ||
| $locales = array_merge($locales, $definition->getArgument($argumentIndex)); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| foreach ($providerDefinitions as $definitionId => $argumentIndex) { | ||
| if (!$container->hasDefinition($definitionId)) { | ||
| continue; | ||
| } | ||
| $definition = $container->getDefinition($definitionId); | ||
| $definition->replaceArgument($argumentIndex, $locales); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -447,10 +447,10 @@ public function load(array $configs, ContainerBuilder $container): void | |||||
| $this->registerEsiConfiguration($config['esi'], $container, $loader); | ||||||
| $this->registerSsiConfiguration($config['ssi'], $container, $loader); | ||||||
| $this->registerFragmentsConfiguration($config['fragments'], $container, $loader); | ||||||
| $this->registerTranslatorConfiguration($config['translator'], $container, $loader, $config['default_locale'], $config['enabled_locales']); | ||||||
| $this->registerTranslatorConfiguration($config['translator'], $container, $loader, $config['default_locale']); | ||||||
| $this->registerWorkflowConfiguration($config['workflows'], $container, $loader); | ||||||
| $this->registerDebugConfiguration($config['php_errors'], $container, $loader); | ||||||
| $this->registerRouterConfiguration($config['router'], $container, $loader, $config['enabled_locales']); | ||||||
| $this->registerRouterConfiguration($config['router'], $container, $loader); | ||||||
| $this->registerPropertyAccessConfiguration($config['property_access'], $container, $loader); | ||||||
| $this->registerSecretsConfiguration($config['secrets'], $container, $loader, $config['secret'] ?? null); | ||||||
|
|
||||||
|
|
@@ -1347,7 +1347,7 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| private function registerRouterConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader, array $enabledLocales = []): void | ||||||
| private function registerRouterConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void | ||||||
| { | ||||||
| if (!$this->readConfigEnabled('router', $container, $config)) { | ||||||
| $container->removeDefinition('console.command.router_debug'); | ||||||
|
|
@@ -1374,11 +1374,6 @@ private function registerRouterConfiguration(array $config, ContainerBuilder $co | |||||
| $container->getDefinition('routing.loader')->replaceArgument(1, ['utf8' => true]); | ||||||
| } | ||||||
|
|
||||||
| if ($enabledLocales) { | ||||||
| $enabledLocales = implode('|', array_map('preg_quote', $enabledLocales)); | ||||||
| $container->getDefinition('routing.loader')->replaceArgument(2, ['_locale' => $enabledLocales]); | ||||||
| } | ||||||
|
|
||||||
| if (!ContainerBuilder::willBeAvailable('symfony/expression-language', ExpressionLanguage::class, ['symfony/framework-bundle', 'symfony/routing'])) { | ||||||
| $container->removeDefinition('router.expression_language_provider'); | ||||||
| } | ||||||
|
|
@@ -1636,7 +1631,7 @@ private function createVersion(ContainerBuilder $container, ?string $version, ?s | |||||
| return new Reference('assets.empty_version_strategy'); | ||||||
| } | ||||||
|
|
||||||
| 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 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
But it needs a bit of refactoring to merge the lists from enabled locales and providers at runtime in the commands. |
||||||
| { | ||||||
| if (!$this->readConfigEnabled('translator', $container, $config)) { | ||||||
| $container->removeDefinition('console.command.translation_debug'); | ||||||
|
|
@@ -1672,7 +1667,6 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder | |||||
| $defaultOptions = $translator->getArgument(4); | ||||||
| $defaultOptions['cache_dir'] = $config['cache_dir']; | ||||||
| $translator->setArgument(4, $defaultOptions); | ||||||
| $translator->setArgument(5, $enabledLocales); | ||||||
|
|
||||||
| $container->setParameter('translator.logging', $config['logging']); | ||||||
| $container->setParameter('translator.default_path', $config['default_path']); | ||||||
|
|
@@ -1806,11 +1800,11 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder | |||||
| return; | ||||||
| } | ||||||
|
|
||||||
| $locales = $enabledLocales; | ||||||
| $locales = []; | ||||||
|
|
||||||
| foreach ($config['providers'] as $provider) { | ||||||
| if ($provider['locales']) { | ||||||
| $locales += $provider['locales']; | ||||||
| $locales = array_merge($locales, $provider['locales']); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
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.