OQLToCLassConverter class conversion

This commit is contained in:
Benjamin Dalsass
2025-11-24 13:50:51 +01:00
parent a19472cfd1
commit dd4eb9b9f0

View File

@@ -7,6 +7,7 @@
namespace Combodo\iTop\Forms\IO\Converter;
use Combodo\iTop\Service\DependencyInjection\DIException;
use Combodo\iTop\Service\DependencyInjection\DIService;
use Combodo\iTop\Forms\IO\Format\ClassIOFormat;
use Combodo\iTop\Forms\IO\FormBlockIOException;
@@ -17,8 +18,8 @@ use Combodo\iTop\Forms\IO\FormBlockIOException;
class OqlToClassConverter extends AbstractConverter
{
/** @inheritdoc
* @throws \Combodo\iTop\Forms\IO\FormBlockIOException
* @throws \Combodo\iTop\Service\DependencyInjection\DIException
* @throws DIException
* @throws FormBlockIOException
*/
public function Convert(mixed $oData): ?ClassIOFormat
{
@@ -26,22 +27,8 @@ class OqlToClassConverter extends AbstractConverter
return null;
}
// Extract OQL information
preg_match('/SELECT\s+(\w+)/', $oData, $aMatches);
// Selected class
if (isset($aMatches[1])) {
$sSelectedClass = $aMatches[1];
/** @var \ModelReflection $oModelReflection */
$oModelReflection = DIService::GetInstance()->GetService('ModelReflection');
if (!$oModelReflection->IsValidClass($sSelectedClass)) {
throw new FormBlockIOException('Class '.json_encode($sSelectedClass).' not found');
}
return new ClassIOFormat($aMatches[1]);
} else {
throw new FormBlockIOException('Incorrect OQL sentence '.json_encode($oData));
}
$oModelReflection = DIService::GetInstance()->GetService('ModelReflection');
$oQuery = $oModelReflection->GetQuery($oData);
return new ClassIOFormat($oQuery->GetClass());
}
}