@@ -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,36 @@ 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
+ if (array ($ prefix .'src ' ) === array_keys ($ f = self ::castFrameStub ($ frame , array (), $ frame , true ))) {
120
+ $ frame = $ f [$ prefix .'src ' ];
121
+ if (1 === count ($ frame ->value )) {
122
+ foreach ($ frame ->value as $ label => $ frame ) {
123
+ }
124
+ } else {
125
+ $ label = '' ;
126
+ }
127
+ }
128
+ $ a [$ prefix .$ j .'. ' .$ label ] = $ frame ;
115
129
116
130
$ lastCall = ' ==> ' .$ call ;
117
131
}
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
132
if (null !== $ trace ->sliceLength ) {
129
133
$ a = array_slice ($ a , 0 , $ trace ->sliceLength , true );
130
134
}
@@ -145,8 +149,13 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, $is
145
149
$ f ['file ' ] = substr ($ f ['file ' ], 0 , -strlen ($ match [0 ]));
146
150
$ f ['line ' ] = (int ) $ match [1 ];
147
151
}
152
+ $ relFile = $ f ['file ' ];
153
+ $ home = getenv ('HOME ' );
154
+ if (false !== $ home && 0 === strpos ($ relFile , $ home .DIRECTORY_SEPARATOR )) {
155
+ $ relFile = '~ ' .substr ($ relFile , strlen ($ home ));
156
+ }
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 );
158
+ $ src [$ relFile ] = self ::extractSource (explode ("\n" , file_get_contents ($ f ['file ' ])), $ f ['line ' ], self ::$ srcContext );
150
159
151
160
if (!empty ($ f ['class ' ]) && is_subclass_of ($ f ['class ' ], 'Twig_Template ' ) && method_exists ($ f ['class ' ], 'getDebugInfo ' )) {
152
161
$ template = isset ($ f ['object ' ]) ? $ f ['object ' ] : new $ f ['class ' ](new \Twig_Environment (new \Twig_Loader_Filesystem ()));
@@ -156,13 +165,13 @@ public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, $is
156
165
$ templateSrc = explode ("\n" , method_exists ($ template , 'getSource ' ) ? $ template ->getSource () : $ template ->getEnvironment ()->getLoader ()->getSource ($ templateName ));
157
166
$ templateInfo = $ template ->getDebugInfo ();
158
167
if (isset ($ templateInfo [$ f ['line ' ]])) {
159
- $ src [$ templateName. ' : ' . $ templateInfo [ $ f [ ' line ' ]] ] = self ::extractSource ($ templateSrc , $ templateInfo [$ f ['line ' ]], self ::$ srcContext );
168
+ $ src [$ templateName ] = self ::extractSource ($ templateSrc , $ templateInfo [$ f ['line ' ]], self ::$ srcContext );
160
169
}
161
170
} catch (\Twig_Error_Loader $ e ) {
162
171
}
163
172
}
164
173
} else {
165
- $ src [$ f [ ' file ' ] ] = $ f ['line ' ];
174
+ $ src [$ relFile ] = $ f ['line ' ];
166
175
}
167
176
$ a [$ prefix .'src ' ] = new EnumStub ($ src );
168
177
}
@@ -232,12 +241,23 @@ private static function extractSource(array $srcArray, $line, $srcContext)
232
241
++$ ltrim ;
233
242
} while (0 > $ i && null !== $ pad );
234
243
235
- if (--$ ltrim ) {
236
- foreach ($ src as $ i => $ line ) {
237
- $ src [$ i ] = isset ($ line [$ ltrim ]) && "\r" !== $ line [$ ltrim ] ? substr ($ line , $ ltrim ) : ltrim ($ line , " \t" );
244
+ --$ ltrim ;
245
+
246
+ $ pad = strlen ($ line + $ srcContext );
247
+ $ srcArray = array ();
248
+
249
+ foreach ($ src as $ i => $ c ) {
250
+ if ($ ltrim ) {
251
+ $ c = isset ($ c [$ ltrim ]) && "\r" !== $ c [$ ltrim ] ? substr ($ c , $ ltrim ) : ltrim ($ c , " \t" );
252
+ }
253
+ $ c = substr ($ c , 0 , -1 );
254
+ $ c = new ConstStub ($ c , $ c );
255
+ if ($ i !== $ srcContext ) {
256
+ $ c ->class = 'default ' ;
238
257
}
258
+ $ srcArray [sprintf ("% {$ pad }d " , $ i + $ line - $ srcContext )] = $ c ;
239
259
}
240
260
241
- return implode ( '' , $ src );
261
+ return new EnumStub ( $ srcArray );
242
262
}
243
263
}
0 commit comments