8000 [VarDumper] Fix source links to Twig files · symfony/symfony@06203b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 06203b1

Browse files
[VarDumper] Fix source links to Twig files
1 parent bda7e6b commit 06203b1

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,15 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, $is
157157
$template = isset($f['object']) ? $f['object'] : new $f['class'](new \Twig_Environment(new \Twig_Loader_Filesystem()));
158158

159159
$ellipsis = 0;
160-
$templateName = $template->getTemplateName();
161160
$templateSrc = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : '');
162161
$templateInfo = $template->getDebugInfo();
163162
if (isset($templateInfo[$f['line']])) {
164-
if (method_exists($template, 'getSourceContext')) {
165-
$templateName = $template->getSourceContext()->getPath() ?: $templateName;
166-
}
163+
$templatePath = method_exists($template, 'getSourceContext') ? $template->getSourceContext()->getPath() : null;
164+
167165
if ($templateSrc) {
168166
$templateSrc = explode("\n", $templateSrc);
169-
$src = self::extractSource($templateSrc, $templateInfo[$f['line']], self::$srcContext, $caller, 'twig');
170-
$srcKey = $templateName.':'.$templateInfo[$f['line']];
167+
$src = self::extractSource($templateSrc, $templateInfo[$f['line']], self::$srcContext, $caller, 'twig', $templatePath);
168+
$srcKey = ($templatePath ?: $template->getTemplateName()).':'.$templateInfo[$f['line']];
171169
}
172170
}
173171
}

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ private function callCaster($callback, $obj, $a, $stub, $isNested)
312312
$a = $cast;
313313
}
314314
} catch (\Exception $e) {
315-
$a[(Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').''] = new ThrowingCasterException($e);
315+
$a = array((Stub::TYPE_OBJECT === $stub->type ? Caster::PREFIX_VIRTUAL : '').'' => new ThrowingCasterException($e)) + $a;
316316
}
317317

318318
return $a;

src/Symfony/Component/VarDumper/Tests/CliDumperTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,6 @@ public function testThrowingCaster()
268268
$this->assertStringMatchesFormat(
269269
<<<EOTXT
270270
stream resource {@{$ref}
271-
%Awrapper_type: "PHP"
272-
stream_type: "MEMORY"
273-
mode: "%s+b"
274-
unread_bytes: 0
275-
seekable: true
276-
uri: "php://memory"
277-
%Aoptions: []
278271
⚠: Symfony\Component\VarDumper\Exception\ThrowingCasterException {{$r}
279272
#message: "Unexpected Exception thrown from a caster: Foobar"
280273
-trace: {
@@ -305,6 +298,13 @@ public function testThrowingCaster()
305298
}
306299
}
307300
}
301+
%Awrapper_type: "PHP"
302+
stream_type: "MEMORY"
303+
mode: "%s+b"
304+
unread_bytes: 0
305+
seekable: true
306+
uri: "php://memory"
307+
%Aoptions: []
308308
}
309309
310310
EOTXT

0 commit comments

Comments
 (0)
0