mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 07:12:26 +02:00
move PhpParser/Evaluation classes in a specific namespave + composer dumpautoload
This commit is contained in:
41
sources/PhpParser/Evaluation/StaticCallEvaluator.php
Normal file
41
sources/PhpParser/Evaluation/StaticCallEvaluator.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\PhpParser\Evaluation;;
|
||||
|
||||
use ModuleFileReaderException;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use ReflectionFunction;
|
||||
|
||||
class StaticCallEvaluator implements iExprEvaluator {
|
||||
public function GetHandledExpressionType(): string {
|
||||
return StaticCall::class;
|
||||
}
|
||||
|
||||
public function Evaluate(Expr $oExpr): mixed {
|
||||
/** @var StaticCall $oExpr */
|
||||
|
||||
$sClassName = $oExpr->class->name;
|
||||
$sMethodName = $oExpr->name->name;
|
||||
|
||||
$aWhiteList = ["SetupInfo::ModuleIsSelected", "utils::GetItopVersionWikiSyntax"];
|
||||
$sStaticCallDescription = "$sClassName::$sMethodName";
|
||||
if (! in_array($sStaticCallDescription, $aWhiteList)){
|
||||
throw new ModuleFileReaderException("StaticCall $sStaticCallDescription not supported");
|
||||
}
|
||||
|
||||
$aArgs=[];
|
||||
foreach ($oExpr->args as $arg){
|
||||
/** @var \PhpParser\Node\Arg $arg */
|
||||
$aArgs[]=$arg->value->value;
|
||||
}
|
||||
|
||||
$class = new \ReflectionClass($sClassName);
|
||||
$method = $class->getMethod($sMethodName);
|
||||
if (! $method->isPublic()){
|
||||
throw new ModuleFileReaderException("StaticCall $sStaticCallDescription not public");
|
||||
}
|
||||
|
||||
return $method->invokeArgs(null, $aArgs);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user