From 06203b160afa76a658e44af48011002a6f4e11db Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 27 Oct 2016 13:30:59 +0200 Subject: [PATCH] [VarDumper] Fix source links to Twig files --- .../Component/VarDumper/Caster/ExceptionCaster.php | 10 ++++------ .../Component/VarDumper/Cloner/AbstractCloner.php | 2 +- .../Component/VarDumper/Tests/CliDumperTest.php | 14 +++++++------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php b/src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php index bb5647a2acef..e2b85eec1b90 100644 --- a/src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php @@ -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']]; } } } diff --git a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php index 947b4167eeab..d49d2b545e1d 100644 --- a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php +++ b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php @@ -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; diff --git a/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php b/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php index aaaf781441c1..25a1bec0f01d 100644 --- a/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/CliDumperTest.php @@ -268,13 +268,6 @@ public function testThrowingCaster() $this->assertStringMatchesFormat( <<