Skip to content

Conversation

@dbrekelmans
Copy link
Contributor

@dbrekelmans dbrekelmans commented Jul 28, 2020

Q A
Branch? master
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #37686
License MIT
Doc PR -

When constructing the TranslationExtension with any NodeVisitorInterface other than TranslationNodeVisitor, you will get a type error when calling getTranslationNodeVisitor(). This PR fixes that by extracting a new TranslationNodeVisitorInterface.

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

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

This change should be for master.

private $translationNodeVisitor;

public function __construct(TranslatorInterface $translator = null, NodeVisitorInterface $translationNodeVisitor = null)
public function __construct(TranslatorInterface $translator = null, TranslationNodeVisitorInterface $translationNodeVisitor = null)
Copy link
Member

Choose a reason for hiding this comment

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

Let's not create a new interface and type hint with TranslationNodeVisitor instead.

Copy link
Contributor Author

@dbrekelmans dbrekelmans Jul 29, 2020

Choose a reason for hiding this comment

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

That would limit flexibility without much benefit.

I have a use case for passing a different node visitor into this class (basically overwriting the trans function and adding an extra parameter). That was possible in symfony 4.4, because there was no return typehint on the getter. I came across this trying to upgrade to symfony ^5.0. Typehinting on the concrete class here would make that impossible, since the concrete class is final.

It's up to you. If you still prefer the concrete class typehint then I will change it. Let me know @fabpot 👍

@fabpot
Copy link
Member

fabpot commented Jul 29, 2020

Not a big fan of adding such an interface TBH. Your implementation extends the core one, right? In which case, type hinting with the class is not an issue.

@dbrekelmans
Copy link
Contributor Author

dbrekelmans commented Jul 29, 2020

My implementation does not extend the core one as the core one is declared final. We simply overwrite the TranslationExtension service using the core class and only passing a different NodeVisitor as second argument

As it stands we've already had to copy and modify a few core classes (TransNode for example) to make our implementation work, so to upgrade to symfony 5 we could do the same with TranslationExtension.

I will change the typehint to TranslationNodeVisitor and target master.

@nicolas-grekas nicolas-grekas added this to the next milestone Jul 29, 2020
@dbrekelmans dbrekelmans changed the base branch from 5.0 to master July 29, 2020 14:25
@dbrekelmans dbrekelmans requested a review from fabpot July 30, 2020 08:10
@fabpot
Copy link
Member

fabpot commented Jul 30, 2020

Looks like there is an unrelated commit in the PR. Can you get rid of it?

@dbrekelmans
Copy link
Contributor Author

dbrekelmans commented Jul 31, 2020

Looks like there is an unrelated commit in the PR. Can you get rid of it?

Done @fabpot 👍

@fabpot
Copy link
Member

fabpot commented Jul 31, 2020

Thank you @dbrekelmans.

@fabpot fabpot merged commit 79bc5b7 into symfony:master Jul 31, 2020
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.2 Oct 5, 2020
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.

[TwigBridge] TranslationExtension constructor takes implementation but getter returns concrete class

4 participants