A bit improving function signature validation heuristics
Publish PHP Package / docker (push) Successful in 7s
Details
Publish PHP Package / docker (push) Successful in 7s
Details
This commit is contained in:
parent
7e3927cb72
commit
20b3d26ece
37
bhl.inc.php
37
bhl.inc.php
|
@ -284,10 +284,18 @@ function bhl_validate_func_ref(string $module_file, string $func_full_name, arra
|
||||||
$module_chunks = array();
|
$module_chunks = array();
|
||||||
if($namespace)
|
if($namespace)
|
||||||
{
|
{
|
||||||
$module_chunks = preg_split('~namespace\s+'.preg_quote($namespace).'\s*{~', $module_src);
|
$ns_chunks = _bhl_split_by_namespaces($module_src);
|
||||||
if(count($module_chunks) < 2)
|
if(count($ns_chunks) == 0)
|
||||||
|
throw new Exception("No namespaces found in '$module_file'");
|
||||||
|
|
||||||
|
foreach($ns_chunks as $ns => $ns_src)
|
||||||
|
{
|
||||||
|
if($ns === $namespace)
|
||||||
|
$module_chunks[] = $ns_src;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count($module_chunks) == 0)
|
||||||
throw new Exception("Namespace '$namespace' for func '$func_full_name' not found in '$module_file'");
|
throw new Exception("Namespace '$namespace' for func '$func_full_name' not found in '$module_file'");
|
||||||
$module_chunks = array_filter($module_chunks, function($item) { return strlen($item) > 0;});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$module_chunks[] = $module_src;
|
$module_chunks[] = $module_src;
|
||||||
|
@ -322,6 +330,29 @@ function bhl_validate_func_ref(string $module_file, string $func_full_name, arra
|
||||||
throw new Exception("Func '$func_full_name(".implode(',', $signature).")' not found in '$module_file'");
|
throw new Exception("Func '$func_full_name(".implode(',', $signature).")' not found in '$module_file'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _bhl_split_by_namespaces(string $src) : array
|
||||||
|
{
|
||||||
|
$nss = array();
|
||||||
|
|
||||||
|
$chunks = preg_split('~^\s*(namespace\s+[^\{]+){~m', $src, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
||||||
|
|
||||||
|
for($i=0;$i<count($chunks);)
|
||||||
|
{
|
||||||
|
$chunk = $chunks[$i];
|
||||||
|
if(strpos(ltrim($chunk), 'namespace ') === 0)
|
||||||
|
{
|
||||||
|
$ns = trim(substr(ltrim($chunk), 9));
|
||||||
|
$body = $chunks[$i+1];
|
||||||
|
$nss[$ns] = $body;
|
||||||
|
$i+=2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
++$i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $nss;
|
||||||
|
}
|
||||||
|
|
||||||
function bhl_upm_path() : string
|
function bhl_upm_path() : string
|
||||||
{
|
{
|
||||||
global $GAME_ROOT;
|
global $GAME_ROOT;
|
||||||
|
|
Loading…
Reference in New Issue