mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 07:12:26 +02:00
fix few Evaluators code
This commit is contained in:
@@ -4,44 +4,38 @@ namespace Combodo\iTop\PhpParser\Evaluation;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Identifier;
|
||||
use ReflectionClass;
|
||||
|
||||
class PropertyFetchEvaluator extends AbstractExprEvaluator {
|
||||
public function GetHandledExpressionType(): ?string {
|
||||
return PropertyFetch::class;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function GetHandledExpressionTypes(): ?array {
|
||||
return [PropertyFetch::class, Expr\NullsafePropertyFetch::class];
|
||||
}
|
||||
|
||||
public function Evaluate(Expr $oExpr): mixed {
|
||||
/** @var PropertyFetch $oExpr */
|
||||
|
||||
$oVar = PhpExpressionEvaluator::GetInstance()->EvaluateExpression($oExpr->var);
|
||||
if (is_null($oVar)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$sName = PhpExpressionEvaluator::GetInstance()->EvaluateExpression($oExpr->name);
|
||||
$oReflectionClass = new ReflectionClass(get_class($oVar));
|
||||
if ($oExpr->name instanceof Identifier){
|
||||
$sName = $oExpr->name->name;
|
||||
} else {
|
||||
$sName = PhpExpressionEvaluator::GetInstance()->EvaluateExpression($oExpr->name);
|
||||
}
|
||||
|
||||
$oProperties = $oReflectionClass->getProperties();
|
||||
if (array_key_exists($sName, $oProperties)){
|
||||
$oProperty = $oProperties[$sName];
|
||||
$oReflectionClass = new ReflectionClass(get_class($oVar));
|
||||
try{
|
||||
$oProperty = $oReflectionClass->getProperty($sName);
|
||||
if ($oProperty->isPublic()){
|
||||
return $oProperty->getValue($oVar);
|
||||
}
|
||||
} catch (\ReflectionException $t) {}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$aArgs=[];
|
||||
|
||||
$oMethods = $oReflectionClass->getMethods();
|
||||
if (array_key_exists($sName, $oMethods)){
|
||||
$oMethod = $oMethods[$sName];
|
||||
if ($oMethod->isPublic()){
|
||||
return $oMethod->invokeArgs(null, $aArgs);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user