Compiler: added "constants"

SVN:trunk[2955]
This commit is contained in:
Romain Quetiez
2013-10-24 09:49:56 +00:00
parent 54769aa2d1
commit f684cb1745
8 changed files with 140 additions and 125 deletions

View File

@@ -153,6 +153,15 @@ class MFCompiler
$sCompiledCode = '';
$oConstants = $this->oFactory->ListConstants($sModuleName);
if ($oConstants->length > 0)
{
foreach($oConstants as $oConstant)
{
$sCompiledCode .= $this->CompileConstant($oConstant)."\n";
}
}
$oClasses = $this->oFactory->ListClasses($sModuleName);
$iClassCount = $oClasses->length;
if ($iClassCount == 0)
@@ -546,6 +555,58 @@ EOF;
return $sRet;
}
protected function CompileConstant($oConstant)
{
$sName = $oConstant->getAttribute('id');
$sType = $oConstant->getAttribute('xsi:type');
$sText = $oConstant->GetText(null);
switch ($sType)
{
case 'integer':
if (is_null($sText))
{
// No data given => null
$sScalar = 'null';
}
else
{
$sScalar = (string)(int)$sText;
}
break;
case 'float':
if (is_null($sText))
{
// No data given => null
$sScalar = 'null';
}
else
{
$sScalar = (string)(float)$sText;
}
break;
case 'bool':
if (is_null($sText))
{
// No data given => null
$sScalar = 'null';
}
else
{
$sScalar = ($sText == 'true') ? 'true' : 'false';
}
break;
case 'string':
default:
$sScalar = $this->QuoteForPHP($sText, true);
}
$sPHPDefine = "define('$sName', $sScalar);";
return $sPHPDefine;
}
protected function CompileClass($oClass, $sTempTargetDir, $sFinalTargetDir, $sModuleRelativeDir, $oP)
{
$sClass = $oClass->getAttribute('id');

View File

@@ -1,5 +1,5 @@
<?php
// Copyright (C) 2010-2012 Combodo SARL
// Copyright (C) 2010-2013 Combodo SARL
//
// This file is part of iTop.
//
@@ -400,6 +400,14 @@ class ModelFactory
$oNode->SetAttribute('_created_in', $sModuleName);
}
}
$oNodeList = $oXPath->query('/itop_design/constants/constant');
foreach($oNodeList as $oNode)
{
if ($oNode->getAttribute('_created_in') == '')
{
$oNode->SetAttribute('_created_in', $sModuleName);
}
}
$oNodeList = $oXPath->query('/itop_design/menus/menu');
foreach($oNodeList as $oNode)
{
@@ -752,9 +760,26 @@ $sHeader
EOF
;
}
/**
* List all constants from the DOM, for a given module
* @param string $sModuleName
* @param bool $bFlattenLayers
* @throws Exception
*/
public function ListConstants($sModuleName, $bFlattenLayers = true)
{
$sXPath = "/itop_design/constants/constant[@_created_in='$sModuleName']";
if ($bFlattenLayers)
{
$sXPath = "/itop_design/constants/constant[@_created_in='$sModuleName' and (not(@_alteration) or @_alteration!='removed')]";
}
return $this->GetNodes($sXPath);
}
/**
* List all classes from the DOM, for a given module
* @param string $sModuleNale
* @param string $sModuleName
* @param bool $bFlattenLayers
* @throws Exception
*/
@@ -1503,7 +1528,7 @@ class MFElement extends DOMElement
}
/**
* For debugging purposes - but this is currently buggy: the whole document is rendered
* For debugging purposes
*/
public function Dump($bReturnRes = false)
{