Adding check_junk optional support during normalization
Publish PHP Package / docker (push) Successful in 8s
Details
Publish PHP Package / docker (push) Successful in 8s
Details
This commit is contained in:
parent
2c87cfe7ad
commit
c38e315e68
|
@ -353,13 +353,13 @@ function data_normalize($name, \mtgType $type, $buf, $dst, $tokens = array(), $t
|
|||
$str .= "\$vclass__ = AutogenBundle::getClassName(\$vclass_id__);\n";
|
||||
$str .= "if(!is_a(\$vclass__, '{$type->getName()}', true)) throw new Exception(\"'\$vclass__' is not subclass of '{$type->getName()}'\");\n";
|
||||
$str .= "\$tmp_sub_mapped__ = array(\$vclass_id__);\n";
|
||||
$str .= "call_user_func_array([\$vclass__, 'normalize'], array(&\$tmp_sub_arr__, &\$tmp_sub_mapped__));\n";
|
||||
$str .= "call_user_func_array([\$vclass__, 'normalize'], array(&\$tmp_sub_arr__, &\$tmp_sub_mapped__, true, \$check_junk));\n";
|
||||
$str .= "{$dst}[] = \$tmp_sub_mapped__;\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$str .= "\$tmp_sub_mapped__ = array();\n";
|
||||
$str .= "{$type}::normalize(\$tmp_sub_arr__, \$tmp_sub_mapped__);\n";
|
||||
$str .= "{$type}::normalize(\$tmp_sub_arr__, \$tmp_sub_mapped__, true, \$check_junk);\n";
|
||||
$str .= "{$dst}[] = \$tmp_sub_mapped__;\n";
|
||||
}
|
||||
$str .= "}";
|
||||
|
|
|
@ -222,3 +222,11 @@ function val_blob($val)
|
|||
|
||||
return $val;
|
||||
}
|
||||
|
||||
function check_junk_fields(array $data, array $FIELDS)
|
||||
{
|
||||
unset($data['$id']);
|
||||
$diff = array_diff(array_keys($data), $FIELDS);
|
||||
if($diff)
|
||||
throw new Exception("Junk fields: " . json_encode(array_values($diff)));
|
||||
}
|
||||
|
|
|
@ -82,6 +82,7 @@ class {{o.name}} {{o.parent ? 'extends ' ~ o.parent.name}}
|
|||
$FIELDS = self::CLASS_FIELDS();
|
||||
throw new Exception($e->getMessage() . " < {$FIELDS[$IDX]} < ({{o.name}})");
|
||||
}
|
||||
|
||||
return $IDX;
|
||||
}
|
||||
|
||||
|
@ -100,7 +101,7 @@ class {{o.name}} {{o.parent ? 'extends ' ~ o.parent.name}}
|
|||
{{_self.export_fields(o)}}
|
||||
}
|
||||
|
||||
static function normalize(array &$data, array &$mapped, bool $root = true) : int
|
||||
static function normalize(array &$data, array &$mapped, bool $root = true, bool $check_junk = false) : int
|
||||
{
|
||||
$IDX = -1;
|
||||
|
||||
|
@ -108,7 +109,7 @@ class {{o.name}} {{o.parent ? 'extends ' ~ o.parent.name}}
|
|||
{
|
||||
$IDX = 0;
|
||||
{%- if o.parent ~%}
|
||||
$IDX = parent::normalize($data, $mapped, false);
|
||||
$IDX = parent::normalize($data, $mapped, false, false);
|
||||
{%- endif ~%}
|
||||
|
||||
{%- for f in o.fields ~%}
|
||||
|
@ -122,6 +123,9 @@ class {{o.name}} {{o.parent ? 'extends ' ~ o.parent.name}}
|
|||
throw new Exception($e->getMessage() . " < {$FIELDS[$IDX]} < ({{o.name}})");
|
||||
}
|
||||
|
||||
if($root && $check_junk)
|
||||
\metagen_php\check_junk_fields($data, self::CLASS_FIELDS());
|
||||
|
||||
return $IDX;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue