Skip to content

Commit

Permalink
tuning code
Browse files Browse the repository at this point in the history
  • Loading branch information
energy-coresky committed May 16, 2021
1 parent 97eac49 commit f39cc34
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 25 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

# CORESKY is unusual PHP framework

It doesn't follow much of PSRs: namespaces is absent, "global $sky, $user;" used and may be more..
It doesn't follow much of PSRs: coresky and apps code use global namespace!
(however you can use `vendor folder classes` from packagist.org or others),
frequently used "global $sky, $user;" and may be more..
But this is my favorite "oil painting"! Not finished, but you can use it.

Regards,
Expand All @@ -17,3 +19,13 @@ AB (absolute busy) app is product of InfoParc http://absolutebusy.com/ moved to
- http://ru.coresky.net/tree?id69 (Ghost SQLs)
- http://ru.coresky.net/tree?id62 (Parser Jet)
- http://ru.coresky.net/tree?id67 (Sky Gate)

## TODO

- Moves to PDO SQLs and write query builer
- Finish SQL functions and drivers
- Add something like Laravel's middleware
- Add modules for apps (use global namespace)
- Add migration for databases
- Move coresky code to RAM
- Fix others and prepare production version 1.0
Binary file removed apps/ab07776.sky.zip
Binary file not shown.
Binary file added apps/ab07778.sky.zip
Binary file not shown.
19 changes: 10 additions & 9 deletions sky.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ function __construct() {
trace("autoload($name)");
if (in_array(substr($name, 0, 2), ['m_', 'q_', 't_'])) {
is_file($file = "main/app/$name.php") ? require $file : eval("class $name extends Model_$name[0] {}");
} else {
is_file($file = DIR_S . '/w2/' . ($name = strtolower($name)) . '.php') ? require $file : require "main/w3/$name.php";
}
});
} elseif (is_file($file = DIR_S . '/w2/' . ($name = strtolower($name)) . '.php')) {
require $file; # wing2 folder
} elseif (false === strpos($name, '\\')) {
require "main/w3/$name.php";
} # else `vendor` folder
}, true, true);
set_error_handler(function ($no, $message, $file, $line, $context = null) {
if (error_reporting() & $no && ($this->debug || $this->s_prod_error)) {
$this->error_title = 'PHP ' . ($err = Debug::error_name($no));
Expand Down Expand Up @@ -266,7 +268,7 @@ function constants() {
define('TPL_META', '<meta name="%s" content="%s" />');
}

const CORE = '0.113 2021-05-02T23:01:11+03:00 energy';
const CORE = '0.114 2021-05-16T11:01:11+03:00 energy';

static function version() {
global $sky;
Expand Down Expand Up @@ -304,7 +306,7 @@ class eVar implements Iterator
{
private $state = 0;
private $i = -1;
private $max_i = 500; # -1 is infinite
private $max_i;
private $row;
private $e;
private $dd = false;
Expand All @@ -314,7 +316,7 @@ function __construct(Array $e) {
}

function __get($name) {
return isset($this->e[$name]) ? $this->e[$name] : null;
return $this->e[$name] ?? null;
}

function rewind() {
Expand All @@ -337,8 +339,7 @@ function rewind() {
return $this->state++;
$this->dd = $sql->_dd;
}
if (isset($this->e['max_i']))
$this->max_i = $this->e['max_i'];
$this->max_i = $this->e['max_i'] ?? 500; # -1 is infinite
$this->next();
}

Expand Down
4 changes: 2 additions & 2 deletions w2/display.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private function add_line_no(&$val, $key) {
$val = strtr($val, ['=TOP-TITLE=' => '&#61;TOP-TITLE&#61;']);
$colors = ['' => '', '=' => '', '*' => 'ff7', '+' => 'dfd', '-' => 'fdd', '.' => 'eee'];
$pad = $c = '';
if (!$key) for(; $this->lenb > $key + $this->disp && $this->back{$key + $this->disp} == '.'; $this->disp++)
if (!$key) for(; $this->lenb > $key + $this->disp && $this->back[$key + $this->disp] == '.'; $this->disp++)
$this->lnum .= "<br>" and $pad .= '<div class="code" style="background:#eee">&nbsp;</div>';
if ($this->lenb > $key + $this->disp) $c = $colors[$this->back[$key + $this->disp]];
$key++;
Expand All @@ -37,7 +37,7 @@ private function add_line_no(&$val, $key) {
elseif ($val == '</span>') $val = '&nbsp;</span>';
elseif ($val == '</span></span>') $val = '&nbsp;</span></span>';
$val = $pad . ($c ? '<div class="code" style="background:'."#$c\">$val</div>" : "$val\n");
for (; $this->lenb > $key + $this->disp && $this->back{$key + $this->disp} == '.'; $this->disp++) { # = - + * .
for (; $this->lenb > $key + $this->disp && $this->back[$key + $this->disp] == '.'; $this->disp++) { # = - + * .
$this->lnum .= "<br>";
$val .= '<div class="code" style="background:#eee">&nbsp;</div>';
}
Expand Down
26 changes: 14 additions & 12 deletions w2/gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Gate
{
private $out;
private $gate_file;
private $url = '';
static $cshow = 0;
static $contr_ary = false; # not loaded initialy
Expand Down Expand Up @@ -146,7 +146,7 @@ static function put_cache($class, $fn_src, $fn_dst) {
self::real_src($real, $fn_src, false);
$me = new Gate;
$me->parse($fn_src, self::$contr_ary, $class);
file_put_contents($fn_dst, $me->out);
file_put_contents($fn_dst, $me->gate_file);
}

function view_code($ary, $class, $func) {
Expand Down Expand Up @@ -302,20 +302,24 @@ function argc($s) {
}

function parse($fn, $ary = [], $dst_class = false) {
$this->out = "<?php\n\nclass Gape extends Bolt\n{";
$gape = "class Gape extends Bolt\n{";
$c = $f = $depth = $found = 0;
$list = [];
$class = basename($fn, '.php');
$dst_class or $dst_class = $class;
if ($virt = $dst_class != $class)
$this->out .= "\n\tpublic \$src = '" . substr($class, 2) . "';\n";
if (!$dst_class) {
$dst_class = $class;
$gape .= "\n\tpublic \$src = '" . substr($class, 2) . "';\n";
}
$tpl_class = explode(' ', 'T_OPEN_TAG T_CLASS T_STRING T_EXTENDS T_STRING {');
$content = file_get_contents($fn);
if (!preg_match('/^(<\?(php)?)/', $content, $match))
if (!preg_match('/^<\?(php)?(.*?)class ' . $class . ' extends(.+)$/s', $content, $match))
throw new Err("File `$fn` must start from &lt;?");
$start = false;
foreach (token_get_all($content) as $v) {
if (is_array($v)) {
if (in_array($v[0], [T_WHITESPACE, T_COMMENT, T_DOC_COMMENT])) {
if (T_CLASS == $v[0])
$start = true;
if (in_array($v[0], [T_WHITESPACE, T_COMMENT, T_DOC_COMMENT, T_USE]) || !$start && $v[0] != T_OPEN_TAG) {
continue;
}
if (T_CURLY_OPEN == $v[0] || T_DOLLAR_OPEN_CURLY_BRACES == $v[0])
Expand Down Expand Up @@ -349,7 +353,7 @@ function parse($fn, $ary = [], $dst_class = false) {
isset($ary[$name]) or $ary[$name] = [];
$php = $this->code($ary[$name], $cmode, false);
$php = "\t\t" . str_replace("\n", "\n\t\t", substr($php, 0, -1)) . "\n";
$this->out .= "\n\tfunction $name(\$sky, \$user) {\n$php\t}\n";
$gape .= "\n\tfunction $name(\$sky, \$user) {\n$php\t}\n";
$f = 0;
continue;
}
Expand All @@ -360,9 +364,7 @@ function parse($fn, $ary = [], $dst_class = false) {
$func[1] .= $v;
}
}
if ($virt)
$content = preg_replace("/class $class extends/", "class $dst_class extends", $content);
$this->out .= '}' . substr($content, strlen($match[1]));
$this->gate_file = '<?php' . $match[2] . $gape . "}\n\nclass $dst_class extends" . $match[3];
return $found ? $list : [];
}

Expand Down
2 changes: 1 addition & 1 deletion w2/mvc.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ static function top() {
trace("$controller::$action()" . ($controller == $real ? '' : ' (virtual)'), 'TOP-VIEW');
if (DEFAULT_LG) {
require 'main/lng/' . LG . '.php';
SKY::$reg['trans_late'] = isset($lgt) ? $lgt : [];
SKY::$reg['trans_late'] = $lgt ?? [];
SKY::$reg['trans_coll'] = [];
}
require 'main/app/common_c.php';
Expand Down

0 comments on commit f39cc34

Please sign in to comment.