N°9618 - Be able to write comment in MyModuleSettings

N°9618 - Be able to write comment in MyModuleSettings
This commit is contained in:
odain
2026-05-19 23:56:21 +02:00
parent b29a3b5df8
commit 2ecd2d7a96
5 changed files with 152 additions and 4 deletions

View File

@@ -4,9 +4,11 @@ namespace Combodo\iTop\PhpParser\Evaluation;
use Combodo\iTop\Setup\ModuleDiscovery\ModuleFileParser;
use Combodo\iTop\Setup\ModuleDiscovery\ModuleFileReaderException;
use PhpParser\Comment;
use PhpParser\ConstExprEvaluator;
use PhpParser\ExprEvaluator;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\ParserFactory;
/**
@@ -55,4 +57,31 @@ PHP;
throw new ModuleFileReaderException("Eval of '$sExpr' caused an error:".$t->getMessage());
}
}
public function GetArrayWithComments(Array_ $oArray): array
{
$aRes = [];
$i=0;
foreach ($oArray->items as $oItem) {
/** @var \PhpParser\Node\ArrayItem $oItem **/
if(is_null($oItem->key)){
$sKey = $i;
$i++;
} else {
$sKey = $this->EvaluateExpression($oItem->key);
}
foreach ($oItem->getComments() as $oComment) {
/** @var \PhpParser\Comment $oComment */
$aRes[] = 'StartPhpParserComment'.$oComment->getText().'EndPhpParserComment';
}
if ($oItem->value instanceof Array_) {
$aRes[$sKey] = $this->GetArrayWithComments($oItem->value);
} elseif ($oItem->value instanceof Comment) {
$aRes[$sKey] = $oItem->value;
} else {
$aRes[$sKey] = $this->EvaluateExpression($oItem->value);
}
}
return $aRes;
}
}