10000 [TwigBridge][TwigBundle][HttpKernel] prefer getSourceContext() over getSource() by xabbuh · Pull Request #20440 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TwigBridge][TwigBundle][HttpKernel] prefer getSourceContext() over getSource() #20440

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
Nov 7, 2016

Conversation

xabbuh
Copy link
Member
@xabbuh xabbuh commented Nov 7, 2016
Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #20435
License MIT
Doc PR n/a

@@ -75,14 +75,14 @@ public function exists($name)

$loader = $this->environment->getLoader();

if ($loader instanceof \Twig_ExistsLoaderInterface) {
if ($loader instanceof \Twig_ExistsLoaderInterface || method_exists($loader, 'exists')) {
Copy link
Member Author

Choose a reason for hiding this comment

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

In Twig 2.0, the exists() method will be present in the Twig_LoaderInterface.

Copy link
Member

Choose a reason for hiding this comment

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

This is not needed as Twig_ExistsLoaderInterface still exist in 2.0. It will be removed in 3.0 only.

Copy link
Member Author

Choose a reason for hiding this comment

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

The call to exists() will never be made though if the loader does not implement Twig_ExistsLoaderInterface, but is just an instance of Twig_LoaderInterface.

Copy link
Member

Choose a reason for hiding this comment

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

indeed

Copy link
Member Author

Choose a reason for hiding this comment

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

And this seems to happen. Otherwise, I don't see how #20435 would ever reach the getSource() call.

$loader->getSourceContext($template);
} else {
$loader->getSource($template);
}
Copy link
Contributor
@FrancescoBorzi FrancescoBorzi Nov 7, 2016

Choose a reason for hiding this comment

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

I would suggest: ... } else if (method_exists($loader, 'getSource')) { ... instead of line 150

return $loader->exists($template);
}

try {
$loader->getSource($template);
if (method_exists($loader, 'getSourceContext')) {
Copy link
Member

Choose a reason for hiding this comment

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

👍 as HttpKernel does not constrain Twig version.

@xabbuh
Copy link
Member Author
xabbuh commented Nov 7, 2016

fabbot failures are unrelated.

@fabpot
Copy link
Member
fabpot commented Nov 7, 2016

Thank you @xabbuh.

@fabpot fabpot merged commit adbc529 into symfony:2.7 Nov 7, 2016
fabpot added a commit that referenced this pull request Nov 7, 2016
…xt() over getSource() (xabbuh)

This PR was merged into the 2.7 branch.

Discussion
----------

[TwigBridge][TwigBundle][HttpKernel] prefer getSourceContext() over getSource()

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20435
| License       | MIT
| Doc PR        | n/a

Commits
-------

adbc529 prefer getSourceContext() over getSource()
fabpot added a commit to twigphp/Twig that referenced this pull request Nov 7, 2016
This PR was merged into the 1.x branch.

Discussion
----------

add machine-readable version constants

This will make it easier to implement version depending features (see symfony/symfony#20440 (comment) for an example).

Commits
-------

bf07db4 add machine-readable version constants
@xabbuh xabbuh deleted the issue-20435 branch November 7, 2016 19:39
@FrancescoBorzi
Copy link
Contributor

good job @xabbuh

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
0