Browse Source

Cleaner handling of "pure PHP" classes inside the data model

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2225 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 12 years ago
parent
commit
2e62fe34c5
2 changed files with 31 additions and 29 deletions
  1. 26 2
      setup/compiler.class.inc.php
  2. 5 27
      setup/modelfactory.class.inc.php

+ 26 - 2
setup/compiler.class.inc.php

@@ -120,7 +120,7 @@ class MFCompiler
 					{
 						$sCompiledCode .= $this->CompileClass($oClass, $sRelativeDir, $oP);
 					}
-					catch (ssDOMFormatException $e)
+					catch (DOMFormatException $e)
 					{
 						throw new Exception("Failed to process class '$sClass', from '$sModuleRootDir': ".$e->getMessage());
 					}
@@ -835,6 +835,30 @@ EOF;
 		// Let's make the whole class declaration
 		//
 		$sPHP = "\n\n$sCodeComment\n";
+		$sParentClass = $oClass->GetChildText('php_parent');
+		$oPhpParent = $oClass->GetUniqueElement('php_parent', false);
+		if ($oPhpParent)
+		{
+			$sParentClass = $oPhpParent->GetChildText('name', '');
+			if ($sParentClass == '')
+			{
+				throw new Exception("Failed to process class '".$oClass->getAttribute('id')."', from '$sRelativeDir':  missing required tag 'name' under 'php_parent'.");
+			}
+			$sIncludeFile = $oPhpParent->GetChildText('file', '');
+			if ($sIncludeFile != '')
+			{
+				$sPHP .= "\nrequire_once('$sIncludeFile'); // Implementation of the class $sParentClass\n";
+			}
+			$sFullPath =  $this->sSourceDir.'/'.$sModuleRelativeDir.'/'.$sIncludeFile;
+			if (!file_exists($sFullPath))
+			{
+				throw new Exception("Failed to process class '".$oClass->getAttribute('id')."', from '$sModuleRelativeDir'. The required include file: '$sFullPath' does not exist.");
+			}
+		}
+		else
+		{
+			$sParentClass = $oClass->GetChildText('parent', 'DBObject');
+		}
 		if ($oProperties->GetChildText('abstract') == 'true')
 		{
 			$sPHP .= 'abstract class '.$oClass->getAttribute('id');
@@ -843,7 +867,7 @@ EOF;
 		{
 			$sPHP .= 'class '.$oClass->getAttribute('id');
 		}
-		$sPHP .= " extends ".$oClass->GetChildText('parent', 'DBObject')."\n";
+		$sPHP .= " extends $sParentClass\n";
 		$sPHP .=
 <<<EOF
 {

+ 5 - 27
setup/modelfactory.class.inc.php

@@ -198,19 +198,9 @@ class ModelFactory
 	
 				if (!$oTargetParentNode)
 				{
-					if (substr($sParentId, 0, 1) == '/') // Convention for well known classes
-					{
-						$oTargetParentNode = $this->AddWellKnownParent(substr($sParentId, 1));
-						// Remove the leading slash character
-						$oParentNameNode = $oSourceNode->GetOptionalElement('parent')->firstChild; // Get the DOMCharacterData node
-						$oParentNameNode->data = substr($sParentId, 1);
-					}
-					else
-					{
-						echo "Dumping target doc - looking for '$sPath'<br/>\n";
-						$this->oDOMDocument->firstChild->Dump();
-						throw new Exception("XML datamodel loader: could not find parent node for $oSourceNode->tagName / ".$oSourceNode->getAttribute('id')." with parent id $sParentId");
-					}
+					echo "Dumping target doc - looking for '$sParentId'<br/>\n";
+					$this->oDOMDocument->firstChild->Dump();
+					throw new Exception("XML datamodel loader: could not find parent node for $oSourceNode->tagName / ".$oSourceNode->getAttribute('id')." with parent id $sParentId");
 				}
 			}
 			else 
@@ -218,7 +208,7 @@ class ModelFactory
 				$oTargetNode = $oTarget->GetNodeById('/itop_design/classes//class', $oSourceNode->getAttribute('id'))->item(0);
 				if (!$oTargetNode)
 				{
-					echo "Dumping target doc - looking for '$sPath'<br/>\n";
+					echo "Dumping target doc - looking for '".$oSourceNode->getAttribute('id')."'<br/>\n";
 					$this->oDOMDocument->firstChild->Dump();
 					throw new Exception("XML datamodel loader: could not find node for $oSourceNode->tagName/".$oSourceNode->getAttribute('id'));
 				}
@@ -614,19 +604,7 @@ EOF
 	public function GetClass($sClassName, $bFlattenLayers = true)
 	{
 		$oClassNode = $this->GetNodes("/itop_design/classes//class[@id='$sClassName']")->item(0);
-		if ($oClassNode == null)
-		{
-			if (substr($sClassName, 0, 1) == '/') // Convention: this class is a "well known" parent
-			{
-				return $this->AddWellKnownParent(substr($sClassName, 1));
-			}
-			else
-			{
-				return null;
-			}
-			
-		}
-		elseif ($bFlattenLayers)
+		if (($oClassNode != null) && ($bFlattenLayers))
 		{
 			$sOperation = $oClassNode->getAttribute('_alteration');
 			if ($sOperation == 'removed')