Files
iTop/core/metamodel/IncludeFileReader.php
odain 02ea17d897 N°8760 - add GetCreatedIn to get module name based on DBObject class - everything stored in MetaModel during compilation and autoload
N°8760 - be able to describe from which module a datamodel class comes via MetaModel created_in field
2026-01-28 15:06:04 +01:00

53 lines
1.2 KiB
PHP

<?php
use PhpParser\Error;
use PhpParser\ParserFactory;
class IncludeFileReader
{
private static IncludeFileReader $oInstance;
protected function __construct()
{
}
final public static function GetInstance(): IncludeFileReader
{
if (!isset(IncludeFileReader::$oInstance)) {
IncludeFileReader::$oInstance = new IncludeFileReader();
}
return self::$oInstance;
}
final public static function SetInstance(?IncludeFileReader $oInstance): void
{
IncludeFileReader::$oInstance = $oInstance;
}
public function GetClasses($sPath): array
{
try {
$oParser = (new ParserFactory())->createForNewestSupportedVersion();
$aNodes = $oParser->parse(file_get_contents($sPath));
} catch (Error $e) {
throw new Exception("PHP Class Parsing of $sPath caused an exception: ".$e->getMessage(), 0, $e);
}
$aRes = [];
try {
foreach ($aNodes as $sKey => $oNode) {
if ($oNode instanceof PhpParser\Node\Stmt\Class_) {
/** @var PhpParser\Node\Stmt\Class_ $oNode */
//var_dump($oNode->name);
$aRes[] = $oNode->name->name;
}
}
return $aRes;
} catch (Exception $e) {
throw new Exception("PHP Class Discovery of $sPath caused an exception: ".$e->getMessage(), 0, $e);
}
}
}