Improving BHL_REF validation by better splitting code by namespaces
Publish PHP Package / docker (push) Successful in 6s
Details
Publish PHP Package / docker (push) Successful in 6s
Details
This commit is contained in:
parent
82ad2216da
commit
22ec477ddf
34
bhl.inc.php
34
bhl.inc.php
|
@ -267,24 +267,25 @@ function bhl_validate_func_ref(string $module_file, string $func_full_name, arra
|
||||||
if(!$module_src)
|
if(!$module_src)
|
||||||
throw new Exception("Bad module file '{$module_file}'");
|
throw new Exception("Bad module file '{$module_file}'");
|
||||||
|
|
||||||
|
$ns_chunks = _bhl_split_by_namespaces($module_src);
|
||||||
|
|
||||||
$module_chunks = array();
|
$module_chunks = array();
|
||||||
if($namespace)
|
if($namespace)
|
||||||
{
|
{
|
||||||
$ns_chunks = _bhl_split_by_namespaces($module_src);
|
if(!isset($ns_chunks[$namespace]))
|
||||||
if(count($ns_chunks) == 0)
|
throw new Exception("No namespace '$namespace' found in '$module_file'");
|
||||||
throw new Exception("No namespaces found in '$module_file'");
|
|
||||||
|
|
||||||
foreach($ns_chunks as $ns => $ns_src)
|
foreach($ns_chunks[$namespace] as $ns_src)
|
||||||
{
|
$module_chunks[] = $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'");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$module_chunks[] = $module_src;
|
{
|
||||||
|
if(!isset($ns_chunks['']))
|
||||||
|
throw new Exception("No global namespace found in '$module_file'");
|
||||||
|
|
||||||
|
foreach($ns_chunks[''] as $ns_src)
|
||||||
|
$module_chunks[] = $ns_src;
|
||||||
|
}
|
||||||
|
|
||||||
$signature_pattern = '';
|
$signature_pattern = '';
|
||||||
$signature_pattern .= '~func\s+';
|
$signature_pattern .= '~func\s+';
|
||||||
|
@ -346,11 +347,18 @@ function _bhl_split_by_namespaces(string $src) : array
|
||||||
{
|
{
|
||||||
$ns = trim(substr(ltrim($chunk), 9));
|
$ns = trim(substr(ltrim($chunk), 9));
|
||||||
$body = $chunks[$i+1];
|
$body = $chunks[$i+1];
|
||||||
$nss[$ns] = $body;
|
if(!isset($nss[$ns]))
|
||||||
|
$nss[$ns] = array();
|
||||||
|
$nss[$ns][] = $body;
|
||||||
$i+=2;
|
$i+=2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if(!isset($nss['']))
|
||||||
|
$nss[''] = array();
|
||||||
|
$nss[''][] = $chunk;
|
||||||
++$i;
|
++$i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $nss;
|
return $nss;
|
||||||
|
|
Loading…
Reference in New Issue