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');