diff --git a/bhl.inc.php b/bhl.inc.php index 36a1c23..d8de72a 100644 --- a/bhl.inc.php +++ b/bhl.inc.php @@ -214,18 +214,16 @@ function bhl_map_module_to_file($module) return null; } -function bhl_validate_func_ref($module, $func, array $signature) +function bhl_validate_func_ref($module_file, $func, array $signature) { if(sizeof($signature) == 0) throw new Exception("Signature is invalid"); - $module_file = bhl_map_module_to_file($module); - - if(!$module_file) - throw new Exception("Module not found '{$module}'"); - $module_src = file_get_contents($module_file); + if(!$module_src) + throw new Exception("Bad module file '{$module_file}'"); + $signature_pattern = ''; $signature_pattern .= '~func\s+'; if($signature[0] !== 'void') @@ -248,7 +246,7 @@ function bhl_validate_func_ref($module, $func, array $signature) $signature_pattern .= '~'; if(!preg_match($signature_pattern, $module_src)) - throw new Exception("Func '$func' signature '".implode(',', $signature)."' not found in module '$module'"); + throw new Exception("Func '$func' signature '".implode(',', $signature)."' not found in module '$module_file'"); } function bhl_upm_path() diff --git a/bhl_flt.inc.php b/bhl_flt.inc.php index c43f8fd..3b73d4a 100644 --- a/bhl_flt.inc.php +++ b/bhl_flt.inc.php @@ -10,6 +10,10 @@ function flt_bhl_ref($val, $name, $struct, $args) if(!isset($val['module'])) throw new Exception("Missing 'module'"); + $module_file = \taskman\bhl_map_module_to_file($val['module']); + if(!$module_file) + throw new Exception("Module not found '{$val['module']}"); + if(!isset($val['fn'])) throw new Exception("Missing 'fn'"); @@ -17,7 +21,7 @@ function flt_bhl_ref($val, $name, $struct, $args) if(!$signature) throw new Exception("Invalid signature: $args"); - \taskman\bhl_validate_func_ref($val['module'], $val['fn'], $signature); + \taskman\bhl_validate_func_ref($module_file, $val['fn'], $signature); return $val; } diff --git a/bhl_macro.inc.php b/bhl_macro.inc.php index 9eb5f18..3e8e7ef 100644 --- a/bhl_macro.inc.php +++ b/bhl_macro.inc.php @@ -3,17 +3,31 @@ /** * @global */ -function macro_BHL_REF($proc, $mod_name, $func, $signature_json = '') +function macro_BHL_REF($proc, $module, $func, $signature_json = '') { + //let's try the .local override first + $module_file = \taskman\bhl_map_module_to_file($module.".local"); + if($module_file) + { + $module .= '.local'; + $func .= '_Local'; + } + else + { + $module_file = \taskman\bhl_map_module_to_file($module); + if(!$module_file) + throw new Exception("Module not found '{$module}'"); + } + //validate signature only if it's explicitely passed if($signature_json) { $signature = json_decode($signature_json, false); if(!is_array($signature)) - throw new Exception("Signature is invalid '$mod_name'"); - \taskman\bhl_validate_func_ref($mod_name, $func, $signature); + throw new Exception("Signature is invalid '$module'"); + \taskman\bhl_validate_func_ref($module_file, $func, $signature); } - return array('module' => ltrim($mod_name, '/'), 'fn' => $func); + return array('module' => ltrim($module, '/'), 'fn' => $func); }