Source for file jSelectorModule.class.php

Documentation is available at jSelectorModule.class.php

  1. <?php
  2. /**
  3. * see jISelector.iface.php for documentation about selectors. Here abstract class for many selectors
  4. *
  5. @package     jelix
  6. @subpackage  core_selector
  7. @author      Laurent Jouanneau
  8. @copyright   2005-2007 Laurent Jouanneau
  9. @link        http://www.jelix.org
  10. @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  11. */
  12.  
  13. /**
  14.  * base class for all selector concerning module files
  15.  *
  16.  * General syntax for them : "module~resource".
  17.  * Syntax of resource depend on the selector type.
  18.  * module is optional.
  19.  * @package    jelix
  20.  * @subpackage core_selector
  21.  */
  22. abstract class jSelectorModule implements jISelector {
  23.     public $module = null;
  24.     public $resource = null;
  25.  
  26.     protected $type = '_module';
  27.     protected $_dirname='';
  28.     protected $_suffix='';
  29.     protected $_cacheSuffix='.php';
  30.     protected $_path;
  31.     protected $_cachePath;
  32.     protected $_compiler = null;
  33.     protected $_compilerPath;
  34.     protected $_useMultiSourceCompiler=false;
  35.  
  36.     function __construct($sel){
  37.         if(preg_match("/^(([a-zA-Z0-9_\.]+)~)?([a-zA-Z0-9_\.]+)$/"$sel$m)){
  38.             if($m[1]!='' && $m[2]!=''){
  39.                 $this->module = $m[2];
  40.             }else{
  41.                 $this->module = jContext::get ();
  42.             }
  43.             $this->resource = $m[3];
  44.             $this->_createPath();
  45.             $this->_createCachePath();
  46.         }else{
  47.             throw new jExceptionSelector('jelix~errors.selector.invalid.syntax'array($sel,$this->type));
  48.         }
  49.     }
  50.  
  51.     public function getPath (){
  52.         return $this->_path;
  53.     }
  54.  
  55.     public function getCompiledFilePath (){
  56.         return $this->_cachePath;
  57.     }
  58.  
  59.     public function getCompiler(){
  60.         if($this->_compiler == nullreturn null;
  61.         $n $this->_compiler;
  62.         require_once($this->_compilerPath);
  63.         $o new $n();
  64.         return $o;
  65.     }
  66.  
  67.     public function useMultiSourceCompiler(){
  68.         return $this->_useMultiSourceCompiler;
  69.     }
  70.  
  71.     public function toString($full=false){
  72.         if($full)
  73.             return $this->type.':'.$this->module.'~'.$this->resource;
  74.         else
  75.             return $this->module.'~'.$this->resource;
  76.     }
  77.  
  78.     protected function _createPath(){
  79.         global $gJConfig;
  80.         if(!isset($gJConfig->_modulesPathList[$this->module])){
  81.             throw new jExceptionSelector('jelix~errors.selector.module.unknown'$this->toString(true));
  82.         }
  83.         $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->resource.$this->_suffix;
  84.         if (!is_readable ($this->_path)){
  85.             if($this->type == 'loc'){
  86.                 throw new Exception('(202) The file of the locale key "'.$this->toString().'" (charset '.$this->charset.', lang '.$this->locale.') does not exist');
  87.             }elseif($this->toString(== 'jelix~errors.selector.invalid.target'){
  88.                 throw new Exception("Jelix Panic ! don't find localization files to show you an other error message !");
  89.             }else{
  90.                 throw new jExceptionSelector('jelix~errors.selector.invalid.target'array($this->toString()$this->type));
  91.             }
  92.         }
  93.     }
  94.  
  95.     protected function _createCachePath(){
  96.         $this->_cachePath = jApp::tempPath('compiled/'.$this->_dirname.$this->module.'~'.$this->resource.$this->_cacheSuffix);
  97.     }
  98. }

Documentation generated on Mon, 19 Sep 2011 14:13:35 +0200 by phpDocumentor 1.4.3