mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-27 12:38:44 +02:00
35 lines
813 B
PHP
35 lines
813 B
PHP
<?php
|
|
|
|
namespace evaluation\expression;
|
|
|
|
use PhpParser\Node\Expr;
|
|
use PhpParser\Node\Expr\ClassConstFetch;
|
|
|
|
class ClassConstFetchEvaluator implements iExprEvaluator {
|
|
public function GetHandledExpressionType(): string {
|
|
return ClassConstFetch::class;
|
|
}
|
|
|
|
public function Evaluate(Expr $oExpr): mixed {
|
|
/** @var ClassConstFetch $oExpr */
|
|
|
|
$sClassName = $oExpr->class->name;
|
|
$sProperty = $oExpr->name->name;
|
|
|
|
if (class_exists($sClassName)){
|
|
$class = new \ReflectionClass($sClassName);
|
|
if (array_key_exists($sProperty, $class->getConstants())) {
|
|
$oReflectionConstant = $class->getReflectionConstant($sProperty);
|
|
if ($oReflectionConstant->isPublic()){
|
|
return $class->getConstant($sProperty);
|
|
}
|
|
}
|
|
}
|
|
|
|
if ('class' === $sProperty){
|
|
return $sClassName;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
} |