commit 37f6de1a1a58be63fd71a6179b35908dd4d5651c Author: Pavel Shevaev Date: Fri May 26 17:50:05 2023 +0300 Initial commit diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..5d1715e --- /dev/null +++ b/composer.json @@ -0,0 +1,11 @@ +{ + "name": "bit/meta_filters", + "description": "Collection of shared meta filters", + "homepage": "https://git.bit5.ru/composer/meta_filters", + "require": { + "php": ">=7.4" + }, + "autoload": { + "files": ["filters.inc.php"] + } +} diff --git a/filters.inc.php b/filters.inc.php new file mode 100644 index 0000000..87e580b --- /dev/null +++ b/filters.inc.php @@ -0,0 +1,104 @@ + $args[1]) + throw new Exception("Value ".$val.", not in range(" . $args[0] . "," . $args[1] . ")"); + } + + return $val; +} + +function flt_time($val, $name, $struct, $args) +{ + $str = ""; + if(is_string($val)) + { + if(strlen($val) === 0) + throw new Exception("Bad value, string empty, crc28 can't be generated"); + + $reg = "/^([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})$/"; + + if(!preg_match($reg, $val, $matches)) + throw new Exception("Bad value, pattern 00:00:00"); + + $h = $matches[1]; + $m = $matches[2]; + $s = $matches[3]; + + return $h * 3600 + $m * 60 + $s; + } + + return 0; +} + +function flt_class($val, $name, $struct, $args) +{ + global $GAME_ROOT; + + if(is_string($val)) + { + if(strpos($val, '@') === 0) + $val = substr($val, 1) . '.conf.js'; + + $conf_path = \taskman\config_real_path($val); + + $lines = file($conf_path); + foreach($lines as $line) + { + if(preg_match('~"?class"?\s*:\s*"([^"]+)"~', $line, $matches)) + { + $conf_class = $matches[1]; + if($conf_class != $args[0] && !is_subclass_of($conf_class, $args[0])) + throw new Exception($val.". Config class is \"".$conf_class."\". Must be \"".$args[0]."\" or it's child"); + else + return $val; + } + } + + throw new Exception($val.". Config class is not found in '$conf_path'"); + } + + return $val; +}