@@ -97,21 +97,42 @@ public function dump(Data $data)
97
97
98
98
break ;
99
99
} elseif (isset ($ trace [$ i ]['object ' ]) && $ trace [$ i ]['object ' ] instanceof \Twig_Template) {
100
- $ info = $ trace [$ i ]['object ' ];
101
- $ name = $ info ->getTemplateName ();
102
- $ src = method_exists ($ info , 'getSource ' ) ? $ info ->getSource () : $ info ->getEnvironment ()->getLoader ()->getSource ($ name );
103
- $ info = $ info ->getDebugInfo ();
104
- if (null !== $ src && isset ($ info [$ trace [$ i - 1 ]['line ' ]])) {
105
- $ file = false ;
100
+ $ template = $ trace [$ i ]['object ' ];
101
+ $ name = $ template ->getTemplateName ();
102
+ $ info = $ template ->getDebugInfo ();
103
+ try {
104
+ $ src = method_exists ($ template , 'getSource ' ) ? $ template ->getSource () : $ template ->getEnvironment ()->getLoader ()->getSource ($ name );
105
+ } catch (\Twig_Error_Loader $ e ) {
106
+ $ src = false ;
107
+ }
108
+ if (isset ($ info [$ trace [$ i - 1 ]['line ' ]])) {
106
109
$ line = $ info [$ trace [$ i - 1 ]['line ' ]];
107
- $ src = explode ("\n" , $ src );
108
- $ fileExcerpt = array ();
109
110
110
- for ($ i = max ($ line - 3 , 1 ), $ max = min ($ line + 3 , count ($ src )); $ i <= $ max ; ++$ i ) {
111
- $ fileExcerpt [] = '<li ' .($ i === $ line ? ' class="selected" ' : '' ).'><code> ' .$ this ->htmlEncode ($ src [$ i - 1 ]).'</code></li> ' ;
111
+ if (isset ($ info ['file ' ])) {
112
+ $ file = $ info ['file ' ];
113
+ } elseif (method_exists ($ template , 'getEnvironment ' ) && $ template ->getEnvironment ()->getLoader () instanceof \Twig_Loader_Filesystem) {
114
+ try {
115
+ $ file = $ template ->getEnvironment ()->getLoader ()->getCacheKey ($ name );
116
+ } catch (\Twig_Error_Loader $ e ) {
117
+ $ file = false ;
118
+ }
119
+ } else {
120
+ $ file = false ;
121
+ }
122
+ if ($ file && !file_exists ($ file )) {
123
+ $ file = false ;
112
124
}
113
125
114
- $ fileExcerpt = '<ol start=" ' .max ($ line - 3 , 1 ).'"> ' .implode ("\n" , $ fileExcerpt ).'</ol> ' ;
126
+ if ($ src ) {
127
+ $ src = explode ("\n" , $ src );
128
+ $ fileExcerpt = array ();
129
+
130
+ for ($ i = max ($ line - 3 , 1 ), $ max = min ($ line + 3 , count ($ src )); $ i <= $ max ; ++$ i ) {
131
+ $ fileExcerpt [] = '<li ' .($ i === $ line ? ' class="selected" ' : '' ).'><code> ' .$ this ->htmlEncode ($ src [$ i - 1 ]).'</code></li> ' ;
132
+ }
133
+
134
+ $ fileExcerpt = '<ol start=" ' .max ($ line - 3 , 1 ).'"> ' .implode ("\n" , $ fileExcerpt ).'</ol> ' ;
135
+ }
115
136
}
116
137
break ;
117
138
}
0 commit comments