From 78cddbb70d1d7df437acfabca21302ae8d83e322 Mon Sep 17 00:00:00 2001 From: Energy <71418770+energy-coresky@users.noreply.github.com> Date: Fri, 16 Feb 2024 20:25:56 +0300 Subject: [PATCH] Add data yml --- .gitignore | 1 + sky | 4 +- w2/__data.yaml | 92 +++++++++++++++++++++++++ w2/boot.php | 175 +++++++++++++++++++++++++++++++---------------- w2/console.php | 4 +- w2/core.php | 4 ++ w2/transform.php | 63 +++++++++++++++++ 7 files changed, 279 insertions(+), 64 deletions(-) create mode 100644 w2/__data.yaml create mode 100644 w2/transform.php diff --git a/.gitignore b/.gitignore index cd73041..fbe77e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ _arch composer.lock +.coresky diff --git a/sky b/sky index 298365b..a54f4a2 100644 --- a/sky +++ b/sky @@ -63,8 +63,8 @@ do { break; } while($cwd = $_cd); -if ($found[1] && !$found[0] && is_file("$found[1]/.coresky")) { # ware found - $cwd = trim(file_get_contents("$found[1]/.coresky")); +if (!$found[0] && is_file(($cwd = $found[1] ?: __DIR__) . "/.coresky")) { # try find app + $cwd = trim(file_get_contents("$cwd/.coresky")); if ($cwd && is_dir($cwd)) $found[0] = true; # attach app } diff --git a/w2/__data.yaml b/w2/__data.yaml new file mode 100644 index 0000000..8ed69c7 --- /dev/null +++ b/w2/__data.yaml @@ -0,0 +1,92 @@ + +packagist: https://repo.packagist.org/p2/ + +phpman: + en: English + pt_BR: Brazilian Portuguese + zh: Chinese (Simplified) + fr: French + de: German + ja: Japanese + ru: Russian + es: Spanish + tr: Turkish + +const: @csv( ) __DIR__ __FILE__ __LINE__ __FUNCTION__ __CLASS__ __METHOD__ __NAMESPACE__ __TRAIT__ + +keywords: @space + __halt_compiler abstract and array as break callable case catch class clone const continue + declare default die do echo else elseif empty enddeclare endfor endforeach endif endswitch + endwhile eval exit extends final for foreach function global goto if implements include + include_once instanceof insteadof interface isset list namespace new or print private protected + public require require_once return static switch throw trait try unset use var while xor + match readonly fn yield # 'yield from' + +extension: + apache2handler bcmath bz2 calendar cgi-fcgi COM* Core ctype curl date dba dom enchant + exif FFI* fileinfo filter ftp gd gettext gmp hash HRTime* iconv imagick imap interbase + intl ionCube Loader json ldap libxml mbstring mhash* mysqli mysqlnd oci8 odbc openssl pcntl* + pcre PDO PDO_CUBRID PDO_DBLIB PDO_FIREBIRD PDO_IBM PDO_INFORMIX pdo_mysql PDO_OCI PDO_ODBC pdo_pgsql + pdo_sqlite PDO_SQLSRV pgsql Phar phpdbg* posix* pspell readline Reflection session shmop + SimpleXML snmp soap sockets sodium SourceGuardian SPL sqlite3 standard sysvmsg* sysvsem* sysvshm* + tidy tokenizer wddx xml xmlreader xmlwriter xsl Zend OPcache zip zlib + +languages: @bang > + ab.Abkhazian aa.Afar af.Afrikaans ak.Akan sq.Albanian am.Amharic ar.Arabic an.Aragonese hy.Armenian as.Assamese + av.Avaric ae.Avestan ay.Aymara az.Azerbaijani bm.Bambara ba.Bashkir eu.Basque be.Belarusian bn.Bengali bh.Bihari + bi.Bislama bs.Bosnian br.Breton bg.Bulgarian my.Burmese ca.Catalan km.Central_Khmer ch.Chamorro ce.Chechen ny.Chichewa + zh.Chinese cu.Church_Slavic cv.Chuvash kw.Cornish co.Corsican cr.Cree hr.Croatian cs.Czech da.Danish nl.Dutch + dz.Dzongkha en.English eo.Esperanto et.Estonian ee.Ewe fo.Faroese fj.Fijian fi.Finnish fr.French ff.Fulah gd.Gaelic + gl.Galician lg.Ganda ka.Georgian de.German el.Greek kl.Greenlandic gu.Gujarati ht.Haitian ha.Hausa he.Hebrew hz.Herero + hi.Hindi ho.Hiri_Motu hu.Hungarian is.Icelandic io.Ido ig.Igbo id.Indonesian ia.Interlingua ie.Interlingue iu.Inuktitut + ik.Inupiaq ga.Irish it.Italian ja.Japanese jv.Javanese kn.Kannada kr.Kanuri ks.Kashmiri kk.Kazakh ki.Kikuyu rw.Kinyarwanda + ky.Kirghiz kv.Komi kg.Kongo ko.Korean kj.Kuanyama ku.Kurdish lo.Lao la.Latin lv.Latvian li.Limburgan ln.Lingala lt.Lithuanian + lu.Luba-Katanga lb.Luxembourgish mk.Macedonian mg.Malagasy ms.Malay ml.Malayalam dv.Maldivian mt.Maltese gv.Manx mi.Maori + mr.Marathi mh.Marshallese mn.Mongolian na.Nauru nv.Navaho ng.Ndonga ne.Nepali nd.North_Ndebele se.Northern_Sami no.Norwegian + nb.Norwegian_Bokmål nn.Norwegian_Nynorsk ii.Nuosu oj.Ojibwa or.Oriya om.Oromo os.Ossetian pi.Pali pa.Panjabi ps.Pashto + fa.Persian pl.Polish pt.Portuguese qu.Quechua ro.Romanian rm.Romansh rn.Rundi ru.Russian sg.Sango sa.Sanskrit sc.Sardinian + sr.Serbian sn.Shona sd.Sindhi si.Sinhala sk.Slovak sl.Slovene so.Somali nr.South_Ndebele st.Southern_Sotho es.Spanish + su.Sundanese sw.Swahili ss.Swati sv.Swedish tl.Tagalog ty.Tahitian tg.Tajik ta.Tamil tt.Tatar te.Telugu th.Thai + bo.Tibetan ti.Tigrinya to.Tongan ts.Tsonga tn.Tswana tr.Turkish tk.Turkmen tw.Twi ug.Uighur uk.Ukrainian ur.Urdu + uz.Uzbek ve.Venda vi.Vietnamese vo.Volapük wa.Walloon cy.Welsh fy.Western_Frisian wo.Wolof xh.Xhosa yi.Yiddish + yo.Yoruba za.Zhuang zu.Zulu + +timezones: @csv(;) # @join + Africa: Abidjan;Accra;Addis_Ababa;Algiers;Asmara;Bamako;Bangui;Banjul;Bissau;Blantyre;Brazzaville;Bujumbura;Cairo;Ceuta;Conakry;Dakar;Dar_es_Salaam;Djibouti;Douala;Freetown;Gaborone;Harare;Johannesburg;Juba;Kampala;Khartoum;Kigali;Kinshasa;Lagos;Libreville;Lome;Luanda;Lubumbashi;Lusaka;Malabo;Maputo;Maseru;Mbabane;Mogadishu;Monrovia;Nairobi;Ndjamena;Niamey;Nouakchott;Ouagadougou;Porto-Novo;Sao_Tome;Tripoli;Tunis;Windhoek + America: Adak;Anchorage;Anguilla;Antigua;Argentina/Buenos_Aires;Argentina/Catamarca;Argentina/Cordoba;Argentina/Jujuy;Argentina/La_Rioja;Argentina/Mendoza;Argentina/Rio_Gallegos;Argentina/Salta;Argentina/San_Juan;Argentina/San_Luis;Argentina/Tucuman;Argentina/Ushuaia;Aruba;Asuncion;Atikokan;Bahia_Banderas;Barbados;Belize;Blanc-Sablon;Bogota;Boise;Cambridge_Bay;Cancun;Caracas;Cayman;Chicago;Chihuahua;Costa_Rica;Creston;Curacao;Danmarkshavn;Dawson;Dawson_Creek;Denver;Detroit;Dominica;Edmonton;El_Salvador;Fort_Nelson;Glace_Bay;Goose_Bay;Grand_Turk;Grenada;Guadeloupe;Guatemala;Guayaquil;Halifax;Havana;Hermosillo;Indiana/Indianapolis;Indiana/Knox;Indiana/Marengo;Indiana/Petersburg;Indiana/Tell_City;Indiana/Vevay;Indiana/Vincennes;Indiana/Winamac;Inuvik;Iqaluit;Jamaica;Juneau;Kentucky/Louisville;Kentucky/Monticello;Kralendijk;La_Paz;Los_Angeles;Lower_Princes;Managua;Marigot;Martinique;Matamoros;Mazatlan;Menominee;Merida;Metlakatla;Mexico_City;Miquelon;Moncton;Monterrey;Montevideo;Montserrat;Nassau;New_York;Nipigon;Nome;North_Dakota/Beulah;North_Dakota/Center;North_Dakota/New_Salem;Ojinaga;Panama;Pangnirtung;Paramaribo;Phoenix;Port-au-Prince;Port_of_Spain;Puerto_Rico;Punta_Arenas;Rainy_River;Rankin_Inlet;Regina;Resolute;Santiago;Santo_Domingo;Sitka;St_Barthelemy;St_Johns;St_Kitts;St_Lucia;St_Thomas;St_Vincent;Swift_Current;Tegucigalpa;Thule;Thunder_Bay;Tijuana;Toronto;Tortola;Vancouver;Whitehorse;Winnipeg;Yakutat;Yellowknife + Antarctica: Macquarie;McMurdo + Arctic: Longyearbyen + Asia: Amman;Baghdad;Bangkok;Beirut;Colombo;Damascus;Dhaka;Famagusta;Gaza;Hebron;Ho_Chi_Minh;Hong_Kong;Irkutsk;Jakarta;Jayapura;Jerusalem;Karachi;Kolkata;Kuala_Lumpur;Macau;Makassar;Manila;Nicosia;Phnom_Penh;Pontianak;Pyongyang;Seoul;Shanghai;Singapore;Taipei;Tbilisi;Tehran;Tokyo;Vientiane;Yangon;Yekaterinburg + Atlantic: Azores;Bermuda;Canary;Faroe;Madeira;Reykjavik;St_Helena;Stanley + Australia: Adelaide;Brisbane;Broken_Hill;Darwin;Hobart;Lindeman;Lord_Howe;Melbourne;Perth;Sydney + Europe: Amsterdam;Andorra;Athens;Belgrade;Berlin;Bratislava;Brussels;Bucharest;Budapest;Busingen;Chisinau;Copenhagen;Dublin;Gibraltar;Guernsey;Helsinki;Isle_of_Man;Istanbul;Jersey;Kaliningrad;Kiev;Lisbon;Ljubljana;London;Luxembourg;Madrid;Malta;Mariehamn;Minsk;Monaco;Moscow;Oslo;Paris;Podgorica;Prague;Riga;Rome;San_Marino;Sarajevo;Simferopol;Skopje;Sofia;Stockholm;Tallinn;Tirane;Uzhgorod;Vaduz;Vatican;Vienna;Vilnius;Warsaw;Zagreb;Zaporozhye;Zurich + Indian: Antananarivo;Comoro;Maldives;Mayotte + Pacific: Auckland;Easter;Guam;Honolulu;Midway;Pago_Pago;Saipan + +config: + -
+ - + + + + diff --git a/w2/boot.php b/w2/boot.php index 5a53518..5d6424a 100644 --- a/w2/boot.php +++ b/w2/boot.php @@ -12,6 +12,7 @@ class Boot private $at; private $array; + private $tail; private $stack = []; private $mode = [ 'em' => '', @@ -29,36 +30,19 @@ static function auto($v, $more = '', $func = false) { return " $func]; self::$transform = $ary + self::$transform; } function __construct($dc = false, $nx = null) { - $this->array = []; self::$eval = fn($v) => $v; - - self::$transform = [ - 'inc' => fn($v) => self::inc($v), - 'eval' => self::$eval, - 'bin' => fn($v) => intval($v, 2), - 'oct' => fn($v) => intval($v, 8), - 'hex' => fn($v) => intval($v, 16), - 'base64' => fn($v) => base64_decode($v), - 'split' => fn($v) => preg_split("/\s+/", $v), - 'bang' => fn($v) => strbang(trim(unl($v))), - 'self' => function ($path, &$a, $unset = false) { - $p =& $this->array; - foreach (explode('.', $path) as $key) { - $prev =& $p; - $p =& $p[$key]; - } - $return = $p; - if ($unset) - unset($prev[$key]); - return $return; - }, - ]; + $this->transformers(); + $this->array = []; if (!$dc) { if (self::$boot) @@ -141,11 +125,14 @@ static function yml(string $in, $is_file = true, $try = false) { defined('DEV') && (self::$dev = DEV); $yml = new Boot; $yml->at = [$is_file ? $in : false, 0]; - $yml->yml_text($is_file ? file_get_contents($in) : $in); - return $yml->array; + $text = trim($is_file ? file_get_contents($in) : $in) . "\n"; + if ($cell = '+' == $text[0]) + $text[0] = '-'; + $yml->yml_text($text); + return $cell ? $yml->array[0] : $yml->array; } - private function yml_text(string $in) { + private function yml_text(string &$in) { $p = ['' => &$this->array]; $add = function ($m) use (&$p) { if (is_string($m->key) && 'DEV+' == substr($m->key, 0, 4)) { @@ -168,7 +155,8 @@ private function yml_text(string $in) { }; $n = $this->obj(); - foreach (explode("\n", unl($in)) as $key => $in) { + $this->tail = explode("\n~\n", unl($in)); + foreach (explode("\n", $this->tail[0]) as $key => $in) { $this->at[1] = 1 + $key; $m = clone $n; if ($this->yml_line($in . ' ', $n, $m->code)) @@ -191,8 +179,10 @@ private function yml_val($m, &$define) { } if ($m->json) { $v = json_decode($m->json, true); - if (json_last_error()) + if (json_last_error()) { + echo $m->json; $this->halt('JSON failed'); + } } else { $v = $this->scalar($m->mod ? $m->val : trim($m->val), true, $m); if (1 == self::$boot) { @@ -208,6 +198,17 @@ private function yml_val($m, &$define) { return $v; } + private function code(string $str, &$t) { + if (!preg_match("/^@(\w+)(\(|)(.+)$/", $str, $match)) + return false; + [,$name, $q, $rest] = $match; + if (!$q && ' ' == $rest[0]) + return true; + if ($q = self::bracket("($rest"))// ' ' + $t = "@$name$q"; + return $q ? [$name, substr($q, 1, -1)] : false; + } + private function tokens(string &$in, $json) { $len = strlen($in); return new eVar(function ($prev) use (&$in, $json, $len) { @@ -230,13 +231,15 @@ private function tokens(string &$in, $json) { } else { $cl = $this->mode[$mode]; $t = strpbrk($x, ":-$cl") ? $x : substr($in, $j, strcspn($in, "\t\"' :-$cl", $j)); + if ($code = '@' == $x && 'val' == $mode) + $code = $this->code(substr($in, $j), $t); } return [ 'token' => $t, 'ws' => $whitespace, 'keyc' => $colon = ':' == $wt, 'key2' => $colon || '-' == $wt, - 'code' => 'val' == $mode && '@' == $wt[0], + 'code' => $code ?? false, 'mode' => $mode, ]; }); @@ -248,10 +251,11 @@ private function yml_line(string $in, &$n, &$code) { $pad = ''; $len = strlen($p =& $n->val); $setk = true; # set key first - $reqk = false; + $reqk = $pc = false; foreach ($this->tokens($in, $n->json) as $_ => $el) { $t = $el->token; + $_pc = false; if (0 == $_) { # first step ($has_t = !$el->ws) ? ($p .= $t) : ($pad = $this->halt(false, $t)); $reqk = $pad <= $pad_0; # require match key @@ -267,8 +271,8 @@ private function yml_line(string $in, &$n, &$code) { } elseif ($el->key2 && $setk && ($reqk || !$n->mod)) { # key found if ($pad > $n->pad) { # aggregate node $len && $this->halt('Mapping disabled'); - if ($code) - $this->stack[] = [$code, $n->pad, $n->pad]; + foreach ($code as $fun) + $this->stack[] = [$fun, $n->pad, $n->pad]; $code = 0; } $key = $el->keyc ? $this->scalar(substr($p, $len, -1)) : true; @@ -285,10 +289,11 @@ private function yml_line(string $in, &$n, &$code) { null !== $n->key or $this->halt('Key cannot be NULL'); $el->mode = 'val'; $p = ''; - } elseif ($el->code) { - if (!$n->code = self::$transform[substr($p, 1)] ?? false) - $this->halt("Transformation `$p` not found"); - $p = ''; + } elseif ($_pc = $el->code && '' === $p) { + [$name, $param] = is_array($el->code) ? $el->code : [substr($t, 1), '']; + if (!$fun = self::$transform[$name] ?? false) + $this->halt("Transformation `@$name` not found"); + $n->code[] = [$fun, $param]; } elseif ($n->json && 1 == strlen($t) && !$reqk && strpbrk($t, ':{},[]')) { $n->json .= '' === ($p = trim($p)) ? $t : $this->scalar($p, ':' != $t, $n, true) . $t; $p = ''; @@ -301,9 +306,10 @@ private function yml_line(string $in, &$n, &$code) { $len++; if ('' !== $p && 'val' == $el->mode) $el->mode = 'em'; - $p .= $xmul ? " $t" : $t; + $pc or $p .= $xmul ? " $t" : $t; $has_t = true; } + $pc = $_pc; } if ($setk) { @@ -335,7 +341,7 @@ private function obj(array $in = []) : stdClass { 'val' => '', 'voc' => false, 'json' => false, - 'code' => false, + 'code' => [], ]; return (object)$in; } @@ -349,6 +355,10 @@ private function var(string &$in) { $in = self::env($key, substr($bkt, 1, -1)); } elseif ('SELF' == $key) { $in = self::$dir; + } elseif ('TAIL' == substr($key, 0, 4)) { + $in = 'TAILS' == $key + ? array_slice($this->tail, 1) + : $this->tail[$key[4] ?? 1] ?? null; } elseif (defined($key)) { $in = constant($key); 'WWW' != $key or $in = substr($in, 0, -1); @@ -361,22 +371,23 @@ private function var(string &$in) { '' === $rest or $in = (string)$in . $rest; } - private function transform(&$v, $n) { + private function transform(&$v, $n, $has_var) { $ary = array_reverse($this->stack); - if ($n->code) - array_unshift($ary, [$n->code, 1]); # ' ' > 1 is false +//var_export($n->code); + foreach ($n->code as $fun) + array_unshift($ary, [$fun, 1]); # ' ' > 1 is false foreach ($ary as $one) { [$code, $pad] = $one; if ($n->pad > $pad || 1 === $pad) - $v = run_transform($code, $v, $this->array); + $v = run_transform($code, $v, $this->array, $has_var); } return !is_string($v); } private function scalar(string $v, $is_val = false, $n = 0, $json = false) { - if ($v && '$' == $v[0]) + if ($has_var = $v && '$' == $v[0]) $this->var($v); - if ($is_val && 0 !== $n->code && $this->transform($v, $n)) + if ($is_val && 0 !== $n->code && $this->transform($v, $n, $has_var)) return $v; if ('' === $v || 'null' === $v) return $json ? 'null' : null; @@ -394,23 +405,27 @@ private function scalar(string $v, $is_val = false, $n = 0, $json = false) { $x = substr($v, 1); return ctype_digit($x) ? intval($v) : floatval($v); } - return $json ? '"' . str_replace('\\', '\\\\', $v) . '"' : $v; + return $json ? '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $v) . '"' : $v; } static function inc($name, $ware = false) { + $inc = function ($dir, $name) { + $ext = explode('.', $name); + switch (end($ext)) { + case 'php': return $dir ? (require $name) : Plan::_r($name); + case 'json': return json_decode($dir ? file_get_contents($name) : Plan::_g($name), true); + case 'yml': + case 'yaml': return self::yml($dir ? $name : Plan::_t($name)); + default: return strbang(unl($dir ? file_get_contents($name) : Plan::_g($name))); + } + }; + if (true === $ware) + return $inc(true, $name); if (!$ware) { strpos($name, '::') or $name = Plan::$ware . '::' . $name; [$ware, $name] = explode('::', $name, 2); } - $addr = [$ware, $name]; - $ext = explode('.', $name); - switch (end($ext)) { - case 'php': return Plan::app_r($addr); - case 'json': return json_decode(Plan::app_g($addr), true); - case 'yml': - case 'yaml': return self::yml(Plan::app_t($addr)); - default: return strbang(unl(Plan::app_g($addr))); - } + return Plan::set($ware, fn() => $inc(false, $name)); } static function cfg(&$name, $ware = 'main') { @@ -477,16 +492,56 @@ static function str(string &$in, $p, $len) { $p += ($bs = strspn($in, '\\', $p)); } } -} -function yaml($path, $unset = false) { - return (Boot::$transform['self'])($path, $path, $unset); + private function transformers() { + self::$transform = [ + 'inc' => fn($v, $x, &$a, $has_var) => self::inc($v, $has_var), + 'eval' => self::$eval, + 'ip' => fn($v) => ip2long($v), + // 'str' => fn($v) => strval($v), + 'dec' => fn($v) => str_replace([' ', '_', '-'], '', $v), + 'bin' => fn($v) => intval($v, 2), + 'oct' => fn($v) => intval($v, 8), + 'hex' => fn($v) => intval($v, 16), + 'hex2bin' => fn($v) => hex2bin(str_replace(' ', '', $v)), + 'rot13' => fn($v) => str_rot13($v), + 'base64' => fn($v) => base64_decode($v), + 'ini_get' => fn($v) => ini_get($v), + 'space' => fn($v) => preg_split("/\s+/", $v), + 'semi' => fn($v) => explode(';', $v), + 'csv' => fn($v, $x) => explode('' === $x ? ',' : $x, $v), + 'join' => fn($v, $x) => implode('' === $x ? ',' : $x, $v), + 'bang' => fn($v) => strbang(trim(unl($v))), + 'url' => fn($v) => parse_url($v), + 'time' => fn($v) => strtotime($v), + 'scan' => fn($v, $x) => sscanf($v, $x), + 'left' => function ($v, $x) { + if (!is_array($v)) + return $x . $v; + array_walk_recursive($v, fn(&$_) => $_ = $x . $_); + return $v; + }, + 'self' => function& ($v, $path, &$a = null, $_ = 0, $unset = false) { + '' === $v ? ($p =& $this->array) : ($p =& $v); + if (!is_string($path)) + return is_int($path) ? $this->tail[$path] : $this->tail; + foreach (explode('.', $path) as $key) { + $prev =& $p; + $p =& $p[$key]; + } + $return =& $p; + if ($unset) + unset($prev[$key]); + return $return; + }, + ]; + } } -function run_transform($__code__, $v, &$a) { +function run_transform($__code__, $v, &$a, $has_var) { global $sky; - $__ret__ = $__code__($v, $a); - if ($__code__ !== Boot::$eval) + $__ret__ = ($__code__[0])($v, $__code__[1], $a, $has_var); + if ($__code__[0] !== Boot::$eval) return $__ret__; $tok = token_get_all(" $__ret__"); if (!array_filter($tok, fn($v) => is_array($v) && T_RETURN == $v[0])) diff --git a/w2/console.php b/w2/console.php index 49a2c43..3921be6 100644 --- a/w2/console.php +++ b/w2/console.php @@ -321,12 +321,12 @@ function c_w() { print_r($list); } - /** Parse Yaml [ware=main] [fn=config.yaml] [one of 0|1|2] or Inline Yaml > sky y "- @eval SKY::CORE" */ + /** Parse Yaml [ware=main] [fn=config.yaml] [one of 0|1|2] or Inline Yaml > sky y "+ @semi $PATH()" */ function c_y($ware = 'main', $fn = 'config.yaml', $func = 0) { $list = ['var_export', 'print_r', 'var_dump']; if (strpos($ware, ' ')) { # inline yaml !is_num($fn) or $func = $fn; - echo "Inline Yaml: "; + '~' == ltrim($ware)[0] or print "Inline Yaml: "; $list[$func](Boot::yml($ware, false)); } elseif (!$fn = Plan::_t([$ware, $fn])) { echo "File `$fn`, ware=$ware is: not found"; diff --git a/w2/core.php b/w2/core.php index 6e44483..703f120 100644 --- a/w2/core.php +++ b/w2/core.php @@ -10,6 +10,10 @@ function sql(...$in) { return $sql->exec(); } +function yml(...$in) { + +} + function qp(...$in) { # Query Part, Query Parse $in or $in = ['']; return new SQL($in, 'parseT'); diff --git a/w2/transform.php b/w2/transform.php new file mode 100644 index 0000000..a0b2f14 --- /dev/null +++ b/w2/transform.php @@ -0,0 +1,63 @@ + fn($v, $x, &$a, $has_var) => self::inc($v, $has_var), + 'eval' => self::$eval, + 'ip' => fn($v) => ip2long($v), + // 'str' => fn($v) => strval($v), + 'dec' => fn($v) => str_replace([' ', '_', '-'], '', $v), + 'bin' => fn($v) => intval($v, 2), + 'oct' => fn($v) => intval($v, 8), + 'hex' => fn($v) => intval($v, 16), + 'hex2bin' => fn($v) => hex2bin(str_replace(' ', '', $v)), + 'rot13' => fn($v) => str_rot13($v), + 'base64' => fn($v) => base64_decode($v), + 'ini_get' => fn($v) => ini_get($v), + 'space' => fn($v) => preg_split("/\s+/", $v), + 'semi' => fn($v) => explode(';', $v), + 'csv' => fn($v, $x) => explode('' === $x ? ',' : $x, $v), + 'join' => fn($v, $x) => implode('' === $x ? ',' : $x, $v), + 'bang' => fn($v) => strbang(trim(unl($v))), + 'url' => fn($v) => parse_url($v), + 'time' => fn($v) => strtotime($v), + 'scan' => fn($v, $x) => sscanf($v, $x), + 'left' => function ($v, $x) { + if (!is_array($v)) + return $x . $v; + array_walk_recursive($v, fn(&$_) => $_ = $x . $_); + return $v; + }, + 'self' => function& ($v, $path, &$a = null, $_ = 0, $unset = false) { + '' === $v ? ($p =& $this->array) : ($p =& $v); + if (!is_string($path)) + return is_int($path) ? $this->tail[$path] : $this->tail; + foreach (explode('.', $path) as $key) { + $prev =& $p; + $p =& $p[$key]; + } + $return =& $p; + if ($unset) + unset($prev[$key]); + return $return; + }, + ]; + } +} + + +function __run_transform($__code__, $v, &$a, $has_var) { + global $sky; + $__ret__ = ($__code__[0])($v, $__code__[1], $a, $has_var); + if ($__code__[0] !== Boot::$eval) + return $__ret__; + $tok = token_get_all(" $__ret__"); + if (!array_filter($tok, fn($v) => is_array($v) && T_RETURN == $v[0])) + $__ret__ = 'return ' . $__ret__; + return eval("$__ret__;"); +}