示例#1
0
 public function getDatabase()
 {
     if (null === $this->database) {
         $xtad = new SchemaReader($this->getPlatform());
         $xtad->setGeneratorConfig($this->getConfig());
         $appData = $xtad->parseString($this->schema);
         $this->database = $appData->getDatabase();
         // does final initialization
     }
     return $this->database;
 }
 /**
  * Returns all matching XML schema files and loads them into data models for
  * class.
  */
 protected function loadDataModels()
 {
     $schemas = array();
     $totalNbTables = 0;
     $dataModelFiles = $this->getSchemas();
     $defaultPlatform = $this->getGeneratorConfig()->getConfiguredPlatform();
     // Make a transaction for each file
     foreach ($dataModelFiles as $schema) {
         $dmFilename = $schema->getPathName();
         $this->log('Processing: ' . $schema->getFileName());
         $dom = new \DOMDocument('1.0', 'UTF-8');
         $dom->load($dmFilename);
         $this->includeExternalSchemas($dom, $schema->getPath());
         // normalize (or transform) the XML document using XSLT
         if ($this->getGeneratorConfig()->get()['generator']['schema']['transform'] && $this->xsl) {
             $this->log('Transforming ' . $dmFilename . ' using stylesheet ' . $this->xsl->getPath());
             if (!class_exists('\\XSLTProcessor')) {
                 $this->log('Could not perform XLST transformation. Make sure PHP has been compiled/configured to support XSLT.');
             } else {
                 // normalize the document using normalizer stylesheet
                 $xslDom = new \DOMDocument('1.0', 'UTF-8');
                 $xslDom->load($this->xsl->getAbsolutePath());
                 $xsl = new \XsltProcessor();
                 $xsl->importStyleSheet($xslDom);
                 $dom = $xsl->transformToDoc($dom);
             }
         }
         // validate the XML document using XSD schema
         if ($this->validate && $this->xsd) {
             $this->log('  Validating XML using schema ' . $this->xsd->getPath());
             if (!$dom->schemaValidate($this->xsd->getAbsolutePath())) {
                 throw new EngineException(sprintf("XML schema file (%s) does not validate. See warnings above for reasons validation failed (make sure error_reporting is set to show E_WARNING if you don't see any).", $dmFilename), $this->getLocation());
             }
         }
         $xmlParser = new SchemaReader($defaultPlatform, $this->dbEncoding);
         $xmlParser->setGeneratorConfig($this->getGeneratorConfig());
         $schema = $xmlParser->parseString($dom->saveXML(), $dmFilename);
         $nbTables = $schema->getDatabase(null, false)->countTables();
         $totalNbTables += $nbTables;
         $this->log(sprintf('  %d tables processed successfully', $nbTables));
         $schema->setName($dmFilename);
         $schemas[] = $schema;
     }
     $this->log(sprintf('%d tables found in %d schema files.', $totalNbTables, count($dataModelFiles)));
     if (empty($schemas)) {
         throw new BuildException('No schema files were found (matching your schema fileset definition).');
     }
     foreach ($schemas as $schema) {
         // map schema filename with database name
         $this->dataModelDbMap[$schema->getName()] = $schema->getDatabase(null, false)->getName();
     }
     if (count($schemas) > 1 && $this->getGeneratorConfig()->get()['generator']['packageObjectModel']) {
         $schema = $this->joinDataModels($schemas);
         $this->dataModels = array($schema);
     } else {
         $this->dataModels = $schemas;
     }
     foreach ($this->dataModels as &$schema) {
         $schema->doFinalInitialization();
     }
     $this->dataModelsLoaded = true;
 }