Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cdaa6dc

Browse filesBrowse files
[VarDumper] Fix source links with latests Twig versions
1 parent ee8203a commit cdaa6dc
Copy full SHA for cdaa6dc

File tree

3 files changed

+23
-24
lines changed
Filter options

3 files changed

+23
-24
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php
+11-7Lines 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, 'getSourceContext') ? $template->getSourceContext()->getCode() : (method_exists($template, 'getSource') ? $template->getSource() : false);
155+
$templateInfo = $template->getDebugInfo();
156+
if (isset($templateInfo[$f['line']])) {
157+
if (method_exists($template, 'getSourceContext')) {
158+
$templateName = $template->getSourceContext()->getPath();
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Tests/CliDumperTest.php
+9-14Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ public function testClosedResource()
201201
);
202202
}
203203

204+
/**
205+
* @requires function Twig_Template::getSourceContext
206+
*/
204207
public function testThrowingCaster()
205208
{
206209
$out = fopen('php://memory', 'r+b');
@@ -235,19 +238,6 @@ public function testThrowingCaster()
235238
rewind($out);
236239
$out = stream_get_contents($out);
237240

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-
251241
$r = defined('HHVM_VERSION') ? '' : '#%d';
252242
$this->assertStringMatchesFormat(
253243
<<<EOTXT
@@ -269,7 +259,12 @@ public function testThrowingCaster()
269259
throw new \Exception('Foobar');\\n
270260
}\\n
271261
"""
272-
{$twig} }
262+
foo.twig:2: """
263+
foo bar\\n
264+
twig source\\n
265+
\\n
266+
"""
267+
}
273268
}
274269
%d. Twig_Template->displayWithErrorHandling() ==> __TwigTemplate_VarDumperFixture_u75a09->doDisplay(): {
275270
src: {

‎src/Symfony/Component/VarDumper/Tests/Fixtures/Twig.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarDumper/Tests/Fixtures/Twig.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public function getDebugInfo()
2929
return array (19 => 2);
3030
}
3131

32-
public function getSource()
32+
public function getSourceContext()
3333
{
34-
return " foo bar
34+
return new Twig_Source(" foo bar
3535
twig source
3636
37-
";
37+
", 'foo.twig', 'foo.twig');
3838
}
3939
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.