Type the module translator example against the interface - #2166
Draft
boo-code wants to merge 1 commit into
Draft
Conversation
The container decides which translator a module receives and the debug environment decorates it, so the example's Translator type hint made a class that follows the documentation work with debug off and fail with it on. The unqualified name also resolved to nothing in a module namespace, and the assignment was missing its semicolon.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The "Other classes" example in
modules/creation/module-translation/new-system.mdis whatPrestaShop/PrestaShop#34138 reports. It is broken three ways:
public function __construct(Translator $translator)names a concrete class. The container decideswhich translator a module receives and the debug environment decorates it, so a class following the
example works with debug off and throws with it on.
Translatoris unqualified, so inside a module namespace it resolves to a class that does not exist.$this->translator = $translatoris missing its semicolon, so the snippet does not compile.The change types the parameter as
PrestaShopBundle\Translation\TranslatorInterface, adds theuseline the snippet needs, fixes the semicolon, and says in one sentence why the interface rather than a
concrete class.
Paired with a core branch (
fix/translator-contract-is-the-interface-34138, basedevelop) that makesthat interface declare everything the core calls on a translator, since it previously did not declare
setLocale()orgetCatalogue().