Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 695c807

Browse files
[VarDumper] Fix source links with latests Twig versions
1 parent 781c923 commit 695c807

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,19 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, $is
150150

151151
if (!empty($f['class']) && is_subclass_of($f['class'], 'Twig_Template') && method_exists($f['class'], 'getDebugInfo')) {
152152
$template = isset($f['object']) ? $f['object'] : new $f['class'](new \Twig_Environment(new \Twig_Loader_Filesystem()));
153-
154-
try {
155-
$templateName = $template->getTemplateName();
156-
$templateSrc = explode("\n", method_exists($template, 'getSource') ? $template->getSource() : $template->getEnvironment()->getLoader()->getSource($templateName));
157-
$templateInfo = $template->getDebugInfo();
158-
if (isset($templateInfo[$f['line']])) {
153+
$templateName = $template->getTemplateName();
154+
$templateSrc = method_exists($template, 'getSource') ? $template->getSource() : false;
155+
$templateInfo = $template->getDebugInfo();
156+
if (isset($templateInfo[$f['line']])) {
157+
if (isset($templateInfo['file'])) {
158+
$templateName = $templateInfo['file'];
159+
}
160+
if ($templateSrc) {
161+
$templateSrc = explode("\n", $templateSrc);
159162
$src[$templateName.':'.$templateInfo[$f['line']]] = self::extractSource($templateSrc, $templateInfo[$f['line']], self::$srcContext);
163+
} else {
164+
$src[$templateName] = $templateInfo[$f['line']];
160165
}
161-
} catch (\Twig_Error_Loader $e) {
162166
}
163167
}
164168
} else {

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,19 +235,6 @@ public function testThrowingCaster()
235235
rewind($out);
236236
$out = stream_get_contents($out);
237237

238-
if (method_exists($twig, 'getSource')) {
239-
$twig = <<<EOTXT
240-
foo.twig:2: """
241-
foo bar\\n
242-
twig source\\n
243-
\\n
244-
"""
245-
246-
EOTXT;
247-
} else {
248-
$twig = '';
249-
}
250-
251238
$r = defined('HHVM_VERSION') ? '' : '#%d';
252239
$this->assertStringMatchesFormat(
253240
<<<EOTXT
@@ -269,7 +256,12 @@ public function testThrowingCaster()
269256
throw new \Exception('Foobar');\\n
270257
}\\n
271258
"""
272-
{$twig} }
259+
foo.twig:2: """
260+
foo bar\\n
261+
twig source\\n
262+
\\n
263+
"""
264+
}
273265
}
274266
%d. Twig_Template->displayWithErrorHandling() ==> __TwigTemplate_VarDumperFixture_u75a09->doDisplay(): {
275267
src: {

0 commit comments

Comments
 (0)