mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-01 14:38:47 +02:00
33 lines
841 B
PHP
33 lines
841 B
PHP
<?php
|
|
|
|
namespace evaluation\expression;
|
|
|
|
use ModuleFileReaderException;
|
|
use PhpParser\Node\Expr;
|
|
use PhpParser\Node\Expr\FuncCall;
|
|
use ReflectionFunction;
|
|
|
|
class FuncCallEvaluator implements iExprEvaluator {
|
|
public function GetHandledExpressionType(): string {
|
|
return FuncCall::class;
|
|
}
|
|
|
|
public function Evaluate(Expr $oExpr): mixed {
|
|
/** @var FuncCall $oExpr */
|
|
|
|
$sFunction = $oExpr->name->name;
|
|
$aWhiteList = ["function_exists", "class_exists", "method_exists"];
|
|
if (! in_array($sFunction, $aWhiteList)){
|
|
throw new ModuleFileReaderException("FuncCall $sFunction not supported");
|
|
}
|
|
|
|
$aArgs=[];
|
|
foreach ($oExpr->args as $arg){
|
|
/** @var \PhpParser\Node\Arg $arg */
|
|
$aArgs[]=$arg->value->value;
|
|
}
|
|
|
|
$oReflectionFunction = new ReflectionFunction($sFunction);
|
|
return $oReflectionFunction->invoke(...$aArgs);
|
|
}
|
|
} |