예제 #1
0
 /**
  * compile the given class id.
  * @param jSelectorDao $selector
  */
 public function compile($selector)
 {
     $daoPath = $selector->getPath();
     // load the XML file
     $doc = new DOMDocument();
     if (!$doc->load($daoPath)) {
         throw new jException('jelix~daoxml.file.unknown', $daoPath);
     }
     if ($doc->documentElement->namespaceURI != JELIX_NAMESPACE_BASE . 'dao/1.0') {
         throw new jException('jelix~daoxml.namespace.wrong', array($daoPath, $doc->namespaceURI));
     }
     $tools = jApp::loadPlugin($selector->driver, 'db', '.dbtools.php', $selector->driver . 'DbTools');
     if (is_null($tools)) {
         throw new jException('jelix~db.error.driver.notfound', $selector->driver);
     }
     $parser = new jDaoParser($selector);
     $parser->parse(simplexml_import_dom($doc), $tools);
     $class = $selector->dbType . 'DaoBuilder';
     if (!jApp::includePlugin($selector->dbType, 'daobuilder', '.daobuilder.php', $class)) {
         throw new jException('jelix~dao.error.builder.notfound', $selector->dbType);
     }
     $generator = new $class($selector, $tools, $parser);
     // generation of PHP classes corresponding to the DAO definition
     $compiled = '<?php ';
     $compiled .= "\nif (jApp::config()->compilation['checkCacheFiletime']&&(\n";
     $compiled .= "\n filemtime('" . $daoPath . '\') > ' . filemtime($daoPath);
     $importedDao = $parser->getImportedDao();
     if ($importedDao) {
         foreach ($importedDao as $selimpdao) {
             $path = $selimpdao->getPath();
             $compiled .= "\n|| filemtime('" . $path . '\') > ' . filemtime($path);
         }
     }
     $compiled .= ")){ return false;\n}\nelse {\n";
     $compiled .= $generator->buildClasses() . "\n return true; }";
     jFile::write($selector->getCompiledFilePath(), $compiled);
     return true;
 }
예제 #2
0
 protected function import($xml, $tools)
 {
     if (isset($xml['import'])) {
         $import = (string) $xml['import'];
         jApp::pushCurrentModule($this->selector->module);
         // Keep the same driver as current used
         $importSel = new jSelectorDaoDb($import, $this->selector->driver, $this->selector->dbType);
         jApp::popCurrentModule();
         $doc = new DOMDocument();
         if (!$doc->load($importSel->getPath())) {
             throw new jException('jelix~daoxml.file.unknown', $importSel->getPath());
         }
         $parser = new jDaoParser($importSel);
         $parser->parse(simplexml_import_dom($doc), $tools);
         $this->_properties = $parser->getProperties();
         $this->_tables = $parser->getTables();
         $this->_primaryTable = $parser->getPrimaryTable();
         $this->_methods = $parser->getMethods();
         $this->_ojoins = $parser->getOuterJoins();
         $this->_ijoins = $parser->getInnerJoins();
         $this->_eventList = $parser->getEvents();
         $this->_userRecord = $parser->getUserRecord();
         $this->_importedDao = $parser->getImportedDao();
         $this->hasOnlyPrimaryKeys = $parser->hasOnlyPrimaryKeys;
         if ($this->_importedDao) {
             $this->_importedDao[] = $importSel;
         } else {
             $this->_importedDao = array($importSel);
         }
     }
 }