Skip to content

Commit

Permalink
Version 0.5.8 👾
Browse files Browse the repository at this point in the history
Improved `system/error.php` for use `Inphinit\Response` and `Inphinit\Viewing\View` class
  • Loading branch information
brcontainer committed Jan 6, 2020
1 parent b6e1d07 commit 66c07b1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
48 changes: 30 additions & 18 deletions src/Inphinit/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class App
{
/** Inphinit framework version */
const VERSION = '0.5.7';
const VERSION = '0.5.8';

private static $events = array();
private static $configs = array();
Expand Down Expand Up @@ -142,11 +142,14 @@ public static function stop($code, $msg = null)
self::trigger('changestatus', array($code, $msg));
}

self::trigger('finish');

if (self::$state < 4) {
self::trigger('finish');
self::$state = 4;
}

self::dispatch();

exit;
}

Expand All @@ -161,10 +164,10 @@ public static function exec()
return null;
}

self::$state = 1;

self::trigger('init');

self::$state = 1;

if (self::env('maintenance')) {
$resp = 503;
} else {
Expand All @@ -177,15 +180,14 @@ public static function exec()
}

if (is_integer($resp)) {
if (ob_get_level() === 0) {
ob_start();
}

\UtilsSandboxLoader('error.php', array( 'status' => $resp ));
self::on('finish', function () use ($resp) {
\UtilsSandboxLoader('error.php', array( 'status' => $resp ));
});

self::stop($resp);
}

$callback = $resp['callback'];
$callback = &$resp['callback'];

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

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

if (class_exists('\\Inphinit\\Http\\Response', false)) {
Response::dispatch();
}

if (class_exists('\\Inphinit\\Viewing\\View', false)) {
View::dispatch();
}
self::dispatch();

if (self::$state < 2) {
self::$state = 2;
Expand All @@ -217,10 +213,26 @@ public static function exec()
if (self::$state < 3) {
self::$state = 3;
}

self::trigger('finish');

if (self::$state < 4) {
self::trigger('finish');
self::$state = 4;
}
}

/**
* Dispatch before ready event if exec is Ok,
* or dispatch after finish event if stop() is executed
*/
private static function dispatch()
{
if (class_exists('\\Inphinit\\Http\\Response', false)) {
Response::dispatch();
}

if (class_exists('\\Inphinit\\Viewing\\View', false)) {
View::dispatch();
}
}
}
2 changes: 1 addition & 1 deletion src/Inphinit/Http/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ final class Status
*
* @param int $code
* @param string $alternative
* @return void
* @return mixed
*/
public static function message($code, $alternative = null)
{
Expand Down

0 comments on commit 66c07b1

Please sign in to comment.