2023-05-26 12:00:22 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @global
|
|
|
|
*/
|
2023-05-30 16:34:59 +03:00
|
|
|
function macro_BHL_REF($proc, $module, $func, $signature_json = '')
|
2023-05-26 12:00:22 +03:00
|
|
|
{
|
2023-11-24 13:43:39 +03:00
|
|
|
//check if it's a relative path
|
|
|
|
if($module[0] == '.')
|
2023-06-30 16:07:52 +03:00
|
|
|
{
|
|
|
|
$abs_module = \taskman\normalize_path(dirname($proc->getRootFile()) . '/' . $module);
|
|
|
|
$mapped = false;
|
2023-11-24 13:43:39 +03:00
|
|
|
|
|
|
|
$bhl_proj = \taskman\bhl_proj();
|
|
|
|
$inc_path = isset($bhl_proj->inc_dirs) ? $bhl_proj->inc_dirs : $bhl_proj->src_dirs;
|
|
|
|
|
|
|
|
foreach($inc_path as $dir)
|
2023-06-30 16:07:52 +03:00
|
|
|
{
|
|
|
|
$rel_module = str_replace(\taskman\normalize_path($dir), '', $abs_module);
|
|
|
|
if($rel_module != $abs_module)
|
|
|
|
{
|
|
|
|
$mapped = true;
|
2023-07-06 13:06:37 +03:00
|
|
|
$rel_module = str_replace('\\', '/', $rel_module);
|
2023-06-30 16:07:52 +03:00
|
|
|
$module = "/" . $rel_module;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!$mapped)
|
|
|
|
throw new Exception("Could not map relative module: $module");
|
|
|
|
}
|
|
|
|
|
2023-06-27 14:36:34 +03:00
|
|
|
$module_file = \taskman\bhl_map_module_to_file($module);
|
|
|
|
if(!$module_file)
|
|
|
|
throw new Exception("Module not found '{$module}'");
|
2023-05-30 16:34:59 +03:00
|
|
|
|
2023-05-26 12:00:22 +03:00
|
|
|
//validate signature only if it's explicitely passed
|
|
|
|
if($signature_json)
|
|
|
|
{
|
|
|
|
$signature = json_decode($signature_json, false);
|
|
|
|
if(!is_array($signature))
|
2023-05-30 16:34:59 +03:00
|
|
|
throw new Exception("Signature is invalid '$module'");
|
|
|
|
\taskman\bhl_validate_func_ref($module_file, $func, $signature);
|
2023-05-26 12:00:22 +03:00
|
|
|
}
|
|
|
|
|
2023-05-30 16:34:59 +03:00
|
|
|
return array('module' => ltrim($module, '/'), 'fn' => $func);
|
2023-05-26 12:00:22 +03:00
|
|
|
}
|
|
|
|
|