From 712160bd660dd34ce6c8167f8fe66e203d589392 Mon Sep 17 00:00:00 2001 From: Alexander Prusov Date: Tue, 11 Jul 2023 19:16:49 +0300 Subject: [PATCH] Add apply_array_filters for apply filters for array --- src/codegen.inc.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/codegen.inc.php b/src/codegen.inc.php index b004f46..cc94aaa 100644 --- a/src/codegen.inc.php +++ b/src/codegen.inc.php @@ -103,12 +103,12 @@ function default_value($default) return str_replace('$', '\$', $default); } -function apply_value_filters($field_name, array $tokens, $val, $add_assoc_check = true) +function apply_filters($token_prefix, $field_name, array $tokens, $val, $add_assoc_check = true) { $str = $val; foreach($tokens as $token => $args_json) { - if(strpos($token, 'flt_') === false) + if(strpos($token, $token_prefix) === false) continue; $filter_func = '\metagen_php\\' . $token; @@ -136,6 +136,16 @@ function apply_value_filters($field_name, array $tokens, $val, $add_assoc_check return $str; } +function apply_array_filters($field_name, array $tokens, $val, $add_assoc_check = true) +{ + return apply_filters("arr_", $field_name, $tokens, $val, $add_assoc_check); +} + +function apply_value_filters($field_name, array $tokens, $val, $add_assoc_check = true) +{ + return apply_filters("flt_", $field_name, $tokens, $val, $add_assoc_check); +} + //TODO: move it to template function data2value($name, \mtgType $type, $buf, $prefix = '', $tokens = array(), $as_is = false, $postfix = '', $indent = '') { @@ -201,6 +211,7 @@ function data2value($name, \mtgType $type, $buf, $prefix = '', $tokens = array() else if($type instanceof \mtgArrType) { //TODO: maybe filters should be applied to the whole array as well? + $str .= $cond_indent."{$tmp_val} = " . apply_array_filters($name, $tokens, "{$tmp_val}"). ";\n"; $str .= $cond_indent."\$tmp_arr__ = \metagen_php\\val_arr({$tmp_val});\n"; $str .= $cond_indent."foreach(\$tmp_arr__ as \$tmp_arr_item__)\n"; $str .= $cond_indent."{\n";