8000 [TwigBundle] Fixing regression in TwigEngine exception handling by attila901 · Pull Request #21179 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TwigBundle] Fixing regression in TwigEngine exception handling #21179

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
Jan 10, 2017
Merged

[TwigBundle] Fixing regression in TwigEngine exception handling #21179

merged 1 commit into from
Jan 10, 2017

Conversation

attila901
Copy link
@attila901 attila901 commented Jan 6, 2017
Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #21176
License MIT

Fixing regression after #20831 in TwigEngine exception handling.

} else {
$templateName = $e->getTemplateName();
}
$path = (string) $this->locator->locate($this->parser->parse($templateName));
Copy link
Member

Choose a reason for hiding this comment

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

the variable $name should be kept

Copy link
Author

Choose a reason for hiding this comment

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

But $name is a parameter that is already in use, and we even checking if $name instanceof TemplateReference. Should we overwrite this variable?

Copy link
Member
@nicolas-grekas nicolas-grekas Jan 6, 2017

Choose a reason for hiding this comment

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

if you want to rename it, you must rename also line 84 now

Copy link
Author

Choose a reason for hiding this comment

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

True, sorry I missed that part, fixed.

@nicolas-grekas nicolas-grekas changed the title Fixing regression in TwigEngine exception handling. [TwigBundle] Fixing regression in TwigEngine exception handling Jan 6, 2017
@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Jan 6, 2017
@nicolas-grekas
Copy link
Member

👍

$name = $e->getTemplateName();
$path = (string) $this->locator->locate($this->parser->parse($name));
if (method_exists($e, 'getSourceContext')) {
$templateName = $e->getSourceContext()->getName();
Copy link

Choose a reason for hiding this comment

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

@nicolas-grekas @attila901 maybe $path could be also get from the context with $e->getSourceContext()->getPath() in the else $path could be set the old way.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you @burci , I've fixed.

if (method_exists($e, 'setSourceContext')) {
$e->setSourceContext(new \Twig_Source('', $name, $path));
$e->setSourceContext(new \Twig_Source('', $templateName, $path));
Copy link
Member

Choose a reason for hiding this comment

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

why not using $e->getSourceContext() directly here, instead of creating a new one with the same info ? Existence of the getter and setter go together (they have been introduced together)

Copy link

Choose a reason for hiding this comment

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

After this @attila901 will end up something like this:

if (method_exists($e, 'setSourceContext')) {
    $e->setSourceContext($e->getSourceContext());
} else {
    $templateName = $e->getTemplateName();
    $path = (string) $this->locator->locate($this->parser->parse($templateName));
    $e->setTemplateName($path);
}

The $e->setSourceContext($e->getSourceContext()); part can be skiped and we are not using the $name variable at all. Maybe after introducing setSourceContext/getSourceContext it is always filled or we should get necessary info based on $name?

Copy link
Author

Choose a reason for hiding this comment

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

I've fixed.

if (method_exists($e, 'setSourceContext')) {
$e->setSourceContext(new \Twig_Source('', $name, $path));
$e->setSourceContext($e->getSourceContext());
Copy link
Member

Choose a reason for hiding this comment

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

even better: do nothing in this case, as it is a no-op now

@nicolas-grekas
Copy link
Member

Thank you @attila901.

@nicolas-grekas nicolas-grekas merged commit 390cb33 into symfony:2.7 Jan 10, 2017
nicolas-grekas added a commit that referenced this pull request Jan 10, 2017
…dling (Bertalan Attila)

This PR was merged into the 2.7 branch.

Discussion
----------

[TwigBundle] Fixing regression in TwigEngine exception handling

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21176
| License       | MIT

Fixing regression after #20831 in TwigEngine exception handling.

Commits
-------

390cb33 Fixing regression in TwigEngine exception handling.
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.

5 participants
0