Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit888e4bd

Browse files
[VarDumper] Fix source links with latests Twig versions
1 parentee8203a commit888e4bd

File tree

4 files changed

+115
-32
lines changed

4 files changed

+115
-32
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,'getSourceContext') ?$template->getSourceContext()->getCode() : (method_exists($template,'getSource') ?$template->getSource() :'');
155+
$templateInfo =$template->getDebugInfo();
156+
if (isset($templateInfo[$f['line']])) {
157+
if (method_exists($template,'getSourceContext')) {
158+
$templateName =$template->getSourceContext()->getPath() ?:$templateName;
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 {
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\VarDumper\Tests\Caster;
13+
14+
useSymfony\Component\VarDumper\Caster\FrameStub;
15+
useSymfony\Component\VarDumper\Test\VarDumperTestTrait;
16+
17+
class ExceptionCasterTestextends \PHPUnit_Framework_TestCase
18+
{
19+
use VarDumperTestTrait;
20+
21+
/**
22+
* @requires function Twig_Template::getSourceContext
23+
*/
24+
publicfunctiontestFrameWithTwig()
25+
{
26+
require_oncedirname(__DIR__).'/Fixtures/Twig.php';
27+
28+
$f =array(
29+
newFrameStub(array(
30+
'file' =>dirname(__DIR__).'/Fixtures/Twig.php',
31+
'line' =>19,
32+
'class' =>'__TwigTemplate_VarDumperFixture_u75a09',
33+
'object' =>new \__TwigTemplate_VarDumperFixture_u75a09(new \Twig_Environment(new \Twig_Loader_Filesystem())),
34+
)),
35+
newFrameStub(array(
36+
'file' =>dirname(__DIR__).'/Fixtures/Twig.php',
37+
'line' =>19,
38+
'class' =>'__TwigTemplate_VarDumperFixture_u75a09',
39+
'object' =>new \__TwigTemplate_VarDumperFixture_u75a09(new \Twig_Environment(new \Twig_Loader_Filesystem()),null),
40+
)),
41+
);
42+
43+
$expectedDump = <<<'EODUMP'
44+
array:2 [
45+
0 => {
46+
class: "__TwigTemplate_VarDumperFixture_u75a09"
47+
object: __TwigTemplate_VarDumperFixture_u75a09 {
48+
%A
49+
}
50+
src: {
51+
%sTwig.php:19: """
52+
// line 2\n
53+
throw new \Exception('Foobar');\n
54+
}\n
55+
"""
56+
bar.twig:2: """
57+
foo bar\n
58+
twig source\n
59+
\n
60+
"""
61+
}
62+
}
63+
1 => {
64+
class: "__TwigTemplate_VarDumperFixture_u75a09"
65+
object: __TwigTemplate_VarDumperFixture_u75a09 {
66+
%A
67+
}
68+
src: {
69+
%sTwig.php:19: """
70+
// line 2\n
71+
throw new \Exception('Foobar');\n
72+
}\n
73+
"""
74+
foo.twig:2: """
75+
foo bar\n
76+
twig source\n
77+
\n
78+
"""
79+
}
80+
}
81+
]
82+
83+
EODUMP;
84+
85+
$this->assertDumpMatchesFormat($expectedDump,$f);
86+
}
87+
}

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

Lines 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
publicfunctiontestThrowingCaster()
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+
bar.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‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
/* foo.twig */
44
class __TwigTemplate_VarDumperFixture_u75a09extends Twig_Template
55
{
6-
publicfunction__construct(Twig_Environment$env)
6+
private$filename;
7+
8+
publicfunction__construct(Twig_Environment$env,$filename ='bar.twig')
79
{
810
parent::__construct($env);
9-
1011
$this->parent =false;
11-
12-
$this->blocks =array(
13-
);
12+
$this->blocks =array();
13+
$this->filename =$filename;
1414
}
1515

1616
protectedfunctiondoDisplay(array$context,array$blocks =array())
@@ -26,14 +26,11 @@ public function getTemplateName()
2626

2727
publicfunctiongetDebugInfo()
2828
{
29-
returnarray(19 =>2);
29+
returnarray(19 =>2);
3030
}
3131

32-
publicfunctiongetSource()
32+
publicfunctiongetSourceContext()
3333
{
34-
return" foo bar
35-
twig source
36-
37-
";
34+
returnnewTwig_Source(" foo bar\n twig source\n\n",'foo.twig',$this->filename);
3835
}
3936
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp