Skip to content

Sync Twig templateExists behaviors #33792

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

Merged
merged 1 commit into from
Oct 2, 2019

Conversation

fancyweb
Copy link
Contributor

@fancyweb fancyweb commented Oct 1, 2019

Q A
Branch? 4.3
Bug fix? no
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

There are 5 places in the code that does the same check, but they are not consistent. The difficulty here is to support Twig 1, 2 & 3. I think relying on Environment::MAJOR_VERSION is OK. method_exists are useless IMO. The proof is that they are currenty missing in some of them.

Basically if Twig >= 2 -> the method exists exists on the loader so just call it.

For Twig 1, check ExistsLoaderInterface, then check for SourceContextLoaderInterface, then call getSource().

Copy link
Member

@yceruto yceruto left a comment

Choose a reason for hiding this comment

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

Why not since 3.4?

@fancyweb
Copy link
Contributor Author

fancyweb commented Oct 1, 2019

Because I did not think about it 😓, I will have a look.

@fancyweb fancyweb force-pushed the template-exists-43 branch from cd81fb1 to d28558a Compare October 1, 2019 15:12
@fancyweb fancyweb changed the base branch from 4.3 to 3.4 October 1, 2019 15:12
@fancyweb fancyweb force-pushed the template-exists-43 branch from d28558a to d7682fe Compare October 1, 2019 15:13
@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Oct 2, 2019
@nicolas-grekas
Copy link
Member

Thank you @fancyweb.

nicolas-grekas added a commit that referenced this pull request Oct 2, 2019
This PR was merged into the 3.4 branch.

Discussion
----------

Sync Twig templateExists behaviors

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

There are 5 places in the code that does the same check, but they are not consistent. The difficulty here is to support Twig 1, 2 & 3. I think relying on `Environment::MAJOR_VERSION` is OK. `method_exists` are useless IMO. The proof is that they are currenty missing in some of them.

Basically if Twig >= 2 -> the method `exists` exists on the loader so just call it.

For Twig 1, check `ExistsLoaderInterface`, then check for `SourceContextLoaderInterface`, then call `getSource()`.

Commits
-------

d7682fe Sync Twig templateExists behaviors
@nicolas-grekas nicolas-grekas merged commit d7682fe into symfony:3.4 Oct 2, 2019
@fancyweb fancyweb deleted the template-exists-43 branch October 2, 2019 08:35
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.

4 participants