From dfe29ddf3c2f132e5607692660932ed51e460787 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Tue, 17 May 2022 14:02:51 +0300 Subject: [PATCH] Isolating dependencies --- targets/php/php.inc.php | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/targets/php/php.inc.php b/targets/php/php.inc.php index 2cb1d4c..b74bde6 100644 --- a/targets/php/php.inc.php +++ b/targets/php/php.inc.php @@ -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)