48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @global
|
|
*/
|
|
function macro_BHL_REF($proc, $module, $func, $signature_json = '')
|
|
{
|
|
//check if it's a relative path
|
|
if($module[0] == '.')
|
|
{
|
|
$abs_module = \taskman\normalize_path(dirname($proc->getRootFile()) . '/' . $module);
|
|
$mapped = false;
|
|
|
|
$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)
|
|
{
|
|
$rel_module = str_replace(\taskman\normalize_path($dir), '', $abs_module);
|
|
if($rel_module != $abs_module)
|
|
{
|
|
$mapped = true;
|
|
$rel_module = str_replace('\\', '/', $rel_module);
|
|
$module = "/" . $rel_module;
|
|
break;
|
|
}
|
|
}
|
|
if(!$mapped)
|
|
throw new Exception("Could not map relative module: $module");
|
|
}
|
|
|
|
$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 '$module'");
|
|
\taskman\bhl_validate_func_ref($module_file, $func, $signature);
|
|
}
|
|
|
|
return array('module' => ltrim($module, '/'), 'fn' => $func);
|
|
}
|
|
|