From d228b43d1e07ad934e93262d5d9ac8b9f2c6b12a Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Mon, 30 Sep 2024 20:27:31 +0300 Subject: [PATCH] Adding support for custom file extension --- parser.inc.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/parser.inc.php b/parser.inc.php index 417c832..102077b 100644 --- a/parser.inc.php +++ b/parser.inc.php @@ -100,18 +100,21 @@ function mtg_parse_meta(array $meta_srcs, $valid_tokens = null, $inc_path = null return $meta; } -function mtg_load_meta(mtgMetaInfo $meta, mtgIMetaInfoParser $meta_parser, string $dir_or_file) +function mtg_load_meta( + mtgMetaInfo $meta, mtgIMetaInfoParser $meta_parser, + string $dir_or_file, string $extension = '.meta' +) { - $files = mtg_resolve_files($dir_or_file); + $files = mtg_resolve_files($dir_or_file, $extension); foreach($files as $file) $meta_parser->parse($meta, $file); } -function mtg_resolve_files(string $dir_or_file) : array +function mtg_resolve_files(string $dir_or_file, string $extension = '.meta') : array { $files = array(); if(is_dir($dir_or_file)) - $files = mtg_find_meta_files($dir_or_file); + $files = mtg_find_meta_files($dir_or_file, $extension); else if(is_file($dir_or_file)) $files[] = $dir_or_file; else @@ -119,7 +122,7 @@ function mtg_resolve_files(string $dir_or_file) : array return $files; } -function mtg_find_meta_files($dir) +function mtg_find_meta_files($dir, $extension = '.meta') { $items = scandir($dir); if($items === false) @@ -131,7 +134,7 @@ function mtg_find_meta_files($dir) if($item[0] == '.') continue; - if(strpos($item, ".meta") !== (strlen($item)-5)) + if(strpos($item, $extension) !== (strlen($item)-strlen($extension))) continue; $file = $dir . '/' . $item;