Isolating dependencies

This commit is contained in:
Pavel Shevaev 2022-05-17 14:02:51 +03:00
parent aea8c17602
commit dfe29ddf3c
1 changed files with 32 additions and 2 deletions

View File

@ -92,7 +92,7 @@ class mtgPHPCodegen extends mtgCodegen
$repl['%code%'] = $packet->getNumericCode();
$repl['%class%'] = $packet->getName();
$repl['%class_id%'] = $packet->getClassId();
$repl['%parent_class%'] = 'extends gmeStrictPropsObject';
$repl['%parent_class%'] = 'extends mtgStrictPropsObject';
$tpl = $templater->tpl_packet();
@ -108,7 +108,7 @@ class mtgPHPCodegen extends mtgCodegen
$repl = array();
$repl['%class%'] = $struct->getName();
$repl['%class_id%'] = $struct->getClassId();
$repl['%parent_class%'] = $struct->getParent() ? "extends " . $struct->getParent() : "extends gmeStrictPropsObject";
$repl['%parent_class%'] = $struct->getParent() ? "extends " . $struct->getParent() : "extends mtgStrictPropsObject";
$tpl = $templater->tpl_struct();
@ -446,6 +446,36 @@ class mtgPHPCodegen extends mtgCodegen
}
}
class mtgStrictPropsObject
{
function getTextPropsList()
{
return implode(", ", mtg_get_public_props_names($this));
}
function __get($name)
{
throw new Exception("No such property '$name' in class " . get_class($this) . " to get, available properties: " .
$this->getTextPropsList());
}
function __set($name, $value)
{
throw new Exception("No such property '$name' in class " . get_class($this) . " to set, available properties: " .
$this->getTextPropsList());
}
}
function mtg_get_public_props_names($obj)
{
static $cache = array();
$klass = is_string($obj) ? $obj : get_class($obj);
if(!isset($cache[$klass]))
$cache[$klass] = array_keys(get_class_vars($klass));
return $cache[$klass];
}
////////////////////////////////////////////////////////////////////////
function mtg_php_array_extract_val(&$arr, $assoc, $name, $default = null)