Skip to content

Commit

Permalink
bug #20325 [VarDumper] Fix source links to Twig files (nicolas-grekas)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.2-dev branch.

Discussion
----------

[VarDumper] Fix source links to Twig files

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

Commits
-------

06203b1 [VarDumper] Fix source links to Twig files
  • Loading branch information
fabpot committed Oct 27, 2016
2 parents b0e94f1 + 06203b1 commit 1d96df0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
10 changes: 4 additions & 6 deletions src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php
Expand Up @@ -157,17 +157,15 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, $is
$template = isset($f['object']) ? $f['object'] : new $f['class'](new \Twig_Environment(new \Twig_Loader_Filesystem()));

$ellipsis = 0;
$templateName = $template->getTemplateName();
$templateSrc = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : '');
$templateInfo = $template->getDebugInfo();
if (isset($templateInfo[$f['line']])) {
if (method_exists($template, 'getSourceContext')) {
$templateName = $template->getSourceContext()->getPath() ?: $templateName;
}
$templatePath = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getPath() : null;

if ($templateSrc) {
$templateSrc = explode("\n", $templateSrc);
$src = self::extractSource($templateSrc, $templateInfo[$f['line']], self::$srcContext, $caller, 'twig');
$srcKey = $templateName.':'.$templateInfo[$f['line']];
$src = self::extractSource($templateSrc, $templateInfo[$f['line']], self::$srcContext, $caller, 'twig', $templatePath);
$srcKey = ($templatePath ?: $template->getTemplateName()).':'.$templateInfo[$f['line']];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php
Expand Up @@ -312,7 +312,7 @@ private function callCaster($callback, $obj, $a, $stub, $isNested)
$a = $cast;
}
} catch (\Exception $e) {
$a[(Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').'⚠'] = new ThrowingCasterException($e);
$a = array((Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').'⚠' => new ThrowingCasterException($e)) + $a;
}

return $a;
Expand Down
14 changes: 7 additions & 7 deletions src/Symfony/Component/VarDumper/Tests/CliDumperTest.php
Expand Up @@ -268,13 +268,6 @@ public function testThrowingCaster()
$this->assertStringMatchesFormat(
<<<EOTXT
stream resource {@{$ref}
%Awrapper_type: "PHP"
stream_type: "MEMORY"
mode: "%s+b"
unread_bytes: 0
seekable: true
uri: "php://memory"
%Aoptions: []
⚠: Symfony\Component\VarDumper\Exception\ThrowingCasterException {{$r}
#message: "Unexpected Exception thrown from a caster: Foobar"
-trace: {
Expand Down Expand Up @@ -305,6 +298,13 @@ public function testThrowingCaster()
}
}
}
%Awrapper_type: "PHP"
stream_type: "MEMORY"
mode: "%s+b"
unread_bytes: 0
seekable: true
uri: "php://memory"
%Aoptions: []
}
EOTXT
Expand Down

0 comments on commit 1d96df0

Please sign in to comment.