Source for file jDaoCompiler.class.php

Documentation is available at jDaoCompiler.class.php

  1. <?php
  2. /**
  3. * @package    jelix
  4. * @subpackage dao
  5. * @author      Laurent Jouanneau
  6. * @copyright   2005-2010 Laurent Jouanneau
  7. *  Idea of this class was get originally from the Copix project
  8. *  (CopixDaoCompiler, Copix 2.3dev20050901, http://www.copix.org)
  9. *  no more line of code are copyrighted by CopixTeam
  10. *
  11. * @link        http://www.jelix.org
  12. * @licence  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
  13. */
  14.  
  15. /**
  16.  *
  17.  */
  18. require(JELIX_LIB_PATH.'dao/jDaoParser.class.php');
  19. require(JELIX_LIB_PATH.'dao/jDaoProperty.class.php');
  20. require(JELIX_LIB_PATH.'dao/jDaoMethod.class.php');
  21. require(JELIX_LIB_PATH.'dao/jDaoGenerator.class.php');
  22.  
  23. /**
  24.  * The compiler for the DAO xml files. it is used by jIncluder
  25.  * It produces some php classes
  26.  * @package  jelix
  27.  * @subpackage dao
  28.  */
  29. class jDaoCompiler  implements jISimpleCompiler {
  30.  
  31.     /**
  32.     * compile the given class id.
  33.     */
  34.     public function compile ($selector) {
  35.  
  36.         $daoPath = $selector->getPath();
  37.  
  38.         // chargement du fichier XML
  39.         $doc = new DOMDocument();
  40.  
  41.         if(!$doc->load($daoPath)){
  42.             throw new jException('jelix~daoxml.file.unknown', $daoPath);
  43.         }
  44.  
  45.         if($doc->documentElement->namespaceURI != JELIX_NAMESPACE_BASE.'dao/1.0'){
  46.             throw new jException('jelix~daoxml.namespace.wrong',array($daoPath, $doc->namespaceURI));
  47.         }
  48.  
  49.         global $gJConfig;
  50.         $tools = jApp::loadPlugin($selector->driver, 'db', '.dbtools.php', $selector->driver.'DbTools');
  51.         if(is_null($tools))
  52.             throw new jException('jelix~db.error.driver.notfound', $selector->driver);
  53.  
  54.         $parser = new jDaoParser ($selector);
  55.         $parser->parse(simplexml_import_dom($doc), $tools);
  56.  
  57.         require_once($gJConfig->_pluginsPathList_db[$selector->driver].$selector->driver.'.daobuilder.php');
  58.         $class = $selector->driver.'DaoBuilder';
  59.         $generator = new $class ($selector, $tools, $parser);
  60.  
  61.         // génération des classes PHP correspondant à la définition de la DAO
  62.         $compiled = '<?php '.$generator->buildClasses ()."\n?>";
  63.         jFile::write ($selector->getCompiledFilePath(), $compiled);
  64.         return true;
  65.     }
  66. }
  67.  
  68. /**
  69.  * Exception for Dao compiler
  70.  * @package  jelix
  71.  * @subpackage dao
  72.  */
  73. class jDaoXmlException extends jException {
  74.  
  75.     /**
  76.      * @param jSelectorDao $selector 
  77.      * @param string $localekey a locale key
  78.      * @param array $localeParams parameters for the message (for sprintf)
  79.      */
  80.     public function __construct($selector, $localekey, $localeParams=array()) {
  81.         $localekey= 'jelix~daoxml.'.$localekey;
  82.         $arg=array($selector->toString(), $selector->getPath());
  83.         if(is_array($localeParams)){
  84.             $arg=array_merge($arg, $localeParams);
  85.         }else{
  86.             $arg[]=$localeParams;
  87.         }
  88.         parent::__construct($localekey, $arg);
  89.     }
  90. }

Documentation generated on Mon, 19 Sep 2011 14:12:10 +0200 by phpDocumentor 1.4.3