@@ -88,6 +88,7 @@ public static function castTraceStub(TraceStub $trace, array $a, Stub $stub, $is
88
88
$ stub ->class = '' ;
89
89
$ stub ->handle = 0 ;
90
90
$ frames = $ trace ->value ;
91
+ $ prefix = Caster::PREFIX_VIRTUAL ;
91
92
92
93
$ a = array ();
93
94
$ j = count ($ frames );
@@ -98,33 +99,35 @@ public static function castTraceStub(TraceStub $trace, array $a, Stub $stub, $is
98
99
return array ();
99
100
}
100
101
$ lastCall = isset ($ frames [$ i ]['function ' ]) ? ' ==> ' .(isset ($ frames [$ i ]['class ' ]) ? $ frames [0 ]['class ' ].$ frames [$ i ]['type ' ] : '' ).$ frames [$ i ]['function ' ].'() ' : '' ;
102
+ $ frames [] = array ('function ' => '' );
101
103
102
104
for ($ j += $ trace ->numberingOffset - $ i ++; isset ($ frames [$ i ]); ++$ i , --$ j ) {
103
- $ call = isset ($ frames [$ i ]['function ' ]) ? (isset ($ frames [$ i ]['class ' ]) ? $ frames [$ i ]['class ' ].$ frames [$ i ]['type ' ] : '' ).$ frames [$ i ]['function ' ].'() ' : '??? ' ;
105
+ $ f = $ frames [$ i ];
106
+ $ call = isset ($ f ['function ' ]) ? (isset ($ f ['class ' ]) ? $ f ['class ' ].$ f ['type ' ] : '' ).$ f ['function ' ].'() ' : '??? ' ;
104
107
105
- $ a [Caster::PREFIX_VIRTUAL .$ j .'. ' .$ call .$ lastCall ] = new FrameStub (
108
+ $ label = $ call .$ lastCall ;
109
+ $ frame = new FrameStub (
106
110
array (
107
- 'object ' => isset ($ frames [ $ i ][ 'object ' ]) ? $ frames [ $ i ] ['object ' ] : null ,
108
- 'class ' => isset ($ frames [ $ i ][ 'class ' ]) ? $ frames [ $ i ] ['class ' ] : null ,
109
- 'type ' => isset ($ frames [ $ i ][ 'type ' ]) ? $ frames [ $ i ] ['type ' ] : null ,
110
- 'function ' => isset ($ frames [ $ i ][ 'function ' ]) ? $ frames [ $ i ] ['function ' ] : null ,
111
+ 'object ' => isset ($ f [ 'object ' ]) ? $ f ['object ' ] : null ,
112
+ 'class ' => isset ($ f [ 'class ' ]) ? $ f ['class ' ] : null ,
113
+ 'type ' => isset ($ f [ 'type ' ]) ? $ f ['type ' ] : null ,
114
+ 'function ' => isset ($ f [ 'function ' ]) ? $ f ['function ' ] : null ,
111
115
) + $ frames [$ i - 1 ],
112
116
$ trace ->keepArgs ,
113
117
true
114
118
);
119
+ $ f = self ::castFrameStub ($ frame , array (), $ frame , true );
120
+ if (isset ($ f [$ prefix .'src ' ])) {
121
+ foreach ($ f [$ prefix .'src ' ]->value as $ label => $ frame ) {
122
+ }
123
+ if (isset ($ f [$ prefix .'args ' ]) && $ frame instanceof EnumStub) {
124
+ $ frame ->value ['args ' ] = $ f [$ prefix .'args ' ];
125
+ }
126
+ }
127
+ $ a [$ prefix .$ j .'. ' .$ label ] = $ frame ;
115
128
116
129
$ lastCall = ' ==> ' .$ call ;
117
130
}
118
- $ a [Caster::PREFIX_VIRTUAL .$ j .'. {main} ' .$ lastCall ] = new FrameStub (
119
- array (
120
- 'object ' => null ,
121
- 'class ' => null ,
122
- 'type ' => null ,
123
- 'function ' => '{main} ' ,
124
- ) + $ frames [$ i - 1 ],
125
- $ trace ->keepArgs ,
126
- true
127
- );
128
131
if (null !== $ trace ->sliceLength ) {
129
132
$ a = array_slice ($ a , 0 , $ trace ->sliceLength , true );
130
133
}
@@ -145,9 +148,13 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, $is
145
148
$ f ['file ' ] = substr ($ f ['file ' ], 0 , -strlen ($ match [0 ]));
146
149
$ f ['line ' ] = (int ) $ match [1 ];
147
150
}
151
+ $ relFile = $ f ['file ' ];
152
+ $ home = getenv ('HOME ' );
153
+ if (false !== $ home && 0 === strpos ($ relFile , $ home .DIRECTORY_SEPARATOR )) {
154
+ $ relFile = '~ ' .substr ($ relFile , strlen ($ home ));
155
+ }
156
+ $ src = array ();
148
157
if (file_exists ($ f ['file ' ]) && 0 <= self ::$ srcContext ) {
149
- $ src [$ f ['file ' ].': ' .$ f ['line ' ]] = self ::extractSource (explode ("\n" , file_get_contents ($ f ['file ' ])), $ f ['line ' ], self ::$ srcContext );
150
-
151
158
if (!empty ($ f ['class ' ]) && is_subclass_of ($ f ['class ' ], 'Twig_Template ' ) && method_exists ($ f ['class ' ], 'getDebugInfo ' )) {
152
159
$ template = isset ($ f ['object ' ]) ? $ f ['object ' ] : new $ f ['class ' ](new \Twig_Environment (new \Twig_Loader_Filesystem ()));
153
160
@@ -156,13 +163,16 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, $is
156
163
$ templateSrc = explode ("\n" , method_exists ($ template , 'getSource ' ) ? $ template ->getSource () : $ template ->getEnvironment ()->getLoader ()->getSource ($ templateName ));
157
164
$ templateInfo = $ template ->getDebugInfo ();
158
165
if (isset ($ templateInfo [$ f ['line ' ]])) {
159
- $ src [$ templateName. ' : ' . $ templateInfo [ $ f [ ' line ' ]] ] = self ::extractSource ($ templateSrc , $ templateInfo [$ f ['line ' ]], self ::$ srcContext );
166
+ $ src [$ templateName ] = self ::extractSource ($ templateSrc , $ templateInfo [$ f ['line ' ]], self ::$ srcContext );
160
167
}
161
168
} catch (\Twig_Error_Loader $ e ) {
162
169
}
163
170
}
171
+ if (!$ src ) {
172
+ $ src [$ relFile ] = self ::extractSource (explode ("\n" , file_get_contents ($ f ['file ' ])), $ f ['line ' ], self ::$ srcContext );
173
+ }
164
174
} else {
165
- $ src [$ f [ ' file ' ] ] = $ f ['line ' ];
175
+ $ src [$ relFile ] = $ f ['line ' ];
166
176
}
167
177
$ a [$ prefix .'src ' ] = new EnumStub ($ src );
168
178
}
@@ -177,7 +187,7 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, $is
177
187
}
178
188
}
179
189
if ($ frame ->keepArgs && isset ($ f ['args ' ])) {
180
- $ a [$ prefix .'args ' ] = $ f ['args ' ];
190
+ $ a [$ prefix .'args ' ] = new EnumStub ( $ f ['args ' ], false ) ;
181
191
}
182
192
183
193
return $ a ;
@@ -232,12 +242,23 @@ private static function extractSource(array $srcArray, $line, $srcContext)
232
242
++$ ltrim ;
233
243
} while (0 > $ i && null !== $ pad );
234
244
235
- if (--$ ltrim ) {
236
- foreach ($ src as $ i => $ line ) {
237
- $ src [$ i ] = isset ($ line [$ ltrim ]) && "\r" !== $ line [$ ltrim ] ? substr ($ line , $ ltrim ) : ltrim ($ line , " \t" );
245
+ --$ ltrim ;
246
+
247
+ $ pad = strlen ($ line + $ srcContext );
248
+ $ srcArray = array ();
249
+
250
+ foreach ($ src as $ i => $ c ) {
251
+ if ($ ltrim ) {
252
+ $ c = isset ($ c [$ ltrim ]) && "\r" !== $ c [$ ltrim ] ? substr ($ c , $ ltrim ) : ltrim ($ c , " \t" );
253
+ }
254
+ $ c = substr ($ c , 0 , -1 );
255
+ $ c = new ConstStub ($ c , $ c );
256
+ if ($ i !== $ srcContext ) {
257
+ $ c ->class = 'default ' ;
238
258
}
259
+ $ srcArray [sprintf ("% {$ pad }d " , $ i + $ line - $ srcContext )] = $ c ;
239
260
}
240
261
241
- return implode ( '' , $ src );
262
+ return new EnumStub ( $ srcArray );
242
263
}
243
264
}
0 commit comments