Skip to content

Commit

Permalink
tiny fix
Browse files Browse the repository at this point in the history
  • Loading branch information
energy-coresky committed Jan 16, 2024
1 parent 1195532 commit a782f15
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 72 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013-2023 Energy (nickname)
Copyright (c) 2013-now Energy (nickname)
Home: https://coresky.net/

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
6 changes: 2 additions & 4 deletions sky.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,11 @@ function shutdown($web = false) {
$tracing .= "<h1>Stdout</h1><pre>$stdout</pre>";
}
$this->_static = false; # skip app css and js files
$fn = MVC::jet('__std.crash', '', $vars);
$vars->data['_vars'] += [
MVC::jet('__std.crash', '', [
'redirect' => $redirect,
'no' => $http_code,
'tracing' => $toggle ? $tracing : '',
];
Plan::jet_r($fn, $vars);
]);
}
});
SQL::close();
Expand Down
4 changes: 0 additions & 4 deletions w2/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,6 @@ class_exists('SKY', false) or require DIR_S . '/sky.php';
echo SKY::CORE . ' path:' . realpath(DIR_S);
}

static function tail_x($exit, $stdout = '') {
//
}

static function test($m1 = 5, $m2 = 100) {
echo rand(0, $m2);
sleep(rand(1, $m1));
Expand Down
49 changes: 30 additions & 19 deletions w2/dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,38 @@ static function e($top) {
trace(["Gate error in $top->hnd", 'Gate error'], true, 2);
}

static function gate(&$ctrl, $key, $func) {
static function jet($fn) {
if (!$php = Plan::jet_gq($fn))
return trace("$fn, recompiled", 'JET');
$fmt = Plan::jet_m($fn);
$line = substr($php, $n = strpos($php, "\n"), strpos($php, "\n", 2 + $n) - $n);
$files = explode(' ', trim($line, " \r\n#"));
foreach ($files as $one) {
if (Plan::view_('m', "$one.jet") > $fmt) {
Plan::jet_d($fn);
return trace("$fn, recompiled", 'JET');
}
}
trace("$fn, used cached", 'JET');
}

static function gate(&$ctrl, $in, $func) {
$ware = ($set = $func($x)) ?: 'main';
$class = $set && '*' !== $key && !$x ? "c_$key" : 'default_c';
$class = $set && '*' !== $in && !$x ? "c_$in" : 'default_c';
$msrc = Plan::app_mq([$ware, "mvc/$class.php"]);
if ('main' == $ware) {
//common_c::$tune = false;
if (!$set && ($mt = Plan::app_mq("mvc/c_$key.php"))) {
$msrc = $mt;
$ctrl[$key] = 'main'; # added new Controller
$class = "c_$key";
Plan::cache_d('sky_plan.php');
} elseif (!$msrc) {
if ('default_c' == $class)
throw new Error('Controller `main::default_c` is mandatory');
unset($ctrl[$key]); # Controller deleted
$msrc = Plan::app_m('mvc/' . ($class = 'default_c') . '.php');
Plan::cache_d('sky_plan.php');
}
} else {
if ('main' != $ware) {
trace($ware, 'WARE');
} elseif (!$set && ($mt = Plan::app_mq("mvc/c_$in.php"))) {
$msrc = $mt;
$ctrl[$in] = 'main'; # added new Controller
$class = "c_$in";
Plan::cache_d('sky_plan.php');
} elseif (!$msrc) {
if ('default_c' == $class)
throw new Error('Controller `main::default_c` is mandatory');
unset($ctrl[$in]); # Controller deleted
$msrc = Plan::app_m('mvc/' . ($class = 'default_c') . '.php');
Plan::cache_d('sky_plan.php');
}
$mdst = Plan::gate_mq("$ware-$class.php");
if ($drop = $mdst && $msrc > $mdst)
Expand Down Expand Up @@ -231,7 +243,7 @@ function j_attach() {
$name = basename($dir);
if ($class = is_file($fn = "$dir/w3/ware.php") ? "$name\\ware" : false)
require $fn;
$wares = (array)Plan::_rq('wares.php');
$wares = Plan::_rq('wares.php');
if ('un' == ($mode = $_POST['mode'])) { # UnInstall
if ($class)
return $this->j_ware($class, 'uninstall');
Expand Down Expand Up @@ -520,7 +532,6 @@ function c_main($n) {
'static' => ['', '', 'size="50"'],
'etc' => ['Turn ON tracing for default_c::a_etc()', 'chk'],
'red_label' => ['Red label', 'radio', ['Off', 'On']],
'jet_cache' => ['Jet cache', 'radio', ['Off', 'On']],
['Save', 'submit'],
]),
];
Expand Down
75 changes: 32 additions & 43 deletions w2/mvc.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ function view($in, $return = false, &$param = null) {
trace("$mvc->no $mvc->hnd $layout^$mvc->body", $mvc->no ? 'SUB-VIEW' : 'TOP-VIEW', 1);

if ($layout || $mvc->body)
$mvc->ob = Plan::jet_r(MVC::jet($mvc, $layout, $vars), $vars);
$mvc->ob = MVC::jet($mvc, $layout);
if ($mvc->no)
return $mvc->return ? $mvc->ob : null;
global $sky;
if ($sky->fly || !$layout)
method_exists($sky, 'tail_x') ? $sky->tail_x(0, $mvc->ob) : Console::tail_x(0, $mvc->ob);
if ($sky instanceof HEAVEN && ($sky->fly || !$layout))
$sky->tail_x(0, $mvc->ob);
}

//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -371,37 +371,6 @@ static function vars(&$all, &$new, $pref = false) {
});
}

static function jet($mvc, $layout, &$vars) {
global $sky;
$vars = new stdClass;
$vars->data['_vars'] = SKY::$vars;
$_vars =& $vars->data['_vars'];
if (is_string($mvc)) { # for __std.crash
$name = $mvc;
$_vars['sky'] = $sky;
} else {
$name = "_$mvc->body";
$mvc->no or MVC::vars($_vars, MVC::$_y, 'y_');
MVC::vars($_vars, $mvc->_v);
$_vars['sky'] = $mvc;
}
$fn = MVC::fn_parsed($layout, $name);
$ok = Plan::jet_t($fn) && (!DEV || $sky->d_jet_cache);
if ($ok && DEV) {
$mtime = Plan::jet_m($fn);
$jet = Plan::jet_g($fn);
$line = substr($jet, $n = strpos($jet, "\n"), strpos($jet, "\n", 2 + $n) - $n);
$files = explode(' ', trim($line, " \r\n#"));
foreach ($files as $one) {
if (!$ok = Plan::view_('m', "$one.jet") < $mtime)
break; # recompilation required
}
}
$ok or new Jet($name, $layout, $fn, is_string($mvc) ? false : $mvc->return);
trace("JET: $fn, " . ($ok ? 'used cached' : 'recompiled'));
return $fn;
}

static function last_modified($time, $use_site_ts = true, $func = null) {
global $sky;

Expand Down Expand Up @@ -514,21 +483,41 @@ function set($in, $is_common = false) {
}
}

static function jet($mvc, $layout, $vars = []) {
$vars += SKY::$vars;
if (is_string($mvc)) { # for __std.crash
$fn = MVC::fn_parsed('', $name = $mvc);
$vars['sky'] = $GLOBALS['sky'];
} else {
$fn = MVC::fn_parsed($layout, $name = "_$mvc->body");
$mvc->no or MVC::vars($vars, MVC::$_y, 'y_');
MVC::vars($vars, $mvc->_v);
$vars['sky'] = $mvc;
}
DEV && DEV::jet($fn);
$vars = (object)['data' => ['_vars' => $vars]];
if (false !== ($str = Plan::jet_rq($fn, $vars, false)))
return $str;
new Jet($name, $layout, $fn, is_string($mvc) ? false : $mvc->return);
return Plan::jet_r($fn, $vars);
}

private function gate(&$class, &$action, &$gate) {
$ctrl =& SKY::$plans['main']['ctrl'];
is_string($key = $this->_0) or $key = '*';
$func = function (&$x) use (&$ctrl, $key) {
is_string($in = $this->_0) or $in = '*';
$func = function (&$x) use (&$ctrl, $in) {
$x = false;
if (!$y = common_c::$tune)
return $ctrl[$key] ?? false;
return $ctrl["$y/$key"] ?? $ctrl[$x = "$y/*"] ?? false;
return $ctrl[$in] ?? false;
return $ctrl["$y/$in"] ?? $ctrl[$x = "$y/*"] ?? false;
};
$vars = DEV ? (object)DEV::gate($ctrl, $key, $func) : false;

$vars = DEV ? (object)DEV::gate($ctrl, $in, $func) : false;
if ($set = $func($x)) {
Plan::$ware = Plan::$view = $set;
if ($set = '*' !== $key && !$x) {
$class = 'c_' . (MVC::$tpl = $key);
is_string($key = $this->_1) or $key = '*';
if ($set = '*' !== $in && !$x) {
$class = 'c_' . (MVC::$tpl = $in);
is_string($in = $this->_1) or $in = '*';
}
}
if (!$set)
Expand All @@ -538,7 +527,7 @@ private function gate(&$class, &$action, &$gate) {
Plan::gate_r($fn, $vars);
}
$x = $this->return ? 'j' : 'a';
$action = '' === $key ? "empty_$x" : $x . '_' . $key;
$action = '' === $in ? "empty_$x" : $x . '_' . $in;
$cls_g = $class . '_G';
method_exists($gate = new $cls_g, $action) or $action = "default_$x";
}
Expand Down
2 changes: 1 addition & 1 deletion w2/wares.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function __toString() {
}

function off_ware() {
$wares = (array)Plan::_rq($plan = ['main', 'wares.php']);
$wares = Plan::_rq($plan = ['main', 'wares.php']);
unset($wares[$this->k_ware]);
Plan::app_p($plan, Boot::auto($wares));
Plan::cache_d(['main', 'sky_plan.php']);
Expand Down

0 comments on commit a782f15

Please sign in to comment.