complete Evaluators list + autoload

This commit is contained in:
odain
2025-09-03 16:48:40 +02:00
parent 794a9afe3e
commit c14ac90a13
42 changed files with 522 additions and 80 deletions

View File

@@ -0,0 +1,47 @@
<?php
namespace Combodo\iTop\PhpParser\Evaluation;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\PropertyFetch;
use ReflectionClass;
class PropertyFetchEvaluator extends AbstractExprEvaluator {
public function GetHandledExpressionType(): ?string {
return PropertyFetch::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));
$oProperties = $oReflectionClass->getProperties();
if (array_key_exists($sName, $oProperties)){
$oProperty = $oProperties[$sName];
if ($oProperty->isPublic()){
return $oProperty->getValue($oVar);
}
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;
}
}
}