Skip to content

[VarDumper] Fix source links with latests Twig versions #20175

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

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 2.8
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

Sibling to #20173

@fabpot
Copy link
Member

fabpot commented Oct 17, 2016

Closing in favor of #20224

@fabpot fabpot closed this Oct 17, 2016
@nicolas-grekas nicolas-grekas force-pushed the dump-twig branch 3 times, most recently from cdaa6dc to 6401a33 Compare October 18, 2016 09:58
$templateInfo = $template->getDebugInfo();
if (isset($templateInfo[$f['line']])) {
if (method_exists($template, 'getSourceContext')) {
$templateName = $template->getSourceContext()->getPath();
Copy link
Member

Choose a reason for hiding this comment

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

you should overwrite it only when the path is not null (not all loaders can give you a path, as not all of them are based on a file)

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

$templateInfo = $template->getDebugInfo();
if (isset($templateInfo[$f['line']])) {
$templateName = $template->getTemplateName();
$templateSrc = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : false);
Copy link
Member

Choose a reason for hiding this comment

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

I would use the empty string rather than false, to have a consistent variable type (getCode() will return the empty string in non-debug mode anyway)

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

twig source

";
return new Twig_Source(" foo bar\n twig source\n\n", 'foo.twig', 'foo.twig');
Copy link
Member

Choose a reason for hiding this comment

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

Please also add tests for other cases:

  • Twig_Source with an empty code string (i.e. a non-debug compilation)
  • Twig_Source without a path (i.e. a loader not based on the filesystem, or a loader not updated to use new features)

Copy link
Member Author

Choose a reason for hiding this comment

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

Bof, that's only a caster, adding a test for that would be quite a bit of work for a minor thing to me...

Copy link
Member

Choose a reason for hiding this comment

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

well, it would avoid issues when refactoring it, reintroducing the bugs I spotted during the review

Copy link
Member Author

Choose a reason for hiding this comment

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

tests added

@nicolas-grekas nicolas-grekas force-pushed the dump-twig branch 2 times, most recently from d71fcd9 to 888e4bd Compare October 18, 2016 14:18
@nicolas-grekas nicolas-grekas merged commit f3b09d9 into symfony:2.8 Oct 18, 2016
nicolas-grekas added a commit that referenced this pull request Oct 18, 2016
…icolas-grekas)

This PR was merged into the 2.8 branch.

Discussion
----------

[VarDumper] Fix source links with latests Twig versions

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Sibling to #20173

Commits
-------

f3b09d9 [VarDumper] Fix source links with latests Twig versions
@nicolas-grekas nicolas-grekas deleted the dump-twig branch October 18, 2016 16:01
This was referenced Oct 27, 2016
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