Skip to content

Commit 66c07b1

Browse files
committed
Version 0.5.8 👾
Improved `system/error.php` for use `Inphinit\Response` and `Inphinit\Viewing\View` class
1 parent b6e1d07 commit 66c07b1

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

src/Inphinit/App.php

+30-18
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class App
1717
{
1818
/** Inphinit framework version */
19-
const VERSION = '0.5.7';
19+
const VERSION = '0.5.8';
2020

2121
private static $events = array();
2222
private static $configs = array();
@@ -142,11 +142,14 @@ public static function stop($code, $msg = null)
142142
self::trigger('changestatus', array($code, $msg));
143143
}
144144

145+
self::trigger('finish');
146+
145147
if (self::$state < 4) {
146-
self::trigger('finish');
147148
self::$state = 4;
148149
}
149150

151+
self::dispatch();
152+
150153
exit;
151154
}
152155

@@ -161,10 +164,10 @@ public static function exec()
161164
return null;
162165
}
163166

164-
self::$state = 1;
165-
166167
self::trigger('init');
167168

169+
self::$state = 1;
170+
168171
if (self::env('maintenance')) {
169172
$resp = 503;
170173
} else {
@@ -177,15 +180,14 @@ public static function exec()
177180
}
178181

179182
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+
185187
self::stop($resp);
186188
}
187189

188-
$callback = $resp['callback'];
190+
$callback = &$resp['callback'];
189191

190192
if (is_string($callback)) {
191193
$parsed = explode(':', $callback, 2);
@@ -196,13 +198,7 @@ public static function exec()
196198

197199
$output = call_user_func_array($callback, $resp['args']);
198200

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();
206202

207203
if (self::$state < 2) {
208204
self::$state = 2;
@@ -217,10 +213,26 @@ public static function exec()
217213
if (self::$state < 3) {
218214
self::$state = 3;
219215
}
216+
217+
self::trigger('finish');
220218

221219
if (self::$state < 4) {
222-
self::trigger('finish');
223220
self::$state = 4;
224221
}
225222
}
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+
}
226238
}

src/Inphinit/Http/Status.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ final class Status
151151
*
152152
* @param int $code
153153
* @param string $alternative
154-
* @return void
154+
* @return mixed
155155
*/
156156
public static function message($code, $alternative = null)
157157
{

0 commit comments

Comments
 (0)