Skip to content
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

Add support for Twig 3 #1807

Closed
wants to merge 2 commits into from
Closed

Add support for Twig 3 #1807

wants to merge 2 commits into from

Conversation

jorrit
Copy link
Contributor

@jorrit jorrit commented Sep 16, 2020

Subject

It seems Twig 3 support can be enabled without other changes.

I am targeting this branch, because using Twig 3 is backwards compatible.

Changelog

### Added
- Added support for Twig 3.

TODO:

@jorrit
Copy link
Contributor Author

jorrit commented Sep 16, 2020

For some reason the tests fail locally because \Sonata\Form\Validator\ErrorElement is final and some tests in FileProviderTest try to mock it. I have no idea why it works in GitHub actions.

@phansys
Copy link
Member

phansys commented Sep 16, 2020

@franmomu
Copy link
Member

By the way:

$ composer why-not twig/twig 3
sonata-project/formatter-bundle  4.2.0  requires  twig/twig (^2.12.1)

@jorrit
Copy link
Contributor Author

jorrit commented Sep 16, 2020

Sorry, what a rookie mistake. Tomorrow I'll see if the formatter bundle can be upgraded.

@franmomu
Copy link
Member

Sorry, what a rookie mistake. Tomorrow I'll see if the formatter bundle can be upgraded.

It's not rookie at all, I didn't know about that command until I saw it to @greg0ire

@jorrit
Copy link
Contributor Author

jorrit commented Sep 17, 2020

FormatterBundle requires the MediaBundle so there is a circular reference of two bundles requiring twig 2. What's the best approach here? Update one, check the other and then go back and check the first again?

@jordisala1991
Copy link
Member

Do you know if the media-bundle has any dependency with formatter-bundle? I mean, does it have: use Sonata\Formatter....; or on services.xml?

@jorrit
Copy link
Contributor Author

jorrit commented Sep 17, 2020

@jordisala1991: no, there is no code reference. In fact, it seems the only place the Formatter Bundle is referenced is to load an additional configuration file called formatter.xml, which loads a Twig extension. This Twig extension is needed by the Formatter Bundle but has no dependency on it.

I have removed the dev dependency and Twig 3 is installed now. I have fixed a breakage, but it seems nelmio/api-doc-bundle has to be updated too. This is quite some work: https://github.com/nelmio/NelmioApiDocBundle/blob/master/UPGRADE-3.0.md


/**
* @final since sonata-project/media-bundle 3.21.0
*/
class MediaExtension extends AbstractExtension implements InitRuntimeInterface
class MediaExtension extends AbstractExtension
Copy link
Member

Choose a reason for hiding this comment

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

BC Break alert

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this matter? I don't think anyone (should) rely on MediaExtension implements InitRuntimeInterface or not.

Copy link
Member

Choose a reason for hiding this comment

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

Does this matter? I don't think anyone (should) rely on MediaExtension implements InitRuntimeInterface or not.

Think about the result if a user is declaring a method (argument or return) with the removed interface. Does this matter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

InitRuntimeInterface is part of Twig 2 and removed in Twig 3. If the user refers to InitRuntimeInterface they can't upgrade to Twig 3.

Copy link
Member

Choose a reason for hiding this comment

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

AFAIK, we aren't dropping the support for twig/twig:2 in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true. The functionality of InitRuntimeInterface can be implemented diffently in a way that works both in Twig 2 and 3. InitRuntimeInterface is only used to inject the Twig\Environment and I've moved that to the classes in Twig\Node.

@jordisala1991
Copy link
Member

This PR should target master branch if it contains BC breaks.

@jorrit
Copy link
Contributor Author

jorrit commented Oct 14, 2020

This PR should target master branch if it contains BC breaks.

Perhaps I can do something with interface_exists()? Anyway, #1801 needs to be finished first.

@github-actions
Copy link

This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label May 17, 2021
@github-actions github-actions bot closed this May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants