public function __construct($objSettingsXml) { // Lookup Instance-Specific Configuration from the SettingsXml Node $this->strServiceUrl = QCodeGen::LookupSetting($objSettingsXml, null, 'serviceUrl'); }
public function __construct($objSettingsXml) { // Setup Local Arrays $this->strAssociationTableNameArray = array(); $this->objTableArray = array(); $this->objTypeTableArray = array(); $this->strExcludedTableArray = array(); // Set the DatabaseIndex $this->intDatabaseIndex = QCodeGen::LookupSetting($objSettingsXml, null, 'index', QType::Integer); // Append Suffix/Prefixes $this->strClassPrefix = QCodeGen::LookupSetting($objSettingsXml, 'className', 'prefix'); $this->strClassSuffix = QCodeGen::LookupSetting($objSettingsXml, 'className', 'suffix'); $this->strAssociatedObjectPrefix = QCodeGen::LookupSetting($objSettingsXml, 'associatedObjectName', 'prefix'); $this->strAssociatedObjectSuffix = QCodeGen::LookupSetting($objSettingsXml, 'associatedObjectName', 'suffix'); // Table Type Identifiers $this->strTypeTableSuffix = QCodeGen::LookupSetting($objSettingsXml, 'typeTableIdentifier', 'suffix'); $this->intTypeTableSuffixLength = strlen($this->strTypeTableSuffix); $this->strAssociationTableSuffix = QCodeGen::LookupSetting($objSettingsXml, 'associationTableIdentifier', 'suffix'); $this->intAssociationTableSuffixLength = strlen($this->strAssociationTableSuffix); // Stripping TablePrefixes $this->strStripTablePrefix = QCodeGen::LookupSetting($objSettingsXml, 'stripFromTableName', 'prefix'); $this->intStripTablePrefixLength = strlen($this->strStripTablePrefix); // Exclude/Include Tables $this->strExcludePattern = QCodeGen::LookupSetting($objSettingsXml, 'excludeTables', 'pattern'); $strExcludeList = QCodeGen::LookupSetting($objSettingsXml, 'excludeTables', 'list'); $this->strExcludeListArray = explode(',', $strExcludeList); array_walk($this->strExcludeListArray, 'array_trim'); // Include Patterns $this->strIncludePattern = QCodeGen::LookupSetting($objSettingsXml, 'includeTables', 'pattern'); $strIncludeList = QCodeGen::LookupSetting($objSettingsXml, 'includeTables', 'list'); $this->strIncludeListArray = explode(',', $strIncludeList); array_walk($this->strIncludeListArray, 'array_trim'); // ManualQuery Support $this->blnManualQuerySupport = QCodeGen::LookupSetting($objSettingsXml, 'manualQuery', 'support', QType::Boolean); // Relationship Scripts $this->strRelationships = QCodeGen::LookupSetting($objSettingsXml, 'relationships'); $this->strRelationshipsScriptPath = QCodeGen::LookupSetting($objSettingsXml, 'relationshipsScript', 'filepath'); $this->strRelationshipsScriptFormat = QCodeGen::LookupSetting($objSettingsXml, 'relationshipsScript', 'format'); // Check to make sure things that are required are there if (!$this->intDatabaseIndex) { $this->strErrors .= "CodeGen Settings XML Fatal Error: databaseIndex was invalid or not set\r\n"; } // Aggregate RelationshipLinesQcodo and RelationshipLinesSql arrays if ($this->strRelationships) { $strLines = explode("\n", strtolower($this->strRelationships)); if ($strLines) { foreach ($strLines as $strLine) { $strLine = trim($strLine); if ($strLine && strlen($strLine) > 2 && substr($strLine, 0, 2) != '//' && substr($strLine, 0, 2) != '--' && substr($strLine, 0, 1) != '#') { $this->strRelationshipLinesQcodo[$strLine] = $strLine; } } } } if ($this->strRelationshipsScriptPath) { if (!file_exists($this->strRelationshipsScriptPath)) { $this->strErrors .= sprintf("CodeGen Settings XML Fatal Error: relationshipsScript filepath \"%s\" does not exist\r\n", $this->strRelationshipsScriptPath); } else { $strScript = strtolower(trim(file_get_contents($this->strRelationshipsScriptPath))); switch ($this->strRelationshipsScriptFormat) { case 'qcodo': $strLines = explode("\n", $strScript); if ($strLines) { foreach ($strLines as $strLine) { $strLine = trim($strLine); if ($strLine && strlen($strLine) > 2 && substr($strLine, 0, 2) != '//' && substr($strLine, 0, 2) != '--' && substr($strLine, 0, 1) != '#') { $this->strRelationshipLinesQcodo[$strLine] = $strLine; } } } break; case 'sql': // Separate all commands in the script (separated by ";") $strCommands = explode(';', $strScript); if ($strCommands) { foreach ($strCommands as $strCommand) { $strCommand = trim($strCommand); if ($strCommand) { // Take out all comment lines in the script $strLines = explode("\n", $strCommand); $strCommand = ''; foreach ($strLines as $strLine) { $strLine = trim($strLine); if ($strLine && substr($strLine, 0, 2) != '//' && substr($strLine, 0, 2) != '--' && substr($strLine, 0, 1) != '#') { $strLine = str_replace(' ', ' ', $strLine); $strLine = str_replace(' ', ' ', $strLine); $strLine = str_replace(' ', ' ', $strLine); $strLine = str_replace(' ', ' ', $strLine); $strLine = str_replace(' ', ' ', $strLine); $strLine = str_replace(' ', ' ', $strLine); $strLine = str_replace(' ', ' ', $strLine); $strLine = str_replace(' ', ' ', $strLine); $strLine = str_replace(' ', ' ', $strLine); $strLine = str_replace(' ', ' ', $strLine); $strLine = str_replace(' ', ' ', $strLine); $strLine = str_replace(' ', ' ', $strLine); $strCommand .= $strLine . ' '; } } $strCommand = trim($strCommand); if (strpos($strCommand, 'alter table') === 0 && strpos($strCommand, 'foreign key') !== false) { $this->strRelationshipLinesSql[$strCommand] = $strCommand; } } } } break; default: $this->strErrors .= sprintf("CodeGen Settings XML Fatal Error: relationshipsScript format \"%s\" is invalid (must be either \"qcodo\" or \"sql\")\r\n", $this->strRelationshipsScriptFormat); break; } } } if ($this->strErrors) { return; } $this->AnalyzeDatabase(); }
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; } } } }