mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°8760 - be able to describe from which module a datamodel class comes via MetaModel created_in field
53 lines
1.2 KiB
PHP
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);
|
|
}
|
|
}
|
|
}
|