Ejemplo n.º 1
0
 public static function Run($strSettingsXmlFilePath)
 {
     QCodeGen::$CodeGenArray = array();
     QCodeGen::$SettingsFilePath = $strSettingsXmlFilePath;
     if (!file_exists($strSettingsXmlFilePath)) {
         QCodeGen::$RootErrors = 'FATAL ERROR: CodeGen Settings XML File (' . $strSettingsXmlFilePath . ') was not found.';
         return;
     }
     if (!is_file($strSettingsXmlFilePath)) {
         QCodeGen::$RootErrors = 'FATAL ERROR: CodeGen Settings XML File (' . $strSettingsXmlFilePath . ') was not found.';
         return;
     }
     // Try Parsing the Xml Settings File
     try {
         QApplication::SetErrorHandler('QcodoHandleCodeGenParseError', E_ALL);
         QCodeGen::$SettingsXml = new SimpleXMLElement(file_get_contents($strSettingsXmlFilePath));
         QApplication::RestoreErrorHandler();
     } catch (Exception $objExc) {
         QCodeGen::$RootErrors .= 'FATAL ERROR: Unable to parse CodeGenSettings XML File: ' . $strSettingsXmlFilePath;
         QCodeGen::$RootErrors .= "\r\n";
         QCodeGen::$RootErrors .= $objExc->getMessage();
         return;
     }
     // Set the Template Escaping
     QCodeGen::$TemplateEscapeBegin = QCodeGen::LookupSetting(QCodeGen::$SettingsXml, 'templateEscape', 'begin');
     QCodeGen::$TemplateEscapeEnd = QCOdeGen::LookupSetting(QCodeGen::$SettingsXml, 'templateEscape', 'end');
     QCodeGen::$TemplateEscapeBeginLength = strlen(QCodeGen::$TemplateEscapeBegin);
     QCodeGen::$TemplateEscapeEndLength = strlen(QCodeGen::$TemplateEscapeEnd);
     if (!QCodeGen::$TemplateEscapeBeginLength || !QCodeGen::$TemplateEscapeEndLength) {
         QCodeGen::$RootErrors .= "CodeGen Settings XML Fatal Error: templateEscape begin and/or end was not defined\r\n";
         return;
     }
     // Application Name
     QCodeGen::$ApplicationName = QCodeGen::LookupSetting(QCodeGen::$SettingsXml, 'name', 'application');
     // Iterate Through DataSources
     if (QCodeGen::$SettingsXml->dataSources->asXML()) {
         foreach (QCodeGen::$SettingsXml->dataSources->children() as $objChildNode) {
             switch (dom_import_simplexml($objChildNode)->nodeName) {
                 case 'database':
                     QCodeGen::$CodeGenArray[] = new QDatabaseCodeGen($objChildNode);
                     break;
                 case 'restService':
                     QCodeGen::$CodeGenArray[] = new QRestServiceCodeGen($objChildNode);
                     break;
                 default:
                     QCodeGen::$RootErrors .= sprintf("Invalid Data Source Type in CodeGen Settings XML File (%s): %s\r\n", $strSettingsXmlFilePath, dom_import_simplexml($objChildNode)->nodeName);
                     break;
             }
         }
     }
 }