-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] don't load translator services if not required #20928
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
Conversation
@@ -87,7 +87,7 @@ public function load(array $configs, ContainerBuilder $container) | |||
// A translator must always be registered (as support is included by | |||
// default in the Form component). If disabled, an identity translator | |||
// will be used and everything will still work as expected. | |||
if (class_exists('Symfony\Component\Translation\Translator') || $this->isConfigEnabled($container, $config['form'])) { | |||
if ($this->isConfigEnabled($container, $config['translator']) || $this->isConfigEnabled($container, $config['form'])) { | |||
if (!class_exists('Symfony\Component\Translation\Translator')) { | |||
throw new LogicException('Form support cannot be enabled as the Translation component is not installed.'); |
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.
The error message should probably be different for the first case.
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.
Indeed, updated it.
@@ -87,8 +87,12 @@ public function load(array $configs, ContainerBuilder $container) | |||
// A translator must always be registered (as support is included by | |||
// default in the Form component). If disabled, an identity translator | |||
// will be used and everything will still work as expected. | |||
if (class_exists('Symfony\Component\Translation\Translator') || $this->isConfigEnabled($container, $config['form'])) { | |||
if (!class_exists('Symfony\Component\Translation\Translator')) { | |||
if ($this->isConfigEnabled($container, $config['translator']) || $this->isConfigEnabled($container, $config['form'])) { |
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.
What about remove this condition then?
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.
We still need it to not always load the translation.xml
file (in case both the form
and the translator
section are not enabled).
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.
ah right, Github did not show the whole if code, so I as confused.
I would indeed go one step further and only register the identity if |
8711b67
to
1f86628
Compare
Fair enough, I included that change too. |
Woo, thank you @xabbuh! The identity translation stuff seemed a little fiddly and I'm totally unfamiliar with it so I didn't dare open a PR myself :) A small review: I spy the class already has if ($this->isConfigEnabled($container, $config['translator']) || $this->isConfigEnabled($container, $config['form']) || $this->isConfigEnabled($container, $config['validation'])) {
if (!class_exists('Symfony\Component\Translation\Translator') {
if ($this->isConfigEnabled($container, $config['translator'])) {
throw new LogicException('Translation support cannot be enabled as the Translation component is not installed.');
}
if ($this->isConfigEnabled($container, $config['form'])) {
throw new LogicException('Form support cannot be enabled as the Translation component is not installed.');
}
if ($this->isConfigEnabled($container, $config['validation'])) {
throw new LogicException('Validator support cannot be enabled as the Translation component is not installed.');
}
}
$loader->load('identity_translator.xml');
} |
@BPScott I don't think that's necessary as this code is only executed during compilation. |
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.
LGTM
Thank you @xabbuh. |
…t required (xabbuh) This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle] don't load translator services if not required | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20791 | License | MIT | Doc PR | One step further could be to remove all the loader services (or not register them at all) if only the identity translator is used (i.e. when only forms are enabled, but not translations), but that could be seen as a BC break. Commits ------- 1e67155 don't load translator services if not required
@xabbuh "templating.helper.translator" service has a dependency on translator and will not work if templating engine is set to "php" (see templating_php.xml) |
@inalgnu can you provide a PR that fixes the issue ? |
@aitboudad done here #21374 |
see #22006 |
…s disabled (xabbuh) This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle] remove translator helper if Translator is disabled | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20928 (comment), #21374 | License | MIT | Doc PR | Commits ------- 25ea510 remove translator helper if Translator is disabled
…s disabled (xabbuh) This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle] remove translator helper if Translator is disabled | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony/symfony#20928 (comment), #21374 | License | MIT | Doc PR | Commits ------- 25ea510ba4 remove translator helper if Translator is disabled
One step further could be to remove all the loader services (or not register them at all) if only the identity translator is used (i.e. when only forms are enabled, but not translations), but that could be seen as a BC break.