From e8879a0455a72edbc2e7356a96ce278652b0c15f Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Mon, 18 Nov 2019 15:29:03 +0100 Subject: [PATCH] :art: Code formatting --- setup/modelfactory.class.inc.php | 651 +++++++++++++++++-------------- setup/wizardsteps.class.inc.php | 8 +- 2 files changed, 370 insertions(+), 289 deletions(-) diff --git a/setup/modelfactory.class.inc.php b/setup/modelfactory.class.inc.php index cea96dff8..fcc52b65b 100644 --- a/setup/modelfactory.class.inc.php +++ b/setup/modelfactory.class.inc.php @@ -67,16 +67,17 @@ class MFException extends Exception * @param string $sExtraInfo * @param null $previous */ - public function __construct ($message = null, $code = null, $iSourceLineNumber = 0, $sXPath = '', $sExtraInfo = '', $previous = null) + public function __construct($message = null, $code = null, $iSourceLineNumber = 0, $sXPath = '', $sExtraInfo = '', $previous = null) { parent::__construct($message, $code, $previous); $this->iSourceLineNumber = $iSourceLineNumber; $this->sXPath = $sXPath; $this->sExtraInfo = $sExtraInfo; } - + /** * Get the source line number where the problem happened + * * @return number */ public function GetSourceLineNumber() @@ -86,15 +87,17 @@ class MFException extends Exception /** * Get the XPath in the whole document where the problem happened + * * @return string */ public function GetXPath() { return $this->sXPath; } - + /** * Get some extra info (depending on the exception's code), like the invalid value for the _delta attribute + * * @return string */ public function GetExtraInfo() @@ -103,8 +106,9 @@ class MFException extends Exception } } - /** +/** * ModelFactoryModule: the representation of a Module (i.e. element that can be selected during the setup) + * * @package ModelFactory */ class MFModule @@ -156,8 +160,8 @@ class MFModule */ public function __construct($sId, $sRootDir, $sLabel, $bAutoSelect = false) { - $this->sId = $sId; - + $this->sId = $sId; + list($this->sName, $this->sVersion) = ModuleDiscovery::GetModuleName($sId); if (strlen($this->sVersion) == 0) { @@ -170,7 +174,7 @@ class MFModule $this->bAutoSelect = $bAutoSelect; $this->sAutoSelect = 'false'; $this->aFilesToInclude = array('addons' => array(), 'business' => array(), 'webservices' => array(),); - + // Scan the module's root directory to find the datamodel(*).xml files if ($hDir = opendir($sRootDir)) { @@ -242,7 +246,7 @@ class MFModule { return $this->aDataModels; } - + /** * List all classes in this module */ @@ -262,14 +266,16 @@ class MFModule while (($sFile = readdir($hDir)) !== false) { $aMatches = array(); - if (preg_match("/^[^\\.]+.dict.".$this->sName.".php$/i", $sFile, $aMatches)) // Dictionary files are named like .dict..php + if (preg_match("/^[^\\.]+.dict.".$this->sName.".php$/i", $sFile, + $aMatches)) // Dictionary files are named like .dict..php { $aDictionaries[] = $this->sRootDir.'/'.$sFile; } } closedir($hDir); } - return $aDictionaries; + + return $aDictionaries; } /** @@ -315,11 +321,12 @@ class MFModule { return $this->aFilesToInclude[$sCategory]; } - + } - /** +/** * MFDeltaModule: an optional module, made of a single file + * * @package ModelFactory */ class MFDeltaModule extends MFModule @@ -373,6 +380,7 @@ class MFDeltaModule extends MFModule /** * MFDeltaModule: an optional module, made of a single file + * * @package ModelFactory */ class MFCoreModule extends MFModule @@ -420,6 +428,7 @@ class MFCoreModule extends MFModule /** * MFDictModule: an optional module, consisting only of dictionaries + * * @package ModelFactory */ class MFDictModule extends MFModule @@ -467,20 +476,23 @@ class MFDictModule extends MFModule while (($sFile = readdir($hDir)) !== false) { $aMatches = array(); - if (preg_match("/^.*dictionary\\.itop.*.php$/i", $sFile, $aMatches)) // Dictionary files are named like .dict..php + if (preg_match("/^.*dictionary\\.itop.*.php$/i", $sFile, + $aMatches)) // Dictionary files are named like .dict..php { $aDictionaries[] = $this->sRootDir.'/'.$sFile; } } closedir($hDir); } + return $aDictionaries; - } + } } /** * ModelFactory: the class that manages the in-memory representation of the XML MetaModel + * * @package ModelFactory */ class ModelFactory @@ -494,7 +506,7 @@ class ModelFactory protected $oMeta; protected $oDictionaries; static protected $aLoadedClasses; - static protected $aWellKnownParents = array('DBObject', 'CMDBObject','cmdbAbstractObject'); + static protected $aWellKnownParents = array('DBObject', 'CMDBObject', 'cmdbAbstractObject'); static protected $aLoadedModules; static protected $aLoadErrors; protected $aDict; @@ -525,18 +537,18 @@ class ModelFactory $this->oRoot->AppendChild($this->oClasses); $this->oDictionaries = $this->oDOMDocument->CreateElement('dictionaries'); $this->oRoot->AppendChild($this->oDictionaries); - + foreach (self::$aWellKnownParents as $sWellKnownParent) { $this->AddWellKnownParent($sWellKnownParent); } $this->oMenus = $this->oDOMDocument->CreateElement('menus'); $this->oRoot->AppendChild($this->oMenus); - + $this->oMeta = $this->oDOMDocument->CreateElement('meta'); $this->oRoot->AppendChild($this->oMeta); - - foreach($aRootNodeExtensions as $sElementName) + + foreach ($aRootNodeExtensions as $sElementName) { $oElement = $this->oDOMDocument->CreateElement($sElementName); $this->oRoot->AppendChild($oElement); @@ -559,6 +571,7 @@ class ModelFactory { $oNode = $this->oRoot; } + return $oNode->Dump($bReturnRes); } @@ -569,10 +582,10 @@ class ModelFactory { $this->oDOMDocument->load($sCacheFile); $this->oRoot = $this->oDOMDocument->firstChild; - + $this->oModules = $this->oRoot->getElementsByTagName('loaded_modules')->item(0); self::$aLoadedModules = array(); - foreach($this->oModules->getElementsByTagName('module') as $oModuleNode) + foreach ($this->oModules->getElementsByTagName('module') as $oModuleNode) { $sId = $oModuleNode->getAttribute('id'); $sRootDir = $oModuleNode->GetChildText('root_dir'); @@ -600,7 +613,10 @@ class ModelFactory */ public function LoadDelta($oSourceNode, $oTargetParentNode) { - if (!$oSourceNode instanceof DOMElement) return; + if (!$oSourceNode instanceof DOMElement) + { + return; + } //echo "Load $oSourceNode->tagName::".$oSourceNode->getAttribute('id')." (".$oSourceNode->getAttribute('_delta').")
\n"; $oTarget = $this->oDOMDocument; @@ -612,17 +628,18 @@ class ModelFactory { // This tag is organized in hierarchy: determine the real parent node (as a subnode of the current node) $oTargetParentNode = $oTarget->GetNodeById('/itop_design/classes//class', $sParentId)->item(0); - + if (!$oTargetParentNode) { // echo "Dumping target doc - looking for '$sParentId'
\n"; // $this->oDOMDocument->firstChild->Dump(); $sPath = MFDocument::GetItopNodePath($oSourceNode); $iLine = $oSourceNode->getLineNo(); - throw new MFException($sPath.' at line '.$iLine.": parent class '$sParentId' could not be found", MFException::PARENT_NOT_FOUND, $iLine, $sPath, $sParentId); + throw new MFException($sPath.' at line '.$iLine.": parent class '$sParentId' could not be found", + MFException::PARENT_NOT_FOUND, $iLine, $sPath, $sParentId); } } - else + else { $oTargetNode = $oTarget->GetNodeById('/itop_design/classes//class', $oSourceNode->getAttribute('id'))->item(0); if (!$oTargetNode) @@ -638,7 +655,7 @@ class ModelFactory $sPath = MFDocument::GetItopNodePath($oSourceNode); $iLine = $oSourceNode->getLineNo(); throw new MFException($sPath.' at line '.$iLine.": could not be found", MFException::NOT_FOUND, $iLine, $sPath); - + } } else @@ -652,94 +669,97 @@ class ModelFactory $oSourceNode->setAttribute('_delta', 'define'); $sDeltaSpec = 'define'; } - } - + } + } } switch ($sDeltaSpec) { - case 'if_exists': - case 'must_exist': - case 'merge': - case '': - $bMustExist = ($sDeltaSpec == 'must_exist'); - $bIfExists =($sDeltaSpec == 'if_exists'); - $sSearchId = $oSourceNode->hasAttribute('_rename_from') ? $oSourceNode->getAttribute('_rename_from') : $oSourceNode->getAttribute('id'); - $oTargetNode = $oSourceNode->MergeInto($oTargetParentNode, $sSearchId, $bMustExist, $bIfExists); - if ($oTargetNode) - { - foreach ($oSourceNode->childNodes as $oSourceChild) + case 'if_exists': + case 'must_exist': + case 'merge': + case '': + $bMustExist = ($sDeltaSpec == 'must_exist'); + $bIfExists = ($sDeltaSpec == 'if_exists'); + $sSearchId = $oSourceNode->hasAttribute('_rename_from') ? $oSourceNode->getAttribute('_rename_from') : $oSourceNode->getAttribute('id'); + $oTargetNode = $oSourceNode->MergeInto($oTargetParentNode, $sSearchId, $bMustExist, $bIfExists); + if ($oTargetNode) { - // Continue deeper - $this->LoadDelta($oSourceChild, $oTargetNode); + foreach ($oSourceNode->childNodes as $oSourceChild) + { + // Continue deeper + $this->LoadDelta($oSourceChild, $oTargetNode); + } } - } - break; + break; + + case 'define_if_not_exists': + $oExistingNode = $oTargetParentNode->_FindChildNode($oSourceNode); + if (($oExistingNode == null) || ($oExistingNode->getAttribute('_alteration') == 'removed')) + { + // Same as 'define' below + $oTargetNode = $oTarget->ImportNode($oSourceNode, true); + $oTargetParentNode->AddChildNode($oTargetNode); + } + else + { + $oTargetNode = $oExistingNode; + } + $oTargetNode->setAttribute('_alteration', 'needed'); + break; - case 'define_if_not_exists': - $oExistingNode = $oTargetParentNode->_FindChildNode($oSourceNode); - if ( ($oExistingNode == null) || ($oExistingNode->getAttribute('_alteration') == 'removed') ) - { - // Same as 'define' below - $oTargetNode = $oTarget->ImportNode($oSourceNode, true); - $oTargetParentNode->AddChildNode($oTargetNode); - } - else - { - $oTargetNode = $oExistingNode; - } - $oTargetNode->setAttribute('_alteration', 'needed'); - break; - case 'define': // New node - copy child nodes as well $oTargetNode = $oTarget->ImportNode($oSourceNode, true); $oTargetParentNode->AddChildNode($oTargetNode); break; - - case 'force': - // Force node - copy child nodes as well - $oTargetNode = $oTarget->ImportNode($oSourceNode, true); - $oTargetParentNode->SetChildNode($oTargetNode, null, true); - break; - - case 'redefine': - // Replace the existing node by the given node - copy child nodes as well - $oTargetNode = $oTarget->ImportNode($oSourceNode, true); - $sSearchId = $oSourceNode->hasAttribute('_rename_from') ? $oSourceNode->getAttribute('_rename_from') : $oSourceNode->getAttribute('id'); - $oTargetParentNode->RedefineChildNode($oTargetNode, $sSearchId); - break; - case 'delete_if_exists': - $oTargetNode = $oTargetParentNode->_FindChildNode($oSourceNode); - if (($oTargetNode !== null) && ($oTargetNode->getAttribute('_alteration') !== 'removed')) - { - // Delete the node if it actually exists and is not already marked as deleted + case 'force': + // Force node - copy child nodes as well + $oTargetNode = $oTarget->ImportNode($oSourceNode, true); + $oTargetParentNode->SetChildNode($oTargetNode, null, true); + break; + + case 'redefine': + // Replace the existing node by the given node - copy child nodes as well + $oTargetNode = $oTarget->ImportNode($oSourceNode, true); + $sSearchId = $oSourceNode->hasAttribute('_rename_from') ? $oSourceNode->getAttribute('_rename_from') : $oSourceNode->getAttribute('id'); + $oTargetParentNode->RedefineChildNode($oTargetNode, $sSearchId); + break; + + case 'delete_if_exists': + $oTargetNode = $oTargetParentNode->_FindChildNode($oSourceNode); + if (($oTargetNode !== null) && ($oTargetNode->getAttribute('_alteration') !== 'removed')) + { + // Delete the node if it actually exists and is not already marked as deleted + $oTargetNode->Delete(); + } + // otherwise fail silently + break; + + case 'delete': + $oTargetNode = $oTargetParentNode->_FindChildNode($oSourceNode); + $sPath = MFDocument::GetItopNodePath($oSourceNode); + $iLine = $oSourceNode->getLineNo(); + if ($oTargetNode == null) + { + throw new MFException($sPath.' at line '.$iLine.": could not be deleted (not found)", MFException::COULD_NOT_BE_DELETED, + $iLine, $sPath); + } + if ($oTargetNode->getAttribute('_alteration') == 'removed') + { + throw new MFException($sPath.' at line '.$iLine.": could not be deleted (already marked as deleted)", + MFException::ALREADY_DELETED, $iLine, $sPath); + } $oTargetNode->Delete(); - } - // otherwise fail silently - break; - - case 'delete': - $oTargetNode = $oTargetParentNode->_FindChildNode($oSourceNode); - $sPath = MFDocument::GetItopNodePath($oSourceNode); - $iLine = $oSourceNode->getLineNo(); - if ($oTargetNode == null) - { - throw new MFException($sPath.' at line '.$iLine.": could not be deleted (not found)", MFException::COULD_NOT_BE_DELETED, $iLine, $sPath); - } - if ($oTargetNode->getAttribute('_alteration') == 'removed') - { - throw new MFException($sPath.' at line '.$iLine.": could not be deleted (already marked as deleted)", MFException::ALREADY_DELETED, $iLine, $sPath); - } - $oTargetNode->Delete(); - break; - - default: - $sPath = MFDocument::GetItopNodePath($oSourceNode); - $iLine = $oSourceNode->getLineNo(); - throw new MFException($sPath.' at line '.$iLine.": unexpected value for attribute _delta: '".$sDeltaSpec."'", MFException::INVALID_DELTA, $iLine, $sPath, $sDeltaSpec); + break; + + default: + $sPath = MFDocument::GetItopNodePath($oSourceNode); + $iLine = $oSourceNode->getLineNo(); + throw new MFException($sPath.' at line '.$iLine.": unexpected value for attribute _delta: '".$sDeltaSpec."'", + MFException::INVALID_DELTA, $iLine, $sPath, $sDeltaSpec); } if ($oTargetNode) @@ -770,16 +790,16 @@ class ModelFactory $aDataModels = $oModule->GetDataModelFiles(); $sModuleName = $oModule->GetName(); self::$aLoadedModules[] = $oModule; - + // For persistence in the cache $oModuleNode = $this->oDOMDocument->CreateElement('module'); $oModuleNode->setAttribute('id', $oModule->GetId()); $oModuleNode->AppendChild($this->oDOMDocument->CreateElement('root_dir', $oModule->GetRootDir())); $oModuleNode->AppendChild($this->oDOMDocument->CreateElement('label', $oModule->GetLabel())); - + $this->oModules->AppendChild($oModuleNode); - - foreach($aDataModels as $sXmlFile) + + foreach ($aDataModels as $sXmlFile) { $oDocument = new MFDocument(); libxml_clear_errors(); @@ -789,10 +809,10 @@ class ModelFactory { throw new Exception($this->GetXMLErrorMessage($aErrors)); } - + $oXPath = new DOMXPath($oDocument); $oNodeList = $oXPath->query('/itop_design/classes//class'); - foreach($oNodeList as $oNode) + foreach ($oNodeList as $oNode) { if ($oNode->getAttribute('_created_in') == '') { @@ -800,7 +820,7 @@ class ModelFactory } } $oNodeList = $oXPath->query('/itop_design/constants/constant'); - foreach($oNodeList as $oNode) + foreach ($oNodeList as $oNode) { if ($oNode->getAttribute('_created_in') == '') { @@ -808,7 +828,7 @@ class ModelFactory } } $oNodeList = $oXPath->query('/itop_design/menus/menu'); - foreach($oNodeList as $oNode) + foreach ($oNodeList as $oNode) { if ($oNode->getAttribute('_created_in') == '') { @@ -823,16 +843,16 @@ class ModelFactory $oUserRightsNode->SetAttribute('_created_in', $sModuleName); } } - + $oAlteredNodes = $oXPath->query('/itop_design//*[@_delta]'); if ($oAlteredNodes->length > 0) { - foreach($oAlteredNodes as $oAlteredNode) + foreach ($oAlteredNodes as $oAlteredNode) { $oAlteredNode->SetAttribute('_altered_in', $sModuleName); } } - + $oFormat = new iTopDesignFormat($oDocument); if (!$oFormat->Convert()) { @@ -843,29 +863,29 @@ class ModelFactory $oDeltaRoot = $oDocument->childNodes->item(0); $this->LoadDelta($oDeltaRoot, $this->oDOMDocument); } - + $aDictionaries = $oModule->GetDictionaryFiles(); $sPHPFile = 'undefined'; try { $this->ResetTempDictionary(); - foreach($aDictionaries as $sPHPFile) + foreach ($aDictionaries as $sPHPFile) { $sDictFileContents = file_get_contents($sPHPFile); $sDictFileContents = str_replace(array('<'.'?'.'php', '?'.'>'), '', $sDictFileContents); $sDictFileContents = str_replace('Dict::Add', '$this->AddToTempDictionary', $sDictFileContents); eval($sDictFileContents); } - + foreach ($this->aDict as $sLanguageCode => $aDictDefinition) { - if ((count($aLanguages) > 0 ) && !in_array($sLanguageCode, $aLanguages)) + if ((count($aLanguages) > 0) && !in_array($sLanguageCode, $aLanguages)) { // skip some languages if the parameter says so continue; } - + $oNodes = $this->GetNodeById('dictionary', $sLanguageCode, $this->oDictionaries); if ($oNodes->length == 0) { @@ -874,7 +894,8 @@ class ModelFactory $this->oDictionaries->AddChildNode($oXmlDict); $oXmlEntries = $this->oDOMDocument->CreateElement('english_description', $aDictDefinition['english_description']); $oXmlDict->AppendChild($oXmlEntries); - $oXmlEntries = $this->oDOMDocument->CreateElement('localized_description', $aDictDefinition['localized_description']); + $oXmlEntries = $this->oDOMDocument->CreateElement('localized_description', + $aDictDefinition['localized_description']); $oXmlDict->AppendChild($oXmlEntries); $oXmlEntries = $this->oDOMDocument->CreateElement('entries'); $oXmlDict->AppendChild($oXmlEntries); @@ -884,15 +905,16 @@ class ModelFactory $oXmlDict = $oNodes->item(0); $oXmlEntries = $oXmlDict->GetUniqueElement('entries'); } - + foreach ($aDictDefinition['entries'] as $sCode => $sLabel) { - + $oXmlEntry = $this->oDOMDocument->CreateElement('entry'); $oXmlEntry->setAttribute('id', $sCode); $oXmlValue = $this->oDOMDocument->CreateCDATASection($sLabel); $oXmlEntry->appendChild($oXmlValue); - if (array_key_exists($sLanguageCode, $this->aDictKeys) && array_key_exists($sCode, $this->aDictKeys[$sLanguageCode])) + if (array_key_exists($sLanguageCode, $this->aDictKeys) && array_key_exists($sCode, + $this->aDictKeys[$sLanguageCode])) { $oMe = $this->aDictKeys[$sLanguageCode][$sCode]; $sFlag = $oMe->getAttribute('_alteration'); @@ -903,36 +925,38 @@ class ModelFactory $sNewFlag = 'replaced'; } $oXmlEntry->setAttribute('_alteration', $sNewFlag); - + } - else + else { $oXmlEntry->setAttribute('_alteration', 'added'); $oXmlEntries->appendChild($oXmlEntry); } $this->aDictKeys[$sLanguageCode][$sCode] = $oXmlEntry; } - } + } } - catch(Exception $e) + catch (Exception $e) { throw new Exception('Failed to load dictionary file "'.$sPHPFile.'", reason: '.$e->getMessage()); } - + } - catch(Exception $e) + catch (Exception $e) { $aLoadedModuleNames = array(); foreach (self::$aLoadedModules as $oModule) { $aLoadedModuleNames[] = $oModule->GetName(); } - throw new Exception('Error loading module "'.$oModule->GetName().'": '.$e->getMessage().' - Loaded modules: '.implode(',', $aLoadedModuleNames)); + throw new Exception('Error loading module "'.$oModule->GetName().'": '.$e->getMessage().' - Loaded modules: '.implode(',', + $aLoadedModuleNames)); } } /** * Collects the PHP Dict entries into the ModelFactory for transforming the dictionary into an XML structure + * * @param string $sLanguageCode The language code * @param string $sEnglishLanguageDesc English description of the language (unused but kept for API compatibility) * @param string $sLocalizedLanguageDesc Localized description of the language (unused but kept for API compatibility) @@ -947,7 +971,7 @@ class ModelFactory $this->aDict[$sLanguageCode]['entries'] = array(); } - foreach($aEntries as $sKey => $sValue) + foreach ($aEntries as $sKey => $sValue) { $this->aDict[$sLanguageCode]['entries'][$sKey] = $sValue; } @@ -957,18 +981,19 @@ class ModelFactory { $this->aDict = array(); } - + /** - * XML load errors (XML format and validation) + * XML load errors (XML format and validation) + * * @Deprecated Errors are now sent by Exception - */ + */ function HasLoadErrors() { return (count(self::$aLoadErrors) > 0); } /** - * @Deprecated Errors are now sent by Exception + * @Deprecated Errors are now sent by Exception * @return array */ function GetLoadErrors() @@ -984,11 +1009,12 @@ class ModelFactory protected function GetXMLErrorMessage($aErrors) { $sMessage = "Data model source file ({$aErrors[0]->file}) could not be loaded : \n"; - foreach($aErrors as $oXmlError) + foreach ($aErrors as $oXmlError) { // XML messages already ends with \n $sMessage .= $oXmlError->message; } + return $sMessage; } @@ -1002,7 +1028,7 @@ class ModelFactory if ($bExcludeWorkspace) { $aModules = array(); - foreach(self::$aLoadedModules as $oModule) + foreach (self::$aLoadedModules as $oModule) { if (!$oModule instanceof MFWorkspace) { @@ -1014,6 +1040,7 @@ class ModelFactory { $aModules = self::$aLoadedModules; } + return $aModules; } @@ -1025,10 +1052,14 @@ class ModelFactory */ function GetModule($sModuleName) { - foreach(self::$aLoadedModules as $oModule) + foreach (self::$aLoadedModules as $oModule) { - if ($oModule->GetName() == $sModuleName) return $oModule; + if ($oModule->GetName() == $sModuleName) + { + return $oModule; + } } + return null; } @@ -1057,13 +1088,15 @@ class ModelFactory /** * Check if the class specified by the given node already exists in the loaded DOM + * * @param DOMNode $oClassNode The node corresponding to the class to load - * @throws Exception + * * @return bool True if the class exists, false otherwise + * @throws Exception */ protected function ClassExists(DOMNode $oClassNode) { - assert(false); + assert(false); if ($oClassNode->hasAttribute('id')) { $sClassName = $oClassNode->GetAttribute('id'); @@ -1072,19 +1105,19 @@ class ModelFactory { throw new Exception('ModelFactory::AddClass: Cannot add a class with no name'); } - + return (array_key_exists($sClassName, self::$aLoadedClasses)); } - + /** * Check if the class specified by the given name already exists in the loaded DOM * * @param string $sClassName The node corresponding to the class to load * @param bool $bIncludeMetas Look for $sClassName also in meta declaration (PHP classes) if not found in XML classes * + * @return bool True if the class exists, false otherwise * @throws \Exception * - * @return bool True if the class exists, false otherwise */ protected function ClassNameExists($sClassName, $bIncludeMetas = false) { @@ -1093,8 +1126,10 @@ class ModelFactory /** * Add the given class to the DOM + * * @param DOMNode $oClassNode * @param string $sModuleName The name of the module in which this class is declared + * * @throws Exception */ public function AddClass(DOMNode $oClassNode, $sModuleName) @@ -1111,7 +1146,7 @@ class ModelFactory { throw new Exception("ModelFactory::AddClass: Cannot add the already existing class $sClassName"); } - + $sParentClass = $oClassNode->GetChildText('parent', ''); $oParentNode = $this->GetClass($sParentClass); if ($oParentNode == null) @@ -1125,7 +1160,7 @@ class ModelFactory $oClassNode->SetAttribute('_created_in', $sModuleName); } $oParentNode->AddChildNode($this->oDOMDocument->importNode($oClassNode, true)); - + if (substr($sParentClass, 0, 1) == '/') // Convention for well known parent classes { // Remove the leading slash character @@ -1144,8 +1179,9 @@ class ModelFactory public function GetClassXMLTemplate($sName, $sIcon) { $sHeader = ''; + return -<< @@ -1166,7 +1202,7 @@ $sHeader EOF - ; + ; } /** @@ -1205,15 +1241,17 @@ EOF public function ListAllClasses($bIncludeMetas = false) { $sXPath = "/itop_design/classes//class[@id]"; - if($bIncludeMetas === true) + if ($bIncludeMetas === true) { $sXPath .= "|/itop_design/meta/classes/class[@id]"; } + return $this->GetNodes($sXPath); } - + /** * List top level (non abstract) classes having child classes + * * @throws Exception */ public function ListRootClasses() @@ -1233,7 +1271,7 @@ EOF $oClassNode = $this->GetNodes("/itop_design/classes//class[@id='$sClassName']")->item(0); // If not, check if class among exposed meta classes (PHP classes) - if(is_null($oClassNode) && ($bIncludeMetas === true)) + if (is_null($oClassNode) && ($bIncludeMetas === true)) { $oClassNode = $this->GetNodes("/itop_design/meta/classes/class[@id='$sClassName']")->item(0); } @@ -1251,7 +1289,8 @@ EOF $oWKClass = $this->oDOMDocument->CreateElement('class'); $oWKClass->setAttribute('id', $sWellKnownParent); $this->oClasses->AppendChild($oWKClass); - return $oWKClass; + + return $oWKClass; } /** @@ -1284,6 +1323,7 @@ EOF { return $this->GetField($sParentClass, $sAttCode); } + return $oFieldNode; } @@ -1360,28 +1400,29 @@ EOF } switch ($sAlteration) { - case '': - if ($oNodeClone->hasAttribute('id')) - { - $oNodeClone->setAttribute('_delta', 'must_exist'); - } - break; - case 'added': - $oNodeClone->setAttribute('_delta', 'define'); - break; - case 'replaced': - $oNodeClone->setAttribute('_delta', 'redefine'); - break; - case 'removed': - $oNodeClone->setAttribute('_delta', 'delete'); - break; - case 'needed': - $oNodeClone->setAttribute('_delta', 'define_if_not_exists'); - break; - case 'forced': - $oNodeClone->setAttribute('_delta', 'force'); - break; + case '': + if ($oNodeClone->hasAttribute('id')) + { + $oNodeClone->setAttribute('_delta', 'must_exist'); + } + break; + case 'added': + $oNodeClone->setAttribute('_delta', 'define'); + break; + case 'replaced': + $oNodeClone->setAttribute('_delta', 'redefine'); + break; + case 'removed': + $oNodeClone->setAttribute('_delta', 'delete'); + break; + case 'needed': + $oNodeClone->setAttribute('_delta', 'define_if_not_exists'); + break; + case 'forced': + $oNodeClone->setAttribute('_delta', 'force'); + break; } + return $oNodeClone; } @@ -1428,7 +1469,7 @@ EOF $this->SetDeltaFlags($oNodeClone); // Handle the moved classes found under the root node (or the root node itself) - foreach($oNodeClone->GetNodes("descendant-or-self::class[@id]", false) as $oClassNode) + foreach ($oNodeClone->GetNodes("descendant-or-self::class[@id]", false) as $oClassNode) { if (array_key_exists($oClassNode->getAttribute('id'), $aMovedClasses)) { @@ -1475,6 +1516,7 @@ EOF $oParentClone->appendChild($oNodeClone); } } + return $oNodeClone; } @@ -1490,7 +1532,7 @@ EOF { // Search into the deleted node as well! $oNodeSet = $this->oDOMDocument->GetNodes("//*[@$sAttribute='$sPreviousValue']", null, false); - foreach($oNodeSet as $oTouchedNode) + foreach ($oNodeSet as $oTouchedNode) { $oTouchedNode->setAttribute($sAttribute, $sNewValue); } @@ -1514,7 +1556,7 @@ EOF // 1) Identify the moved classes (marked as deleted under the original parent, and created under the new parent) // 2) When importing those "moved" classes into the delta (see ImportNodeAndPathDelta), extract them from the hierarchy (the alteration can be done at an upper level in the hierarchy) and mark them as "modified" $aMovedClasses = array(); - foreach($this->GetNodes("/itop_design/classes//class/class[@_alteration='removed']", null, false) as $oNode) + foreach ($this->GetNodes("/itop_design/classes//class/class[@_alteration='removed']", null, false) as $oNode) { $sId = $oNode->getAttribute('id'); if ($this->GetNodes("/itop_design/classes//class/class[@id='$sId']/properties", null, false)->length > 0) @@ -1523,14 +1565,14 @@ EOF } } - foreach($this->ListChanges() as $oAlteredNode) + foreach ($this->ListChanges() as $oAlteredNode) { $this->ImportNodeAndPathDelta($aMovedClasses, $oDelta, $oAlteredNode); } - foreach($aNodesToIgnore as $sXPath) + foreach ($aNodesToIgnore as $sXPath) { $oNodesToRemove = $oDelta->GetNodes($sXPath); - foreach($oNodesToRemove as $oNode) + foreach ($oNodesToRemove as $oNode) { if ($oNode instanceof DOMAttr) { @@ -1543,11 +1585,11 @@ EOF } } $oNodesToClean = $oDelta->GetNodes('/itop_design//*[@_altered_in]'); - foreach($oNodesToClean as $oNode) + foreach ($oNodesToClean as $oNode) { $oNode->removeAttribute('_altered_in'); } - + if ($aAttributes != null) { foreach ($aAttributes as $sAttribute => $value) @@ -1558,6 +1600,7 @@ EOF } } } + return $oDelta; } @@ -1573,6 +1616,7 @@ EOF public function GetDelta($aNodesToIgnore = array(), $aAttributes = null) { $oDelta = $this->GetDeltaDocument($aNodesToIgnore, $aAttributes); + return $oDelta->saveXML(); } @@ -1587,7 +1631,7 @@ EOF { $aAvailableModules = ModuleDiscovery::GetAvailableModules($this->aRootDirs); $aResult = array(); - foreach($aAvailableModules as $sId => $aModule) + foreach ($aAvailableModules as $sId => $aModule) { $oModule = new MFModule($sId, $aModule['root_dir'], $aModule['label'], isset($aModule['auto_select'])); if (isset($aModule['auto_select'])) @@ -1608,6 +1652,7 @@ EOF } $aResult[] = $oModule; } + return $aResult; } @@ -1621,7 +1666,7 @@ EOF { $sHeader = ''; $sOriginalXML = -<< @@ -1643,20 +1688,20 @@ EOF; $this->oDOMDocument = new MFDocument(); $this->oDOMDocument->loadXML($sOriginalXML); - + // DOM Get the original values, then modify its contents by the mean of the API $oRoot = $this->GetNodes('//itop_design')->item(0); //$oRoot->Dump(); $sDOMOriginal = $oRoot->Dump(true); - + $oNode = $oRoot->GetNodes('a/b')->item(0); $oNew = $this->oDOMDocument->CreateElement('b', 'New text'); - $oNode->parentNode->RedefineChildNode($oNew); - + $oNode->parentNode->RedefineChildNode($oNew); + $oNode = $oRoot->GetNodes('a/c')->item(0); $oNewC = $this->oDOMDocument->CreateElement('c'); $oNewC->setAttribute('id', '1'); - $oNode->parentNode->RedefineChildNode($oNewC); + $oNode->parentNode->RedefineChildNode($oNewC); $oNewC->appendChild($this->oDOMDocument->CreateElement('d', 'x')); $oNewC->appendChild($this->oDOMDocument->CreateElement('d', 'y')); @@ -1675,22 +1720,22 @@ EOF; $oSubNode->Rename('abcdef'); $oSubNode = $oNewC->GetUniqueElement('x'); $oSubNode->Delete(); - $oNewC->RedefineChildNode($this->oDOMDocument->CreateElement('r', 'replacement')); + $oNewC->RedefineChildNode($this->oDOMDocument->CreateElement('r', 'replacement')); $oNode = $oRoot->GetNodes("//a[@id='second a']")->item(0); - $oNode->Rename('el 2o A'); - $oNode->Rename('el secundo A'); + $oNode->Rename('el 2o A'); + $oNode->Rename('el secundo A'); $oNew = $this->oDOMDocument->CreateElement('e', 'Something new here'); - $oNode->AddChildNode($oNew); + $oNode->AddChildNode($oNew); $oNewA = $this->oDOMDocument->CreateElement('a'); $oNewA->setAttribute('id', 'new a'); - $oNode->AddChildNode($oNewA); + $oNode->AddChildNode($oNewA); $oSubnode = $this->oDOMDocument->CreateElement('parent', 'el secundo A'); $oSubnode->setAttribute('id', 'to be changed'); $oNewA->AddChildNode($oSubnode); $oNewA->AddChildNode($this->oDOMDocument->CreateElement('f', 'Welcome to the newcomer')); $oNewA->AddChildNode($this->oDOMDocument->CreateElement('x', 'To delete programmatically')); - + // Alter this "new a", as it is new, no flag should be set $oNewA->Rename('new_a'); $oSubNode = $oNewA->GetUniqueElement('parent'); @@ -1698,10 +1743,10 @@ EOF; $oNewA->RedefineChildNode($this->oDOMDocument->CreateElement('f', 'dummy data')); $oSubNode = $oNewA->GetUniqueElement('x'); $oSubNode->Delete(); - + $oNode = $oRoot->GetNodes("//a[@id='third a']")->item(0); - $oNode->Delete(); - + $oNode->Delete(); + //$oRoot->Dump(); $sDOMModified = $oRoot->Dump(true); @@ -1721,7 +1766,7 @@ EOF; echo "

Rebuild the DOM - Delta applied...

\n"; $oDeltaDoc = new MFDocument(); $oDeltaDoc->loadXML($sDeltaXML); - + //$oDeltaDoc->Dump(); //$this->oDOMDocument->Dump(); $oDeltaRoot = $oDeltaDoc->childNodes->item(0); @@ -1784,6 +1829,7 @@ EOF; /** * MFElement: helper to read/change the DOM + * * @package ModelFactory * @property \MFDocument $ownerDocument This is only here for type hinting as iTop replaces \DOMDocument with \MFDocument */ @@ -1827,7 +1873,7 @@ class MFElement extends Combodo\iTop\DesignElement public function GetUniqueElement($sTagName, $bMustExist = true) { $oNode = null; - foreach($this->childNodes as $oChildNode) + foreach ($this->childNodes as $oChildNode) { if (($oChildNode->nodeName == $sTagName) && (($oChildNode->getAttribute('_alteration') != 'removed'))) { @@ -1839,6 +1885,7 @@ class MFElement extends Combodo\iTop\DesignElement { throw new DOMFormatException('Missing unique tag: '.$sTagName); } + return $oNode; } @@ -1863,7 +1910,7 @@ class MFElement extends Combodo\iTop\DesignElement { $res = array(); $aRanks = array(); - foreach($oItems->childNodes as $oItem) + foreach ($oItems->childNodes as $oItem) { if ($oItem instanceof DOMElement) { @@ -1885,7 +1932,7 @@ class MFElement extends Combodo\iTop\DesignElement $sRank = $oItem->GetChildText('rank'); if ($sRank != '') { - $aRanks[] = (float) $sRank; + $aRanks[] = (float)$sRank; } else { @@ -1899,6 +1946,7 @@ class MFElement extends Combodo\iTop\DesignElement { $res = $this->GetText(); } + return $res; } @@ -1913,12 +1961,12 @@ class MFElement extends Combodo\iTop\DesignElement { $oXmlItems = $oXmlDoc->CreateElement('items'); $oXMLNode->AppendChild($oXmlItems); - - foreach($itemValue as $key => $item) + + foreach ($itemValue as $key => $item) { $oXmlItem = $oXmlDoc->CreateElement('item'); $oXmlItems->AppendChild($oXmlItem); - + if (is_string($key)) { $oXmlItem->SetAttribute('key', $key); @@ -1928,14 +1976,14 @@ class MFElement extends Combodo\iTop\DesignElement } else { - $oXmlText = $oXmlDoc->CreateTextNode((string) $itemValue); + $oXmlText = $oXmlDoc->CreateTextNode((string)$itemValue); $oXMLNode->AppendChild($oXmlText); } } /** - * Helper to remove child nodes - */ + * Helper to remove child nodes + */ protected function DeleteChildren() { while (isset($this->firstChild)) @@ -1998,59 +2046,65 @@ class MFElement extends Combodo\iTop\DesignElement $sSearchId = $oRefNode->getAttribute('id'); } $sXPath = './'.$oRefNode->tagName."[@id='$sSearchId']"; - + $oRes = $oXPath->query($sXPath, $oRoot)->item(0); } else { // Get the first one having the same tag name (ignore others) $sXPath = './'.$oRefNode->tagName; - + $oRes = $oXPath->query($sXPath, $oRoot)->item(0); } + return $oRes; } /** * Check if the current node is under a node 'added' or 'altered' - * Usage: In such a case, the change must not be tracked + * Usage: In such a case, the change must not be tracked */ - public function IsInDefinition() - { + public function IsInDefinition() + { // Iterate through the parents: reset the flag if any of them has a flag set - for($oParent = $this ; $oParent instanceof MFElement ; $oParent = $oParent->parentNode) + for ($oParent = $this; $oParent instanceof MFElement; $oParent = $oParent->parentNode) { if ($oParent->getAttribute('_alteration') != '') { return true; } } + return false; } /** - * Check if the given node is (a child of a node) altered by one of the supplied modules + * Check if the given node is (a child of a node) altered by one of the supplied modules + * * @param array $aModules The list of module codes to consider + * * @return boolean */ public function IsAlteredByModule($aModules) { // Iterate through the parents: reset the flag if any of them has a flag set - for($oParent = $this ; $oParent instanceof MFElement ; $oParent = $oParent->parentNode) + for ($oParent = $this; $oParent instanceof MFElement; $oParent = $oParent->parentNode) { if (in_array($oParent->getAttribute('_altered_in'), $aModules)) { return true; } } + return false; } static $aTraceAttributes = null; + /** * Enable/disable the trace on changed nodes - * - *@param array aAttributes Array of attributes (key => value) to be added onto any changed node + * + * @param array aAttributes Array of attributes (key => value) to be added onto any changed node */ static public function SetTrace($aAttributes = null) { @@ -2058,8 +2112,8 @@ class MFElement extends Combodo\iTop\DesignElement } /** - * Mark the node as touched (if tracing is active) - */ + * Mark the node as touched (if tracing is active) + */ public function AddTrace() { if (!is_null(self::$aTraceAttributes)) @@ -2091,15 +2145,16 @@ class MFElement extends Combodo\iTop\DesignElement { $sPath = MFDocument::GetItopNodePath($oNode); $iLine = $oNode->getLineNo(); - throw new MFException($sPath.' at line '.$iLine.": could not be added (already exists)", MFException::COULD_NOT_BE_ADDED, $iLine, $sPath); + throw new MFException($sPath.' at line '.$iLine.": could not be added (already exists)", MFException::COULD_NOT_BE_ADDED, + $iLine, $sPath); } $oExisting->ReplaceWith($oNode); - $sFlag = 'replaced'; + $sFlag = 'replaced'; } else { $this->appendChild($oNode); - $sFlag = 'added'; + $sFlag = 'added'; } if (!$this->IsInDefinition()) { @@ -2126,14 +2181,16 @@ class MFElement extends Combodo\iTop\DesignElement { $sPath = MFDocument::GetItopNodePath($this)."/".$oNode->tagName.(empty($sSearchId) ? '' : "[$sSearchId]"); $iLine = $oNode->getLineNo(); - throw new MFException($sPath." at line $iLine: could not be modified (not found)", MFException::COULD_NOT_BE_MODIFIED_NOT_FOUND, $sPath, $iLine); + throw new MFException($sPath." at line $iLine: could not be modified (not found)", MFException::COULD_NOT_BE_MODIFIED_NOT_FOUND, + $sPath, $iLine); } $sPrevFlag = $oExisting->getAttribute('_alteration'); if ($sPrevFlag == 'removed') { $sPath = MFDocument::GetItopNodePath($this)."/".$oNode->tagName.(empty($sSearchId) ? '' : "[$sSearchId]"); $iLine = $oNode->getLineNo(); - throw new MFException($sPath." at line $iLine: could not be modified (marked as deleted)", MFException::COULD_NOT_BE_MODIFIED_ALREADY_DELETED, $sPath, $iLine); + throw new MFException($sPath." at line $iLine: could not be modified (marked as deleted)", + MFException::COULD_NOT_BE_MODIFIED_ALREADY_DELETED, $sPath, $iLine); } $oExisting->ReplaceWith($oNode); if (!$this->IsInDefinition()) @@ -2149,6 +2206,7 @@ class MFElement extends Combodo\iTop\DesignElement /** * Combination of AddChildNode or RedefineChildNode... it depends * This should become the preferred way of doing things (instead of implementing a test + the call to one of the APIs! + * * @param MFElement $oNode The node (including all subnodes) to set * @param string $sSearchId Optional Id of the node to SearchMenuNode * @param bool $bForce Force mode to dynamically add or replace nodes @@ -2164,16 +2222,16 @@ class MFElement extends Combodo\iTop\DesignElement $oExisting = $this->_FindChildNode($oNode, $sSearchId); if ($oExisting) { - $sOldId = $oExisting->getAttribute('_old_id'); - if(!empty($sOldId)) - { - $oNode->setAttribute('_old_id', $sOldId); - } + $sOldId = $oExisting->getAttribute('_old_id'); + if (!empty($sOldId)) + { + $oNode->setAttribute('_old_id', $sOldId); + } $sPrevFlag = $oExisting->getAttribute('_alteration'); if ($sPrevFlag == 'removed') { - $sFlag = $bForce ? 'forced': 'replaced'; + $sFlag = $bForce ? 'forced' : 'replaced'; } else { @@ -2184,13 +2242,13 @@ class MFElement extends Combodo\iTop\DesignElement else { $this->appendChild($oNode); - $sFlag = $bForce ? 'forced': 'added'; + $sFlag = $bForce ? 'forced' : 'added'; } if (!$this->IsInDefinition()) { if ($sFlag == '') { - $sFlag = $bForce ? 'forced': 'replaced'; + $sFlag = $bForce ? 'forced' : 'replaced'; } $oNode->setAttribute('_alteration', $sFlag); } @@ -2198,15 +2256,16 @@ class MFElement extends Combodo\iTop\DesignElement /** * Check that the current node is actually a class node, under classes - */ + */ public function IsClassNode() { if ($this->tagName == 'class') { - if (($this->parentNode->tagName == 'classes') && ($this->parentNode->parentNode->tagName == 'itop_design') ) // Beware: classes/class also exists in the group definition + if (($this->parentNode->tagName == 'classes') && ($this->parentNode->parentNode->tagName == 'itop_design')) // Beware: classes/class also exists in the group definition { return true; } + return $this->parentNode->IsClassNode(); } else @@ -2217,14 +2276,15 @@ class MFElement extends Combodo\iTop\DesignElement /** * Replaces a node by another one, making sure that recursive nodes are preserved + * * @param MFElement $oNewNode The replacement - */ + */ protected function ReplaceWith($oNewNode) { // Move the classes from the old node into the new one if ($this->IsClassNode()) { - foreach($this->GetNodes('class') as $oChild) + foreach ($this->GetNodes('class') as $oChild) { $oNewNode->appendChild($oChild); } @@ -2243,23 +2303,23 @@ class MFElement extends Combodo\iTop\DesignElement { switch ($this->getAttribute('_alteration')) { - case 'replaced': - $sFlag = 'removed'; - break; - case 'added': - case 'needed': - $sFlag = null; - break; - case 'removed': - throw new Exception("Attempting to remove a deleted node: $this->tagName (id: ".$this->getAttribute('id').""); - - default: - $sFlag = 'removed'; - if ($this->IsInDefinition()) - { + case 'replaced': + $sFlag = 'removed'; + break; + case 'added': + case 'needed': $sFlag = null; break; - } + case 'removed': + throw new Exception("Attempting to remove a deleted node: $this->tagName (id: ".$this->getAttribute('id').""); + + default: + $sFlag = 'removed'; + if ($this->IsInDefinition()) + { + $sFlag = null; + break; + } } if ($sFlag) { @@ -2320,12 +2380,14 @@ class MFElement extends Combodo\iTop\DesignElement $oContainer->AddChildNode($oTargetNode); } } + return $oTargetNode; } /** * Renames a node and set the flags that will be used to compute the delta - * @param string $sId The new id + * + * @param string $sId The new id */ public function Rename($sId) { @@ -2345,9 +2407,12 @@ class MFElement extends Combodo\iTop\DesignElement $this->removeAttribute('_rename_from'); } } - else if($sOriginalId == $sId) + else { - $this->removeAttribute('_old_id'); + if ($sOriginalId == $sId) + { + $this->removeAttribute('_old_id'); + } } } $this->setAttribute('id', $sId); @@ -2358,8 +2423,8 @@ class MFElement extends Combodo\iTop\DesignElement /** - * List changes below a given node (see also MFDocument::ListChanges) - */ + * List changes below a given node (see also MFDocument::ListChanges) + */ public function ListChanges() { // Note: omitting the dot will make the query be global to the whole document!!! @@ -2367,28 +2432,28 @@ class MFElement extends Combodo\iTop\DesignElement } /** - * List changes below a given node (see also MFDocument::ApplyChanges) - */ + * List changes below a given node (see also MFDocument::ApplyChanges) + */ public function ApplyChanges() { $oNodes = $this->ListChanges(); - foreach($oNodes as $oNode) + foreach ($oNodes as $oNode) { $sOperation = $oNode->GetAttribute('_alteration'); - switch($sOperation) + switch ($sOperation) { case 'added': case 'replaced': case 'needed': case 'forced': - // marked as added or modified, just reset the flag - $oNode->removeAttribute('_alteration'); - break; - + // marked as added or modified, just reset the flag + $oNode->removeAttribute('_alteration'); + break; + case 'removed': - // marked as deleted, let's remove the node from the tree - $oNode->parentNode->removeChild($oNode); - break; + // marked as deleted, let's remove the node from the tree + $oNode->parentNode->removeChild($oNode); + break; } if ($oNode->hasAttribute('_old_id')) { @@ -2400,6 +2465,7 @@ class MFElement extends Combodo\iTop\DesignElement /** * MFDocument - formatting rules for XML input/output + * * @package ModelFactory */ class MFDocument extends \Combodo\iTop\DesignDocument @@ -2455,6 +2521,7 @@ class MFDocument extends \Combodo\iTop\DesignDocument { $oElement->appendChild(new DOMText($value)); } + return $oElement; } @@ -2489,7 +2556,7 @@ class MFDocument extends \Combodo\iTop\DesignDocument { $sXPath .= "[not(@_alteration) or @_alteration!='removed']"; } - + if (is_null($oContextNode)) { $oResult = $oXPath->query($sXPath); @@ -2498,6 +2565,7 @@ class MFDocument extends \Combodo\iTop\DesignDocument { $oResult = $oXPath->query($sXPath, $oContextNode); } + return $oResult; } @@ -2513,7 +2581,7 @@ class MFDocument extends \Combodo\iTop\DesignDocument $oXPath = new DOMXPath($this); $sQuotedId = self::XPathQuote($sId); $sXPath .= "[@id=$sQuotedId and(not(@_alteration) or @_alteration!='removed')]"; - + if (is_null($oContextNode)) { return $oXPath->query($sXPath); @@ -2559,6 +2627,7 @@ class MFParameters { return $this->aData[$sCode]; } + return $default; } @@ -2578,7 +2647,7 @@ class MFParameters public function LoadFromDOM(DOMNode $oNode) { $this->aData = array(); - foreach($oNode->childNodes as $oChildNode) + foreach ($oNode->childNodes as $oChildNode) { if ($oChildNode instanceof DOMElement) { @@ -2605,13 +2674,13 @@ class MFParameters $sNodeType = $sDefaultNodeType; } - switch($sNodeType) + switch ($sNodeType) { case 'array': $value = array(); // Treat the current element as zero based array, child tag names are NOT meaningful $sFirstTagName = null; - foreach($oNode->childNodes as $oChildElement) + foreach ($oNode->childNodes as $oChildElement) { if ($oChildElement instanceof DOMElement) { @@ -2619,9 +2688,12 @@ class MFParameters { $sFirstTagName = $oChildElement->nodeName; } - else if ($sFirstTagName != $oChildElement->nodeName) + else { - throw new Exception("Invalid Parameters: mixed tags ('$sFirstTagName' and '".$oChildElement->nodeName."') inside array '".$oNode->nodeName."'"); + if ($sFirstTagName != $oChildElement->nodeName) + { + throw new Exception("Invalid Parameters: mixed tags ('$sFirstTagName' and '".$oChildElement->nodeName."') inside array '".$oNode->nodeName."'"); + } } $val = $this->ReadElement($oChildElement); // No specific Id, just push the value at the end of the array @@ -2630,11 +2702,11 @@ class MFParameters } ksort($value, SORT_NUMERIC); break; - + case 'hash': $value = array(); // Treat the current element as a hash, child tag names are keys - foreach($oNode->childNodes as $oChildElement) + foreach ($oNode->childNodes as $oChildElement) { if ($oChildElement instanceof DOMElement) { @@ -2647,12 +2719,12 @@ class MFParameters } } break; - + case 'int': case 'integer': $value = (int)$this->GetText($oNode); break; - + case 'bool': case 'boolean': if (($this->GetText($oNode) == 'true') || ($this->GetText($oNode) == 1)) @@ -2664,15 +2736,18 @@ class MFParameters $value = false; } break; - + case 'string': default: $value = str_replace('\n', "\n", (string)$this->GetText($oNode)); } } - else if ($oNode instanceof DOMText) + else { - $value = $oNode->wholeText; + if ($oNode instanceof DOMText) + { + $value = $oNode->wholeText; + } } return $value; @@ -2689,7 +2764,7 @@ class MFParameters { $sRet = $sDefaultValue; - foreach($oNode->attributes as $oAttribute) + foreach ($oNode->attributes as $oAttribute) { if ($oAttribute->nodeName == $sAttName) { @@ -2697,6 +2772,7 @@ class MFParameters break; } } + return $sRet; } @@ -2711,11 +2787,14 @@ class MFParameters public function GetText($oNode, $sDefault = null) { $sText = null; - foreach($oNode->childNodes as $oChildNode) + foreach ($oNode->childNodes as $oChildNode) { if ($oChildNode instanceof DOMText) { - if (is_null($sText)) $sText = ''; + if (is_null($sText)) + { + $sText = ''; + } $sText .= $oChildNode->wholeText; } } @@ -2740,7 +2819,7 @@ class MFParameters { if ($oNode instanceof DOMElement) { - foreach($oNode->childNodes as $oChildNode) + foreach ($oNode->childNodes as $oChildNode) { if ($oChildNode instanceof DOMElement) { @@ -2748,6 +2827,7 @@ class MFParameters } } } + return false; } @@ -2781,19 +2861,20 @@ class MFParameters * * @param array $array1 * @param array $array2 + * * @return array * @author Daniel * @author Gabriel Sobrinho */ - protected function array_merge_recursive_distinct ( array &$array1, array &$array2 ) + protected function array_merge_recursive_distinct(array &$array1, array &$array2) { $merged = $array1; - foreach ( $array2 as $key => &$value ) + foreach ($array2 as $key => &$value) { - if ( is_array ( $value ) && isset ( $merged [$key] ) && is_array ( $merged [$key] ) ) + if (is_array($value) && isset ($merged [$key]) && is_array($merged [$key])) { - $merged [$key] = $this->array_merge_recursive_distinct ( $merged [$key], $value ); + $merged [$key] = $this->array_merge_recursive_distinct($merged [$key], $value); } else { diff --git a/setup/wizardsteps.class.inc.php b/setup/wizardsteps.class.inc.php index c353b6403..4d91602c1 100644 --- a/setup/wizardsteps.class.inc.php +++ b/setup/wizardsteps.class.inc.php @@ -2099,7 +2099,7 @@ class WizStepSummary extends WizardStep public function Display(WebPage $oPage) { $oPage->add_style( -<<BuildConfig(); @@ -2261,7 +2261,7 @@ EOF } $oPage->add_ready_script( -<<