N°4756 - Ease extensibility for CRUD operations : Event Service - move event description to an object

This commit is contained in:
Eric Espie
2022-12-13 11:55:05 +01:00
parent 432579657c
commit deb6d1fd9a
7 changed files with 312 additions and 18 deletions

View File

@@ -1097,11 +1097,65 @@ EOF
$sName = $oEvent->getAttribute('id');
$aEventDescription = DesignElement::ToArray($oEvent);
$sDescription = var_export($aEventDescription, true);
// array (
// 'description' => 'An object insert in the database has been requested. All changes to the object will be persisted automatically.',
// 'sources' =>
// array (
// 'cmdbAbstractObject' => 'cmdbAbstractObject',
// ),
// 'replaces' => 'DBObject::OnInsert',
// 'event_data' =>
// array (
// 'object' =>
// array (
// 'description' => 'The object inserted',
// 'type' => 'DBObject',
// ),
// 'debug_info' =>
// array (
// 'description' => 'Debug string',
// 'type' => 'string',
// ),
// ),
// )
$sConstant = $sName;
$sOutput = "const $sConstant = '$sName';\n";
$sOutput .= "Combodo\iTop\Service\EventService::RegisterEvent($sName, $sDescription, '$sModuleName');\n";
$sOutput .= "\Combodo\iTop\Service\EventService::RegisterEvent(\n";
$sOutput .= " new \Combodo\iTop\Service\Description\EventDescription(\n";
//$sEventName
$sOutput .= " '$sName',\n";
//$mEventSources
$sOutput .= " [\n";
foreach ($aEventDescription['sources'] as $sSourceId => $sSourceName) {
$sOutput .= " '$sSourceId' => '$sSourceName',\n";
}
$sOutput .= " ],\n";
// $sDescription
$sOutput .= " '{$aEventDescription['description']}',\n";
// $sReplaces
if (isset($aEventDescription['replaces'])) {
$sOutput .= " '{$aEventDescription['replaces']}',\n";
} else {
$sOutput .= " '',\n";
}
// $aEventDataDescription
$sOutput .= " [\n";
foreach ($aEventDescription['event_data'] as $sEventDataName => $aEventDataDescription) {
$sEventDataDesc = $aEventDataDescription['description'];
$sEventDataType = $aEventDataDescription['type'];
$sOutput .= " new \Combodo\iTop\Service\Description\EventDataDescription(\n";
$sOutput .= " '$sEventDataName',\n";
$sOutput .= " '$sEventDataDesc',\n";
$sOutput .= " '$sEventDataType',\n";
$sOutput .= " ),\n";
}
$sOutput .= " ],\n";
// $sModule
$sOutput .= " '$sModuleName'\n";
$sOutput .= " )\n";
$sOutput .= ");\n";
return $sOutput;
}