hpaco-lib-0.11.0.6: snippets/php/preamble.php
<?php
if (!class_exists('_S', false)) {
class _S {
public $t;
public $p;
public function __construct($t, $p) { $this->t = $t; $this->p = $p; }
public function __isset($key) {
return (
(is_array($this->t) && isset($this->t[$key])) ||
(is_object($this->t) && isset($this->t->$key)) ||
(is_array($this->p) && isset($this->p[$key])) ||
(is_object($this->p) && isset($this->p->$key)));
}
public function __get($key) {
if (is_array($this->t) && isset($this->t[$key])) return $this->t[$key];
if (is_object($this->t) && isset($this->t->$key)) return $this->t->$key;
if (is_array($this->p) && isset($this->p[$key])) return $this->p[$key];
if (is_object($this->p) && isset($this->p->$key)) return $this->p->$key;
return null;
}
}
}
if (!class_exists('_LF', false)) {
class _LF {
public $f;
public function __construct($f) { $this->f = $f; }
public function __invoke() { return call_user_func_array($this->f, func_get_args()); }
public function __toString() { return '<<function>>'; }
}
}
if (!class_exists('_LL', false)) {
class _LL {
public function __invoke($libname) {
switch ($libname) {
case 'std':
return array(
'count' => new _LF('count'),
'join' => new _LF('implode'),
);
default: throw new Exception('No such library: ' . $libname);
}
}
}
}
if (!is_callable('_r')) {
function _r($context, $key) {
if ($key === '.') return $context;
if ($key === 'library') return new _LL;
if (is_array($context)) {
if (isset($context[$key])) return $context[$key];
}
if (is_object($context)) {
if (isset($context->$key)) return $context->$key;
}
return null;
}
}
if (!is_callable('_in')) {
function _in($elem, $list) {
if (is_array($list)) {
return in_array($elem, $list);
}
return false;
}
}
if (!is_callable('_f')) {
function _f($val) {
if (is_array($val)) {
return implode(' ', $val);
}
return (string)$val;
}
}
if (!is_callable('_call')) {
function _call($func, $args) {
if ($func instanceof FunctionPointer || $func instanceof _LL || $func instanceof _LF) {
return call_user_func_array($func, $args);
}
return null;
}
}