Skip to content

Commit

Permalink
Moon tuned
Browse files Browse the repository at this point in the history
  • Loading branch information
energy-coresky committed Jan 24, 2024
1 parent a8d0679 commit 3abf1d9
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 41 deletions.
26 changes: 19 additions & 7 deletions etc/moon.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function __construct() {
key($step) ? ($this->step = $step) : ($this->_fn = current($step));
for ($prev = $this->_func; $prev == $this->_func; ) {
$this->{"_$this->_func"}();
if ($this->err || $this->success)
if ($this->err || $this->success || 'etc' == $this->_func)
break;
}
exit;
Expand Down Expand Up @@ -175,7 +175,7 @@ function _test() {
}

function _dir() {
list($head, $pos, $data) = $this->head($this->_fn);
[$head, $pos, $data] = $this->head($this->_fn);
preg_match("/^A\^(\d+)\.(\d+)\.(\d+)\.\d+/", $head['ftrd'], $h);
if (!preg_match("/^DIRS: (\d+)\n([^\n]+)\n/", $data, $m) || !$h)
return $this->err = "File `$this->_fn` is corrupted";
Expand Down Expand Up @@ -298,7 +298,7 @@ function _sql() {
$q = $this->sql("select tmemo from {$pref}memory where id=3");
$lines = explode("\n", str_replace(["\r\n", "\r"], "\n", mysqli_fetch_row($q)[0]));
foreach ($lines as &$line) {
list($k, $v) = explode(' ', $line, 2);
[$k, $v] = explode(' ', $line, 2);
if ($flag = 'version' == $k) {
$line = "version $this->_ver";
break;
Expand Down Expand Up @@ -368,8 +368,8 @@ function move($exf) { # $mode=2-aold2p 3-anew2p (0 1)
$this->msg = "Moved from `$src` to production successfully";
}

function _etc() { // refresh n o move
$exf = explode('&', urldecode($_POST['exf']));
function _etc() { // _com= refresh|n|o|move
$exf = 'refresh' == $this->_com ? $this->preset() : explode('&', urldecode($_POST['exf']));
if (1 == strlen($this->_com))
$this->drop_dir($this->dir . ('o' == $this->_com ? '/aold' : '/anew'));
if ('move' == $this->_com)
Expand All @@ -383,6 +383,18 @@ function _etc() { // refresh n o move
}
}

function preset() {
[$head,, $data] = $this->head($this->_fn);
preg_match("/^DIRS: (\d+)\n([^\n]+)\n/", $data, $m);
$ln = strlen($x = $head['www']);
$ary = explode(' ', "$m[2] $head[filep]");
$www = basename(__DIR__);
$dirs = array_map(fn($v) => $x == substr($v, 0, $ln) ? "$www/" . substr($v, $ln) : $v, $ary);
$d1 = array_map(fn($v) => "$www/$v", self::list_path('.'));
$d2 = array_map(fn($v) => substr($v, 3), self::list_path('..'));
return array_diff(array_merge($d1, $d2), $dirs);
}

function walk_parent() {
$ary = self::list_path($this->dir);
in_array($dir = "$this->dir/anew", $ary) or $ary[] = $dir;
Expand Down Expand Up @@ -427,7 +439,7 @@ function head($fn) {
$pos = strpos($data, "\n\n");
$ary = false === $pos ? ['corr 1'] : explode("\n", substr($data, 0, $pos));
foreach ($ary as $line) {
list ($k, $v) = explode(' ', $line, 2);
[$k, $v] = explode(' ', $line, 2);
if ($k == 'mod_required')
$v = explode(' ', $v);
$head[$k] = $v;
Expand All @@ -450,7 +462,7 @@ function table($fn) {
'ftrd' => 'Added files, tables, rows dirs (FTRD)',
];
echo '<table width="100%" style="background:silver;margin-top:20px">';
list($head) = $this->head($fn);
[$head] = $this->head($fn);
$tpl = ' - <a style="font:bold 15px monospace" href="javascript:;" onclick="$$.select(%s)">Install</a>';
$tpl .= function_exists('shell_exec')
? ' or.. <a style="" href="javascript:;" onclick="$$.cli(%s)">Run in console</a>'
Expand Down
2 changes: 1 addition & 1 deletion sky.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SKY implements PARADISE
const ERR_DETECT = 1;
const ERR_SHOW = 3;
const ERR_SUPPRESSED = 4;
const CORE = '0.531 2024-01-18T20:29:41+02:00 energy';
const CORE = '0.532 2024-01-24T08:54:27+02:00 energy';

public $tracing = '';
public $error_prod = '';
Expand Down
9 changes: 3 additions & 6 deletions w2/__std.jet
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ DATABASES ({{count($databases)}})
{!$x[1]!}.php @if($x[2])({{$x[2]}})~if
</a>
~loop
#.m_gate.header ------------------------------------------------------------------------------
#.m_gate.header ------------------------------------------------------------------------------ 'v-body'
<h4><span style="color:#4338ca">CONTROLLER</span>:
@if($ctrl[$wc][0])
<span style="color:#000">{{strtoupper($ctrl[$wc][1])}}.PHP</span>
@else
<span style="color:red">{{strtoupper($ctrl[$wc][1])}}.PHP</span> (not exists)
<a style="font-weight:normal" @href(ajax('{{$wc}}',{},'v-body','_delete'))>Delete</a>
<a style="font-weight:normal" @href(ajax('{{$wc}}',{},() => {location.href = '_gate'},'_delete'))>Delete</a>
~if
<a class="@active($cshow)" style="font-weight:normal"
@href($(this).toggleClass('active'); dev('{!$wc!}',{s:$(this).hasClass('active')?1:0}))>Show code</a>
Expand All @@ -176,7 +176,7 @@ DATABASES ({{count($databases)}})
#use(.header)
@use(.m_gate)
<div id="gate">
@if($wc) <!-- delete ??? -->
@if($wc)
<div style="display:none" id="c23-tpl">@view(c23_edit)</div>
@loop($e_func)
<fieldset>
Expand Down Expand Up @@ -309,9 +309,6 @@ $(function() {
#if('_map' != :0)
if ('{{$act}}') {
$('#v-body div:eq(0)').prepend(`<h1 class="g-err">Gate error in "{{$ctrl[$wc][1]}}::{{$act}}()"</h1>`);
//'<div style="margin:0 10px;">'+
//window.parent.document.getElementById('trace-x').innerHTML// + '</div>'
// $('h1 span.gate-err').html('{{$ctrl[$wc][1]}}::{{$act}}');
sky.d.files();
setTimeout(function() {
var el = false;
Expand Down
7 changes: 4 additions & 3 deletions w2/boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static function lint(string $in, $is_file = true) : bool {
}

static function yml(string $in, $is_file = true) {
self::$dir = $is_file ? str_replace('\\', '/', dirname(realpath($in))) : '???';
self::$dir = $is_file ? str_replace('\\', '/', dirname($in)) : '???';
defined('DEV') && (self::$dev = DEV);
$yml = new Boot;
$yml->at = [$is_file ? $in : false, 0];
Expand Down Expand Up @@ -294,8 +294,9 @@ static function wares($fn, &$ctrl, &$class) {
$ymls = [];
foreach (require $fn as $ware => $ary) {
unset($yml);
$path = str_replace('\\', '/', realpath($ary['path']));
$cfg = self::cfg($yml, "$path/config.yaml");
$path = str_replace('\\', '/', $ary['path']);
if (!$cfg = self::cfg($yml, "$path/config.yaml"))
continue; ////?
$plan = $cfg['plans'];
if ($ary['type'] ?? false)
$plan['app']['type'] = 'pr-dev';
Expand Down
17 changes: 8 additions & 9 deletions w2/dev_c.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ function tail_y() {
}

function __call($func, $args) {
$x = explode('_', $func, 2);
$set = isset(SKY::$plans[$name = $x[1] ?? '']);
$x = $x[0];
if ($set && 'dev' == SKY::$plans[$name]['app']['type']) {
[$x, $name] = explode('_', $func, 2) + [1 => ''];

if ('dev' == (SKY::$plans[$name]['app']['type'] ?? '')) {
trace($name, 'WARE');
$this->eview = $this->last_ware = $this->d_last_ware = Plan::$ware = Plan::$view = $name;
if (1 == $this->method) {
Expand Down Expand Up @@ -124,10 +123,10 @@ function a_svg() {
}

function x_databases() {
#$list = ['main' => 0] + SKY::$databases;
#unset($list['driver'], $list['pref'], $list['dsn'], $list['']);
//return ['databases' => array_keys($list), 'is_merc' => 'mercury' == Plan::$ware];
return ['databases' => DEV::databases(), 'is_merc' => 'mercury' == Plan::$ware];
return [
'databases' => DEV::databases(),
'is_merc' => 'mercury' == Plan::$ware,
];
}

# ---------------- j_ + a_, see self::__call(..)
Expand Down Expand Up @@ -176,7 +175,7 @@ function j_gate($x = 'j') {
function j_delete() {
self::save($this->_w, $this->_c, $this->_a);
$this->_a or $this->_c = '';
return $this->j_gate();
return $this->j_gate('c');
}

function j_edit() {
Expand Down
44 changes: 31 additions & 13 deletions w2/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ class Install
{
private $mem = false;
private $fn = false;

const DONE = 'Done.';
static $return = false;

static $cli = true;

static function run($page) {
$page or $page = 'database';
Expand All @@ -21,7 +23,7 @@ function memo($var = false, $default = '') {
if ($var) {
if (is_array($default))
return isset($this->mem[$var]) ? explode(' ', $this->mem[$var]) : $default;
return $this->mem[$var] ?: $default;
return $this->mem[$var] ?? $default;
}
return $this->mem;
}
Expand All @@ -43,14 +45,14 @@ function write_sky($fn, $head = false) {
throw new Error("Install: file `$orig` not exists");
}
$bin = file_get_contents($fn);
if (DIR_M . '/config.yaml' == $fn && 'SQLite3' != SKY::$dd->name) {
if (DIR_M . '/config.yaml' == $fn && 'SQLite3' != SKY::$dd->name && isset($_POST['sql'])) {
$bin = preg_replace("/\b(pref|dsn):\s*[^,}\r\n]+/", '$1: ""', $bin);
} elseif ('bootstrap.php' == $fn) {
$bin = preg_replace("/(DIR_S')[^;]+;/", '$1, \'main\');', $bin);
} elseif (WWW . 'index.php' == $fn) {
self::$return = true;
if ($_ = common_c::make_h(true))
$bin = $_;
self::$cli = false;
$bin = common_c::make_h(true);
common_c::make_h(false);
}
fwrite($handle, "FILE: $orig " . strlen($bin) . "\n");
fwrite($handle, $bin . "\n");
Expand Down Expand Up @@ -176,13 +178,19 @@ function _system() {
$this->fn = 'var/' . $_POST['fn'] . '.sky';
list(, $exf, $mkdir, $dirs) = $this->get_files(1);
array_shift($mkdir); # skip `.`
foreach ($dirs as $one)
foreach ($this->filelist($one) as $fn)
isset($exf[$fn]) or $this->skip_file($fn) or $max++;
foreach ($dirs as $one) {
foreach ($this->filelist($one) as $fn) {
if (isset($exf[$fn]) || $this->skip_file($fn))
continue;
$max++;
$this->filep($fn);
}
}
$head = "type app\nmod_required $head";
$head .= "\ndesc " . escape($_POST['desc']);
$head .= "\nversion $_POST[vphp] $and $_POST[vphp2] $_POST[vmysql]\nwww " . WWW;
$head .= "\ncompiled " . date_default_timezone_get() . ' ' . $sky->s_version;
$head .= "\nfilep " . $this->filep();
$sql = isset($_POST['sql']) ? $this->memo('count_tr', '0.0.') : '0.0.';
$head .= "\nftrd A^$max.$sql" . count($mkdir);
$head .= "\n\nDIRS: " . strlen($mkdir = implode(' ', $mkdir)) . "\n$mkdir";
Expand Down Expand Up @@ -229,6 +237,16 @@ function _system() {
]);
}

function filep($fn = null) {
static $ary = [];
if (null === $fn)
return implode(' ', $ary);
$cnt = count($x = explode('/', $fn));
if ($cnt > 2 || $cnt == 2 && WWW != $x[0] . '/')
return;
$ary[] = $fn;
}

function filelist($path) {
$list = Rare::list_path($path, 'is_file');
if (DIR_M == $path || DIR_M . '/w2' == $path) {
Expand Down Expand Up @@ -305,13 +323,13 @@ function _files() {
];
}

static function make($forward = true, Array $plus = []) {
static function make($forward = true, array $plus = []) {
global $sky;
static $index;

$fn = WWW . 'index.php';
if (!$forward)
return file_put_contents($fn, $index);
return self::$cli && file_put_contents($fn, $index);
$sky->memory(11, 'i');
$tpl = "\n function (\$ok) {\n%s },";
$other = '';
Expand All @@ -322,13 +340,13 @@ static function make($forward = true, Array $plus = []) {
$other .= sprintf($tpl, implode('', $code));
}
$file = view('_inst.first_run', [
'vphp' => $sky->i_vphp ?: '5.0',
'vphp' => $sky->i_vphp ?: '7.3',
'vph2' => $sky->i_vphp2 ?: '9.0',
'exts' => $sky->i_modules ?: 'ctype intl mbstring tokenizer',
'tests' => $other,
]);
$index = file_get_contents($fn);
$file = strtr($file, ['<.' => '<?', '.>' => '?>']) . $index;
return self::$return ? $file : file_put_contents($fn, $file);
return self::$cli ? file_put_contents($fn, $file) : $file;
}
}
5 changes: 3 additions & 2 deletions w2/jet.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ function __invoke($return) { /* compile */
Jet::$top .= "extract(\$_vars, EXTR_REFS) ?>";
if (DEV) {
Jet::$top .= "<?php\ntrace(\$_recompile ? 'recompiled' : 'used cached', 'JET'); trace('TPL: $list');";
Jet::$top .= "\nif (" . ($return ? 'true' : 'false') . ' != ($sky->return || HEAVEN::J_FLY == $sky->fly && !$sky->no))';
Jet::$top .= "\nthrow new Error('Return status do not match for file: ' . __FILE__) ?>";
//Jet::$top .= "\nif (" . ($return ? 'true' : 'false') . ' != ($sky->return || HEAVEN::J_FLY == $sky->fly && !$sky->no))';
Jet::$top .= "\nif (" . ($return ? 'true' : 'false') . ' != $sky->return)';
Jet::$top .= "\n throw new Error('Return status do not match for file: ' . __FILE__) ?>";
}
array_walk_recursive($this->parsed, function ($str, $id) use (&$out) {
$out .= is_string($id) ? '' : $str;
Expand Down

0 comments on commit 3abf1d9

Please sign in to comment.