mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-28 21:18:46 +02:00
OQLToCLassConverter class conversion
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user