16
16
class App
17
17
{
18
18
/** Inphinit framework version */
19
- const VERSION = '0.5.7 ' ;
19
+ const VERSION = '0.5.8 ' ;
20
20
21
21
private static $ events = array ();
22
22
private static $ configs = array ();
@@ -142,11 +142,14 @@ public static function stop($code, $msg = null)
142
142
self ::trigger ('changestatus ' , array ($ code , $ msg ));
143
143
}
144
144
145
+ self ::trigger ('finish ' );
146
+
145
147
if (self ::$ state < 4 ) {
146
- self ::trigger ('finish ' );
147
148
self ::$ state = 4 ;
148
149
}
149
150
151
+ self ::dispatch ();
152
+
150
153
exit ;
151
154
}
152
155
@@ -161,10 +164,10 @@ public static function exec()
161
164
return null ;
162
165
}
163
166
164
- self ::$ state = 1 ;
165
-
166
167
self ::trigger ('init ' );
167
168
169
+ self ::$ state = 1 ;
170
+
168
171
if (self ::env ('maintenance ' )) {
169
172
$ resp = 503 ;
170
173
} else {
@@ -177,15 +180,14 @@ public static function exec()
177
180
}
178
181
179
182
if (is_integer ($ resp )) {
180
- if (ob_get_level () === 0 ) {
181
- ob_start ();
182
- }
183
-
184
- \UtilsSandboxLoader ('error.php ' , array ( 'status ' => $ resp ));
183
+ self ::on ('finish ' , function () use ($ resp ) {
184
+ \UtilsSandboxLoader ('error.php ' , array ( 'status ' => $ resp ));
185
+ });
186
+
185
187
self ::stop ($ resp );
186
188
}
187
189
188
- $ callback = $ resp ['callback ' ];
190
+ $ callback = & $ resp ['callback ' ];
189
191
190
192
if (is_string ($ callback )) {
191
193
$ parsed = explode (': ' , $ callback , 2 );
@@ -196,13 +198,7 @@ public static function exec()
196
198
197
199
$ output = call_user_func_array ($ callback , $ resp ['args ' ]);
198
200
199
- if (class_exists ('\\Inphinit \\Http \\Response ' , false )) {
200
- Response::dispatch ();
201
- }
202
-
203
- if (class_exists ('\\Inphinit \\Viewing \\View ' , false )) {
204
- View::dispatch ();
205
- }
201
+ self ::dispatch ();
206
202
207
203
if (self ::$ state < 2 ) {
208
204
self ::$ state = 2 ;
@@ -217,10 +213,26 @@ public static function exec()
217
213
if (self ::$ state < 3 ) {
218
214
self ::$ state = 3 ;
219
215
}
216
+
217
+ self ::trigger ('finish ' );
220
218
221
219
if (self ::$ state < 4 ) {
222
- self ::trigger ('finish ' );
223
220
self ::$ state = 4 ;
224
221
}
225
222
}
223
+
224
+ /**
225
+ * Dispatch before ready event if exec is Ok,
226
+ * or dispatch after finish event if stop() is executed
227
+ */
228
+ private static function dispatch ()
229
+ {
230
+ if (class_exists ('\\Inphinit \\Http \\Response ' , false )) {
231
+ Response::dispatch ();
232
+ }
233
+
234
+ if (class_exists ('\\Inphinit \\Viewing \\View ' , false )) {
235
+ View::dispatch ();
236
+ }
237
+ }
226
238
}
0 commit comments