Changeset 633

Show
Ignore:
Timestamp:
11/09/07 00:16:03 (1 year ago)
Author:
laurentj
Message:

Created a new branch for the new experimental jOrm component

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/experimental/jorm/lib/jelix/core/jSelector.class.php

    r601 r633  
    523523} 
    524524 
     525 
     526/** 
     527 * Selector for orm file 
     528 * syntax : "module~ormName". 
     529 * file : orms/ormName.orm.xml 
     530 * @package    jelix 
     531 * @subpackage core_selector 
     532 */ 
     533class jSelectorOrm extends jSelectorModule { 
     534    protected $type = 'orm'; 
     535    public $driver; 
     536    protected $_dirname = 'orms/'; 
     537    protected $_suffix = '.orm.xml'; 
     538    protected $_where; 
     539 
     540    function __construct($sel, $driver, $isprofil=true){ 
     541        if($isprofil){ 
     542            $p = jDb::getProfil($driver); 
     543            if($p['driver'] == 'pdo'){ 
     544                $this->driver=substr($p['dsn'],0,strpos($p['dsn'],':')); 
     545            }else{ 
     546                $this->driver= $p['driver']; 
     547            } 
     548            if($this->driver=='pgsql') 
     549                $this->driver='postgresql'; 
     550        }else{ 
     551            $this->driver=$driver; 
     552        } 
     553        $this->_compiler='jOrmCompiler'; 
     554        $this->_compilerPath=JELIX_LIB_ORM_PATH.'jOrmCompiler.class.php'; 
     555        parent::__construct($sel); 
     556    } 
     557 
     558    protected function _createPath(){ 
     559        global $gJConfig; 
     560        if(!isset($gJConfig->_modulesPathList[$this->module])){ 
     561            throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString()); 
     562        } 
     563 
     564        // on regarde si le dao a été redéfini 
     565        $overloadedPath = JELIX_APP_VAR_PATH.'overloads/'.$this->module.'/'.$this->_dirname.$this->resource.$this->_suffix; 
     566        if (is_readable ($overloadedPath)){ 
     567           $this->_path = $overloadedPath; 
     568           $this->_where = 'overloaded/'; 
     569           return; 
     570        } 
     571        // et sinon, on regarde si le dao existe dans le module en question 
     572        $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->resource.$this->_suffix; 
     573 
     574        if (!is_readable ($this->_path)){ 
     575            throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "orm")); 
     576        } 
     577        $this->_where = 'modules/'; 
     578    } 
     579 
     580    protected function _createCachePath(){ 
     581        // on ne partage pas le même cache pour tous les emplacements possibles 
     582        // au cas où un overload était supprimé 
     583        $this->_cachePath = JELIX_APP_TEMP_PATH.'compiled/orms/'.$this->_where.$this->module.'~'.$this->resource.'~'.$this->driver.$this->_cacheSuffix; 
     584    } 
     585 
     586    public function getOrmClass(){ 
     587        return 'cOrm_'.$this->module.'_Jx_'.$this->resource.'_Jx_'.$this->driver; 
     588    } 
     589    public function getOrmRecordClass(){ 
     590        return 'cOrmRecord_'.$this->module.'_Jx_'.$this->resource.'_Jx_'.$this->driver; 
     591    } 
     592} 
     593 
     594 
    525595/** 
    526596 * Template selector 
  • branches/experimental/jorm/lib/jelix/core/jSelector.class.php

    r601 r633  
    523523} 
    524524 
     525 
     526/** 
     527 * Selector for orm file 
     528 * syntax : "module~ormName". 
     529 * file : orms/ormName.orm.xml 
     530 * @package    jelix 
     531 * @subpackage core_selector 
     532 */ 
     533class jSelectorOrm extends jSelectorModule { 
     534    protected $type = 'orm'; 
     535    public $driver; 
     536    protected $_dirname = 'orms/'; 
     537    protected $_suffix = '.orm.xml'; 
     538    protected $_where; 
     539 
     540    function __construct($sel, $driver, $isprofil=true){ 
     541        if($isprofil){ 
     542            $p = jDb::getProfil($driver); 
     543            if($p['driver'] == 'pdo'){ 
     544                $this->driver=substr($p['dsn'],0,strpos($p['dsn'],':')); 
     545            }else{ 
     546                $this->driver= $p['driver']; 
     547            } 
     548            if($this->driver=='pgsql') 
     549                $this->driver='postgresql'; 
     550        }else{ 
     551            $this->driver=$driver; 
     552        } 
     553        $this->_compiler='jOrmCompiler'; 
     554        $this->_compilerPath=JELIX_LIB_ORM_PATH.'jOrmCompiler.class.php'; 
     555        parent::__construct($sel); 
     556    } 
     557 
     558    protected function _createPath(){ 
     559        global $gJConfig; 
     560        if(!isset($gJConfig->_modulesPathList[$this->module])){ 
     561            throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString()); 
     562        } 
     563 
     564        // on regarde si le dao a été redéfini 
     565        $overloadedPath = JELIX_APP_VAR_PATH.'overloads/'.$this->module.'/'.$this->_dirname.$this->resource.$this->_suffix; 
     566        if (is_readable ($overloadedPath)){ 
     567           $this->_path = $overloadedPath; 
     568           $this->_where = 'overloaded/'; 
     569           return; 
     570        } 
     571        // et sinon, on regarde si le dao existe dans le module en question 
     572        $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->resource.$this->_suffix; 
     573 
     574        if (!is_readable ($this->_path)){ 
     575            throw new jExceptionSelector('jelix~errors.selector.invalid.target', array($this->toString(), "orm")); 
     576        } 
     577        $this->_where = 'modules/'; 
     578    } 
     579 
     580    protected function _createCachePath(){ 
     581        // on ne partage pas le même cache pour tous les emplacements possibles 
     582        // au cas où un overload était supprimé 
     583        $this->_cachePath = JELIX_APP_TEMP_PATH.'compiled/orms/'.$this->_where.$this->module.'~'.$this->resource.'~'.$this->driver.$this->_cacheSuffix; 
     584    } 
     585 
     586    public function getOrmClass(){ 
     587        return 'cOrm_'.$this->module.'_Jx_'.$this->resource.'_Jx_'.$this->driver; 
     588    } 
     589    public function getOrmRecordClass(){ 
     590        return 'cOrmRecord_'.$this->module.'_Jx_'.$this->resource.'_Jx_'.$this->driver; 
     591    } 
     592} 
     593 
     594 
    525595/** 
    526596 * Template selector 
  • branches/experimental/jorm/lib/jelix/init.php

    r582 r633  
    5252define ('JELIX_LIB_ACL_PATH',     JELIX_LIB_PATH.'acl/'); 
    5353define ('JELIX_LIB_DAO_PATH',     JELIX_LIB_PATH.'dao/'); 
     54define ('JELIX_LIB_ORM_PATH',     JELIX_LIB_PATH.'orm/'); 
    5455define ('JELIX_LIB_EVENTS_PATH',  JELIX_LIB_PATH.'events/'); 
    5556define ('JELIX_LIB_FORMS_PATH',   JELIX_LIB_PATH.'forms/'); 
     
    135136 */ 
    136137$gLibPath=array('Db'=>JELIX_LIB_DB_PATH, 'Dao'=>JELIX_LIB_DAO_PATH, 
     138 'Orm'=>JELIX_LIB_ORM_PATH, 
    137139 'Forms'=>JELIX_LIB_FORMS_PATH, 'Event'=>JELIX_LIB_EVENTS_PATH, 
    138140 'Tpl'=>JELIX_LIB_TPL_PATH, 'Acl'=>JELIX_LIB_ACL_PATH, 'Controller'=>JELIX_LIB_CTRL_PATH); 
     
    142144 */ 
    143145function __autoload($class){ 
    144    if(preg_match('/^j(Dao|Tpl|Acl|Event|Db|Controller|Forms).*$/', $class, $m)){ 
     146   if(preg_match('/^j(Dao|Orm|Tpl|Acl|Event|Db|Controller|Forms).*$/', $class, $m)){ 
    145147       $f=$GLOBALS['gLibPath'][$m[1]].$class.'.class.php'; 
    146148   }elseif(preg_match('/^cDao(?:Record)?_(.+)_Jx_(.+)_Jx_(.+)$/', $class, $m)){ 
    147149       // pour les dao stockés en sessions notament 
    148150       $s = new jSelectorDao($m[1].'~'.$m[2], $m[3], false); 
     151       if($GLOBALS['gJConfig']->compilation['checkCacheFiletime']){ 
     152           // si il faut verifier le filetime, alors on inclus via le jIncluder 
     153           // au cas où il faudrait recompiler le dao avant l'inclusion de la classe 
     154           jIncluder::inc($s); 
     155           return; 
     156       }else{ 
     157          $f = $s->getCompiledFilePath (); 
     158          // on verifie que le fichier est là (dans le cas d'un temp purgé, cf bug #6062) 
     159          if(!file_exists($f)){ // si absent, on recompile 
     160            jIncluder::inc($s); 
     161            return; 
     162          } 
     163       } 
     164   }elseif(preg_match('/^cOrm(?:Record)?_(.+)_Jx_(.+)_Jx_(.+)$/', $class, $m)){ 
     165       // pour les dao stockés en sessions notament 
     166       $s = new jSelectorOrm($m[1].'~'.$m[2], $m[3], false); 
    149167       if($GLOBALS['gJConfig']->compilation['checkCacheFiletime']){ 
    150168           // si il faut verifier le filetime, alors on inclus via le jIncluder 
  • branches/experimental/jorm/lib/jelix/init.php

    r582 r633  
    5252define ('JELIX_LIB_ACL_PATH',     JELIX_LIB_PATH.'acl/'); 
    5353define ('JELIX_LIB_DAO_PATH',     JELIX_LIB_PATH.'dao/'); 
     54define ('JELIX_LIB_ORM_PATH',     JELIX_LIB_PATH.'orm/'); 
    5455define ('JELIX_LIB_EVENTS_PATH',  JELIX_LIB_PATH.'events/'); 
    5556define ('JELIX_LIB_FORMS_PATH',   JELIX_LIB_PATH.'forms/'); 
     
    135136 */ 
    136137$gLibPath=array('Db'=>JELIX_LIB_DB_PATH, 'Dao'=>JELIX_LIB_DAO_PATH, 
     138 'Orm'=>JELIX_LIB_ORM_PATH, 
    137139 'Forms'=>JELIX_LIB_FORMS_PATH, 'Event'=>JELIX_LIB_EVENTS_PATH, 
    138140 'Tpl'=>JELIX_LIB_TPL_PATH, 'Acl'=>JELIX_LIB_ACL_PATH, 'Controller'=>JELIX_LIB_CTRL_PATH); 
     
    142144 */ 
    143145function __autoload($class){ 
    144    if(preg_match('/^j(Dao|Tpl|Acl|Event|Db|Controller|Forms).*$/', $class, $m)){ 
     146   if(preg_match('/^j(Dao|Orm|Tpl|Acl|Event|Db|Controller|Forms).*$/', $class, $m)){ 
    145147       $f=$GLOBALS['gLibPath'][$m[1]].$class.'.class.php'; 
    146148   }elseif(preg_match('/^cDao(?:Record)?_(.+)_Jx_(.+)_Jx_(.+)$/', $class, $m)){ 
    147149       // pour les dao stockés en sessions notament 
    148150       $s = new jSelectorDao($m[1].'~'.$m[2], $m[3], false); 
     151       if($GLOBALS['gJConfig']->compilation['checkCacheFiletime']){ 
     152           // si il faut verifier le filetime, alors on inclus via le jIncluder 
     153           // au cas où il faudrait recompiler le dao avant l'inclusion de la classe 
     154           jIncluder::inc($s); 
     155           return; 
     156       }else{ 
     157          $f = $s->getCompiledFilePath (); 
     158          // on verifie que le fichier est là (dans le cas d'un temp purgé, cf bug #6062) 
     159          if(!file_exists($f)){ // si absent, on recompile 
     160            jIncluder::inc($s); 
     161            return; 
     162          } 
     163       } 
     164   }elseif(preg_match('/^cOrm(?:Record)?_(.+)_Jx_(.+)_Jx_(.+)$/', $class, $m)){ 
     165       // pour les dao stockés en sessions notament 
     166       $s = new jSelectorOrm($m[1].'~'.$m[2], $m[3], false); 
    149167       if($GLOBALS['gJConfig']->compilation['checkCacheFiletime']){ 
    150168           // si il faut verifier le filetime, alors on inclus via le jIncluder 
Download in other formats: Unified Diff Zip Archive