Source for file jSelector.class.php

Documentation is available at jSelector.class.php

  1. <?php
  2. /**
  3. * Declare all differents classes corresponding to main jelix selectors
  4. *
  5. * a selector is a string refering to a file or a ressource, by indicating its module and its name.
  6. * For example : "moduleName~resourceName". There are several type of selector, depending on the
  7. * resource type. Selector objects get the real path of the corresponding file, the name of the
  8. * compiler (if the file has to be compile) etc.
  9. * So here, there is a selector class for each selector type.
  10. @package     jelix
  11. @subpackage  core_selector
  12. @author      Laurent Jouanneau
  13. @contributor Loic Mathaud
  14. @contributor Rahal
  15. @contributor Thibault PIRONT < nuKs >
  16. @contributor Julien Issler
  17. @contributor Baptiste Toinot
  18. @copyright   2005-2010 Laurent Jouanneau, 2007 Loic Mathaud, 2007 Rahal
  19. @copyright   2007 Thibault PIRONT
  20. @copyright   2008 Julien Issler
  21. @copyright   2008 Baptiste Toinot
  22. @link        http://www.jelix.org
  23. @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  24. */
  25.  
  26. /**
  27. * Create instance of selectors object
  28. @package    jelix
  29. @subpackage core_selector
  30. */
  31. class jSelectorFactory {
  32.     private function __construct(){}
  33.  
  34.     /**
  35.      * Create an instance of a selector object corresponding to the given selector
  36.      * @param string $selstr  the selector. It should be a full selector : "type:module~resource" (not "module~resource")
  37.      * @return jISelector the corresponding selector
  38.      */
  39.     static public function create ($selstr){
  40.         if(preg_match("/^([a-z]{3,5})\:([\w~\/\.]+)$/"$selstr$m)){
  41.             $cname='jSelector'.$m[1];
  42.             if(class_exists($cname)){
  43.                 $sel new $cname($m[2]);
  44.                 return $sel;
  45.             }
  46.         }
  47.         throw new jExceptionSelector('jelix~errors.selector.invalid.syntax'array($selstr,''));
  48.     }
  49. }
  50. /**
  51.  * interface of selector classes
  52.  * @package    jelix
  53.  * @subpackage core_selector
  54.  */
  55. interface jISelector {
  56.     /**
  57.      * @return string file path corresponding to the resource pointing by the selector
  58.      */
  59.     public function getPath ();
  60.     /**
  61.      * @return string file path of the compiled file (if the main file should be compiled by jelix)
  62.      */
  63.     public function getCompiledFilePath ();
  64.     /**
  65.      * @return jICompiler the compiler used to compile file
  66.      */
  67.     public function getCompiler();
  68.     /**
  69.      * @return boolean true if the compiler compile many file at one time
  70.      */
  71.     public function useMultiSourceCompiler();
  72.     /**
  73.      * @param boolean $full true if you want a full selector ("type:...")
  74.      * @return string the selector
  75.      */
  76.     public function toString($full=false);
  77. }
  78.  
  79. /**
  80.  * Exception for selector errors
  81.  * @package    jelix
  82.  * @subpackage core_selector
  83.  */
  84. class jExceptionSelector extends jException }
  85.  
  86. /**
  87.  * base class for all selector concerning module files
  88.  *
  89.  * General syntax for them : "module~resource".
  90.  * Syntax of resource depend on the selector type.
  91.  * module is optional.
  92.  * @package    jelix
  93.  * @subpackage core_selector
  94.  */
  95. abstract class jSelectorModule implements jISelector {
  96.     public $module = null;
  97.     public $resource = null;
  98.  
  99.     protected $type = '_module';
  100.     protected $_dirname='';
  101.     protected $_suffix='';
  102.     protected $_cacheSuffix='.php';
  103.     protected $_path;
  104.     protected $_cachePath;
  105.     protected $_compiler = null;
  106.     protected $_compilerPath;
  107.     protected $_useMultiSourceCompiler=false;
  108.  
  109.     function __construct($sel){
  110.         if(preg_match("/^(([a-zA-Z0-9_\.]+)~)?([a-zA-Z0-9_\.]+)$/"$sel$m)){
  111.             if($m[1]!='' && $m[2]!=''){
  112.                 $this->module = $m[2];
  113.             }else{
  114.                 $this->module = jContext::get ();
  115.             }
  116.             $this->resource = $m[3];
  117.             $this->_createPath();
  118.             $this->_createCachePath();
  119.         }else{
  120.             throw new jExceptionSelector('jelix~errors.selector.invalid.syntax'array($sel,$this->type));
  121.         }
  122.     }
  123.  
  124.     public function getPath (){
  125.         return $this->_path;
  126.     }
  127.  
  128.     public function getCompiledFilePath (){
  129.         return $this->_cachePath;
  130.     }
  131.  
  132.     public function getCompiler(){
  133.         if($this->_compiler == nullreturn null;
  134.         $n $this->_compiler;
  135.         require_once($this->_compilerPath);
  136.         $o new $n();
  137.         return $o;
  138.     }
  139.  
  140.     public function useMultiSourceCompiler(){
  141.         return $this->_useMultiSourceCompiler;
  142.     }
  143.  
  144.     public function toString($full=false){
  145.         if($full)
  146.             return $this->type.':'.$this->module.'~'.$this->resource;
  147.         else
  148.             return $this->module.'~'.$this->resource;
  149.     }
  150.  
  151.     protected function _createPath(){
  152.         global $gJConfig;
  153.         if(!isset($gJConfig->_modulesPathList[$this->module])){
  154.             throw new jExceptionSelector('jelix~errors.selector.module.unknow'$this->toString(true));
  155.         }
  156.         $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->resource.$this->_suffix;
  157.         if (!is_readable ($this->_path)){
  158.             if($this->type == 'loc'){
  159.                 throw new Exception('(202) The file of the locale key "'.$this->toString().'" (charset '.$this->charset.', lang '.$this->locale.') does not exist');
  160.             }elseif($this->toString(== 'jelix~errors.selector.invalid.target'){
  161.                 throw new Exception("Jelix Panic ! don't find localization files to show you an other error message !");
  162.             }else{
  163.                 throw new jExceptionSelector('jelix~errors.selector.invalid.target'array($this->toString()$this->type));
  164.             }
  165.         }
  166.     }
  167.  
  168.     protected function _createCachePath(){
  169.         $this->_cachePath = JELIX_APP_TEMP_PATH.'compiled/'.$this->_dirname.$this->module.'~'.$this->resource.$this->_cacheSuffix;
  170.     }
  171. }
  172.  
  173. /**
  174.  * Special Action selector for jcoordinator
  175.  * Don't use it ! Only for internal purpose.
  176.  * @internal
  177.  * @package    jelix
  178.  * @subpackage core_selector
  179.  */
  180. class jSelectorActFast extends jSelectorModule {
  181.     protected $type = 'act';
  182.     public $request = '';
  183.     public $controller = '';
  184.     public $method='';
  185.     protected $_dirname='actions/';
  186.  
  187.     /**
  188.      */
  189.     function __construct($request$module$action){
  190.         $this->module = $module;
  191.         if($GLOBALS['gJConfig']->enableOldActionSelector == false || strpos($action,':'!== false)
  192.             $separator ':';
  193.         else
  194.             $separator '_';
  195.         $r explode($separator,$action);
  196.         if(count($r== 1){
  197.             $this->controller = 'default';
  198.             $this->method = $r[0]==''?'index':$r[0];
  199.         }else{
  200.             $this->controller = $r[0]=='' 'default':$r[0];
  201.             $this->method = $r[1]==''?'index':$r[1];
  202.         }
  203.         $this->resource = $this->controller.':'.$this->method;
  204.         $this->request = $request;
  205.         $this->_createPath();
  206.     }
  207.  
  208.     protected function _createPath(){
  209.         global $gJConfig;
  210.         if(!isset($gJConfig->_modulesPathList[$this->module])){
  211.             throw new jExceptionSelector('jelix~errors.selector.module.unknow'$this->toString());
  212.         }else{
  213.             $this->_path = $gJConfig->_modulesPathList[$this->module].'controllers/'.$this->controller.'.'.$this->request.'.php';
  214.         }
  215.     }
  216.  
  217.     protected function _createCachePath(){
  218.         $this->_cachePath = '';
  219.     }
  220.  
  221.     public function toString($full=false){
  222.         if($full)
  223.             return $this->type.':'.$this->module.'~'.$this->resource.'@'.$this->request;
  224.         else
  225.             return $this->module.'~'.$this->resource.'@'.$this->request;
  226.     }
  227.  
  228.     public function getClass(){
  229.         $className $this->controller.'Ctrl';
  230.         return $className;
  231.     }
  232.  
  233. }
  234.  
  235.  
  236. /**
  237.  * Generic Action selector
  238.  *
  239.  * main syntax: "module~action@requestType". module should be a valid module name or # (#=says to get
  240.  * the module of the current request). action should be an action name (controller:method or controller_method).
  241.  * all part are optional, but it should have one part at least.
  242.  * @package    jelix
  243.  * @subpackage core_selector
  244.  */
  245. class jSelectorAct extends jSelectorActFast {
  246.  
  247.     /**
  248.      * @param string $sel  the selector
  249.      * @param boolean $enableRequestPart true if the selector can contain the request part
  250.      */
  251.     function __construct($sel$enableRequestPart false){
  252.         global $gJCoord;
  253.  
  254.         if(preg_match("/^(?:([a-zA-Z0-9_\.]+|\#)~)?([a-zA-Z0-9_:]+|\#)?(?:@([a-zA-Z0-9_]+))?$/"$sel$m)){
  255.             $m=array_pad($m,4,'');
  256.             if($m[1]!=''){
  257.                 if($m[1== '#')
  258.                     $this->module = $gJCoord->moduleName;
  259.                 else
  260.                     $this->module = $m[1];
  261.             }else{
  262.                 $this->module = jContext::get ();
  263.             }
  264.             if($m[2== '#')
  265.                 $this->resource = $gJCoord->actionName;
  266.             else
  267.                 $this->resource = $m[2];
  268.             if($GLOBALS['gJConfig']->enableOldActionSelector == false || strpos($this->resource,':'!== false)
  269.                 $r explode(':',$this->resource);
  270.             else
  271.                 $r explode('_',$this->resource);
  272.             if(count($r== 1){
  273.                 $this->controller = 'default';
  274.                 $this->method = $r[0]==''?'index':$r[0];
  275.             }else{
  276.                 $this->controller = $r[0]=='' 'default':$r[0];
  277.                 $this->method = $r[1]==''?'index':$r[1];
  278.             }
  279.             $this->resource = $this->controller.':'.$this->method;
  280.  
  281.             if($m[3!= '' && $enableRequestPart)
  282.                 $this->request = $m[3];
  283.             else
  284.                 $this->request = $gJCoord->request->type;
  285.             $this->_createPath();
  286.         }else{
  287.             throw new jExceptionSelector('jelix~errors.selector.invalid.syntax'array($sel,$this->type));
  288.         }
  289.     }
  290. }
  291.  
  292. /**
  293.  * selector for business class
  294.  *
  295.  * business class is a class stored in classname.class.php file in the classes/ module directory
  296.  * or one of its subdirectory.
  297.  * syntax : "module~classname" or "module~classname.
  298.  * @package    jelix
  299.  * @subpackage core_selector
  300.  */
  301. class jSelectorClass extends jSelectorModule {
  302.     protected $type = 'class';
  303.     protected $_dirname = 'classes/';
  304.     protected $_suffix = '.class.php';
  305.  
  306.     /**
  307.     * subpath part in the resource content
  308.     * @since 1.0b2
  309.     */
  310.     public $subpath ='';
  311.     /**
  312.     * the class name specified in the selector
  313.     * @since 1.0b2
  314.     */
  315.     public $className = '';
  316.  
  317.     function __construct($sel){
  318.         if(preg_match("/^(([a-zA-Z0-9_\.]+)~)?([a-zA-Z0-9_\.\\/]+)$/"$sel$m)){
  319.             if($m[1]!='' && $m[2]!=''){
  320.                 $this->module = $m[2];
  321.             }else{
  322.                 $this->module = jContext::get ();
  323.             }
  324.             $this->resource = $m[3];
  325.             if( ($p=strrpos($m[3]'/')) !== false){
  326.                 $this->className = substr($m[3],$p+1);
  327.                 $this->subpath = substr($m[3],0,$p+1);
  328.             }else{
  329.                 $this->className = $m[3];
  330.                 $this->subpath ='';
  331.             }
  332.             $this->_createPath();
  333.             $this->_createCachePath();
  334.         }else{
  335.             throw new jExceptionSelector('jelix~errors.selector.invalid.syntax'array($sel,$this->type));
  336.         }
  337.     }
  338.  
  339.     protected function _createPath(){
  340.         global $gJConfig;
  341.         if (!isset($gJConfig->_modulesPathList[$this->module])) {
  342.             throw new jExceptionSelector('jelix~errors.selector.module.unknow'$this->toString());
  343.         }
  344.         $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->subpath.$this->className.$this->_suffix;
  345.  
  346.         if (!file_exists($this->_path|| strpos($this->subpath,'..'!== false // second test for security issues
  347.             throw new jExceptionSelector('jelix~errors.selector.invalid.target'array($this->toString()$this->type));
  348.         }
  349.     }
  350.  
  351.     protected function _createCachePath(){
  352.         $this->_cachePath = '';
  353.     }
  354.  
  355.     public function toString($full=false){
  356.         if($full)
  357.             return $this->type.':'.$this->module.'~'.$this->subpath.$this->className;
  358.         else
  359.             return $this->module.'~'.$this->subpath.$this->className;
  360.     }
  361. }
  362.  
  363. /**
  364.  * selector for interface
  365.  *
  366.  * interface is stored in interfacename.iface.php file in the classes/ module directory
  367.  * or one of its subdirectory.
  368.  * syntax : "iface:module~ifacename" or "module~ifacename.
  369.  * @package    jelix
  370.  * @subpackage core_selector
  371.  * @since 1.0.3
  372.  */
  373. class jSelectorIface extends jSelectorClass {
  374.     protected $type = 'iface';
  375.     protected $_dirname = 'classes/';
  376.     protected $_suffix = '.iface.php';
  377. }
  378.  
  379. /**
  380.  * selector for interface
  381.  * @package    jelix
  382.  * @subpackage core_selector
  383.  * @since 1.0b2
  384.  * @deprecated
  385.  */
  386. class jSelectorInterface extends jSelectorIface {}
  387.  
  388. /**
  389.  * selector for localisation string
  390.  *
  391.  * localisation string are stored in file properties.
  392.  * syntax : "module~prefixFile.keyString".
  393.  * Corresponding file : locales/xx_XX/prefixFile.CCC.properties.
  394.  * xx_XX and CCC are lang and charset set in the configuration
  395.  *
  396.  * @package    jelix
  397.  * @subpackage core_selector
  398.  */
  399. class jSelectorLoc extends jSelectorModule {
  400.     protected $type = 'loc';
  401.     public $fileKey = '';
  402.     public $messageKey = '';
  403.     public $locale ='';
  404.     public $charset='';
  405.     public $_compiler = 'jLocalesCompiler';
  406.     protected $_where;
  407.  
  408.     function __construct($sel$locale=null$charset=null){
  409.         global $gJConfig;
  410.         if ($locale === null){
  411.             $locale $gJConfig->locale;
  412.         }
  413.         if ($charset === null){
  414.             $charset $gJConfig->charset;
  415.         }
  416.         if(strpos($locale,'_'=== false){
  417.             $locale.='_'.strtoupper($locale);
  418.         }
  419.         $this->locale = $locale;
  420.         $this->charset = $charset;
  421.         $this->_suffix = '.'.$charset.'.properties';
  422.         $this->_compilerPath=JELIX_LIB_CORE_PATH.'jLocalesCompiler.class.php';
  423.  
  424.         if(preg_match("/^(([a-zA-Z0-9_\.]+)~)?([a-zA-Z0-9_]+)\.([a-zA-Z0-9_\.]+)$/"$sel$m)){
  425.             if($m[1]!='' && $m[2]!=''){
  426.                 $this->module = $m[2];
  427.             }else{
  428.                 $this->module = jContext::get ();
  429.             }
  430.             $this->resource = $m[3];
  431.             $this->fileKey = $m[3];
  432.             $this->messageKey = $m[4];
  433.             $this->_createPath();
  434.             $this->_createCachePath();
  435.         }else{
  436.             throw new jExceptionSelector('jelix~errors.selector.invalid.syntax'array($sel,$this->type));
  437.         }
  438.     }
  439.  
  440.     protected function _createPath(){
  441.         global $gJConfig;
  442.         if(!isset($gJConfig->_modulesPathList[$this->module])){
  443.             if ($this->module == 'jelix')
  444.                 throw new Exception('jelix module is not enabled !!');
  445.             throw new jExceptionSelector('jelix~errors.selector.module.unknow'$this->toString());
  446.         }
  447.  
  448.         $locales array($this->locale);
  449.         $lang substr($this->locale,0,2);
  450.         $generic_locale $lang.'_'.strtoupper($lang);
  451.         if($this->locale !== $generic_locale)
  452.             $locales[$generic_locale;
  453.  
  454.         foreach($locales as $locale){
  455.             // check if the locale has been overloaded
  456.             $overloadedPath JELIX_APP_VAR_PATH.'overloads/'.$this->module.'/locales/'.$locale.'/'.$this->resource.$this->_suffix;
  457.             if (is_readable ($overloadedPath)){
  458.                 $this->_path = $overloadedPath;
  459.                 $this->_where = 'overloaded/';
  460.                 $this->_cacheSuffix = '.'.$locale.'.'.$this->charset.'.php';
  461.                 return;
  462.             }
  463.             // else check for the original locale file
  464.             $path $gJConfig->_modulesPathList[$this->module].'locales/'.$locale.'/'.$this->resource.$this->_suffix;
  465.             if (is_readable ($path)){
  466.                 $this->_where = 'modules/';
  467.                 $this->_path = $path;
  468.                 $this->_cacheSuffix = '.'.$locale.'.'.$this->charset.'.php';
  469.                 return;
  470.             }
  471.         }
  472.  
  473.         // to avoid infinite loop in a specific lang or charset, we should check if we don't
  474.         // try to retrieve the same message as the one we use for the exception below,
  475.         // and if it is this message, it means that the error message doesn't exist
  476.         // in the specific lang or charset, so we retrieve it in en_EN language and UTF-8 charset
  477.         if($this->toString(== 'jelix~errors.selector.invalid.target'){
  478.             $l 'en_EN';
  479.             $c 'UTF-8';
  480.         }
  481.         else{
  482.             $l null;
  483.             $c null;
  484.         }
  485.         throw new jExceptionSelector('jelix~errors.selector.invalid.target'array($this->toString()"locale")1$l$c);
  486.     }
  487.  
  488.     protected function _createCachePath(){
  489.         // on ne partage pas le même cache pour tous les emplacements possibles
  490.         // au cas où un overload était supprimé
  491.         $this->_cachePath = JELIX_APP_TEMP_PATH.'compiled/locales/'.$this->_where.$this->module.'~'.$this->resource.$this->_cacheSuffix;
  492.     }
  493.  
  494.     public function toString($full=false){
  495.         if($full)
  496.             return $this->type.':'.$this->module.'~'.$this->fileKey.'.'.$this->messageKey;
  497.         else
  498.             return $this->module.'~'.$this->fileKey.'.'.$this->messageKey;
  499.     }
  500. }
  501.  
  502. /**
  503.  * Selector for dao file
  504.  * syntax : "module~daoName".
  505.  * file : daos/daoName.dao.xml
  506.  * @package    jelix
  507.  * @subpackage core_selector
  508.  */
  509. class jSelectorDao extends jSelectorModule {
  510.     protected $type = 'dao';
  511.     public $driver;
  512.     protected $_dirname = 'daos/';
  513.     protected $_suffix = '.dao.xml';
  514.     protected $_where;
  515.  
  516.     function __construct($sel$driver$isprofil=true){
  517.         if($isprofil){
  518.             $p jDb::getProfil($driver);
  519.             if($p['driver'== 'pdo'){
  520.                 $this->driver=substr($p['dsn'],0,strpos($p['dsn'],':'));
  521.             }else{
  522.                 $this->driver$p['driver'];
  523.             }
  524.         }else{
  525.             $this->driver=$driver;
  526.         }
  527.         $this->_compiler='jDaoCompiler';
  528.         $this->_compilerPath=JELIX_LIB_DAO_PATH.'jDaoCompiler.class.php';
  529.         parent::__construct($sel);
  530.     }
  531.  
  532.     protected function _createPath(){
  533.         global $gJConfig;
  534.         if(!isset($gJConfig->_modulesPathList[$this->module])){
  535.             throw new jExceptionSelector('jelix~errors.selector.module.unknow'$this->toString());
  536.         }
  537.  
  538.         // on regarde si le dao a été redéfini
  539.         $overloadedPath JELIX_APP_VAR_PATH.'overloads/'.$this->module.'/'.$this->_dirname.$this->resource.$this->_suffix;
  540.         if (is_readable ($overloadedPath)){
  541.            $this->_path = $overloadedPath;
  542.            $this->_where = 'overloaded/';
  543.            return;
  544.         }
  545.         // et sinon, on regarde si le dao existe dans le module en question
  546.         $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->resource.$this->_suffix;
  547.  
  548.         if (!is_readable ($this->_path)){
  549.             throw new jExceptionSelector('jelix~errors.selector.invalid.target'array($this->toString()"dao"));
  550.         }
  551.         $this->_where = 'modules/';
  552.     }
  553.  
  554.     protected function _createCachePath(){
  555.         // on ne partage pas le même cache pour tous les emplacements possibles
  556.         // au cas où un overload était supprimé
  557.         $this->_cachePath = JELIX_APP_TEMP_PATH.'compiled/daos/'.$this->_where.$this->module.'~'.$this->resource.'~'.$this->driver.$this->_cacheSuffix;
  558.     }
  559.  
  560.     public function getDaoClass(){
  561.         return 'cDao_'.$this->module.'_Jx_'.$this->resource.'_Jx_'.$this->driver;
  562.     }
  563.     public function getDaoRecordClass(){
  564.         return 'cDaoRecord_'.$this->module.'_Jx_'.$this->resource.'_Jx_'.$this->driver;
  565.     }
  566. }
  567.  
  568. /**
  569.  * Template selector
  570.  *
  571.  * syntax : "module~tplName".
  572.  * file : templates/tplName.tpl .
  573.  * @package    jelix
  574.  * @subpackage core_selector
  575.  */
  576. class jSelectorTpl extends jSelectorModule {
  577.     protected $type = 'tpl';
  578.     protected $_dirname = 'templates/';
  579.     protected $_suffix = '.tpl';
  580.     protected $_where;
  581.     public $outputType='';
  582.     public $trusted=true;
  583.  
  584.     /**
  585.      * @param string $sel the template selector
  586.      * @param string $outputtype  the type of output (html, text..) By default, it takes the response type
  587.      * @param boolean $trusted  says if the template file is trusted or not
  588.      */
  589.     function __construct($sel$outputtype=''$trusted=true){
  590.         if($outputtype == ''{
  591.             if($GLOBALS['gJCoord']->response)
  592.                 $this->outputType = $GLOBALS['gJCoord']->response->getFormatType();
  593.             else
  594.                 $this->outputType = $GLOBALS['gJCoord']->request->defaultResponseType;
  595.         else
  596.             $this->outputType = $outputtype;
  597.         $this->trusted = $trusted;
  598.         $this->_compiler='jTplCompiler';
  599.         $this->_compilerPath=JELIX_LIB_TPL_PATH.'jTplCompiler.class.php';
  600.         parent::__construct($sel);
  601.     }
  602.  
  603.     protected function _createPath(){
  604.         global $gJConfig;
  605.         if(!isset($gJConfig->_modulesPathList[$this->module])){
  606.             throw new jExceptionSelector('jelix~errors.selector.module.unknow'$this->toString());
  607.         }
  608.  
  609.         $path $this->module.'/'.$this->resource;
  610.         $lpath $this->module.'/'.$gJConfig->locale.'/'.$this->resource;
  611.  
  612.         if($gJConfig->theme != 'default'){
  613.             // on regarde si il y a un template redéfinie pour le theme courant
  614.             $this->_where = 'themes/'.$gJConfig->theme.'/'.$lpath;
  615.             $this->_path = JELIX_APP_VAR_PATH.$this->_where.'.tpl';
  616.             if (is_readable ($this->_path)){
  617.                 return;
  618.             }
  619.             // on regarde si il y a un template redéfinie pour le theme courant
  620.             $this->_where = 'themes/'.$gJConfig->theme.'/'.$path;
  621.             $this->_path = JELIX_APP_VAR_PATH.$this->_where.'.tpl';
  622.             if (is_readable ($this->_path)){
  623.                 return;
  624.             }
  625.         }
  626.  
  627.         // on regarde si il y a un template redéfinie dans le theme par defaut
  628.         $this->_where = 'themes/default/'.$lpath;
  629.         $this->_path = JELIX_APP_VAR_PATH.$this->_where.'.tpl';
  630.         if (is_readable ($this->_path)){
  631.             return;
  632.         }
  633.  
  634.         $this->_where = 'themes/default/'.$path;
  635.         $this->_path = JELIX_APP_VAR_PATH.$this->_where.'.tpl';
  636.         if (is_readable ($this->_path)){
  637.             return;
  638.         }
  639.  
  640.         // et sinon, on regarde si le template existe dans le module en question
  641.         $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$gJConfig->locale.'/'.$this->resource.'.tpl';
  642.         if (is_readable ($this->_path)){
  643.             $this->_where = 'modules/'.$lpath;
  644.             return;
  645.         }
  646.  
  647.         $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->resource.'.tpl';
  648.         if (is_readable ($this->_path)){
  649.             $this->_where = 'modules/'.$path;
  650.             return;
  651.         }
  652.  
  653.         throw new jExceptionSelector('jelix~errors.selector.invalid.target'array($this->toString()"template"));
  654.  
  655.     }
  656.  
  657.     protected function _createCachePath(){
  658.        // on ne partage pas le même cache pour tous les emplacements possibles
  659.        // au cas où un overload était supprimé
  660.        $this->_cachePath = JELIX_APP_TEMP_PATH.'compiled/templates/'.$this->_where.'_'.$this->outputType.($this->trusted?'_t':'').$this->_cacheSuffix;
  661.     }
  662. }
  663.  
  664. /**
  665.  * Zone selector
  666.  *
  667.  * syntax : "module~zoneName".
  668.  * file : zones/zoneName.zone.php .
  669.  * @package    jelix
  670.  * @subpackage core_selector
  671.  */
  672. class jSelectorZone extends jSelectorModule {
  673.     protected $type = 'zone';
  674.     protected $_dirname = 'zones/';
  675.     protected $_suffix = '.zone.php';
  676.  
  677.     protected function _createCachePath(){
  678.         $this->_cachePath = '';
  679.     }
  680. }
  681.  
  682. /**
  683.  * Form selector
  684.  *
  685.  * syntax : "module~formName".
  686.  * file : forms/formName.form.xml .
  687.  * @package    jelix
  688.  * @subpackage core_selector
  689.  */
  690. class jSelectorForm extends jSelectorModule {
  691.     protected $type = 'form';
  692.     protected $_where;
  693.     protected $_dirname = 'forms/';
  694.     protected $_suffix = '.form.xml';
  695.  
  696.     function __construct($sel){
  697.  
  698.         $this->_compiler='jFormsCompiler';
  699.         $this->_compilerPath=JELIX_LIB_FORMS_PATH.'jFormsCompiler.class.php';
  700.  
  701.         parent::__construct($sel);
  702.     }
  703.  
  704.     public function getClass(){
  705.         return 'cForm_'.$this->module.'_Jx_'.$this->resource;
  706.     }
  707.  
  708.  
  709.     protected function _createPath(){
  710.         global $gJConfig;
  711.         if(!isset($gJConfig->_modulesPathList[$this->module])){
  712.             throw new jExceptionSelector('jelix~errors.selector.module.unknow'$this->toString(true));
  713.         }
  714.  
  715.         // we see if the forms have been redefined
  716.         $overloadedPath JELIX_APP_VAR_PATH.'overloads/'.$this->module.'/'.$this->_dirname.$this->resource.$this->_suffix;
  717.         if (is_readable ($overloadedPath)){
  718.            $this->_path = $overloadedPath;
  719.            $this->_where = 'overloaded/';
  720.            return;
  721.         }
  722.  
  723.         $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->resource.$this->_suffix;
  724.         if (!is_readable ($this->_path)){
  725.             throw new jExceptionSelector('jelix~errors.selector.invalid.target'array($this->toString()$this->type));
  726.         }
  727.         $this->_where = 'modules/';
  728.     }
  729.  
  730.     protected function _createCachePath(){
  731.         // on ne partage pas le même cache pour tous les emplacements possibles
  732.         // au cas où un overload était supprimé
  733.         $this->_cachePath = JELIX_APP_TEMP_PATH.'compiled/'.$this->_dirname.$this->_where.$this->module.'~'.$this->resource.$this->_cacheSuffix;
  734.     }
  735.  
  736.     public function getCompiledBuilderFilePath ($type){
  737.         return JELIX_APP_TEMP_PATH.'compiled/'.$this->_dirname.$this->_where.$this->module.'~'.$this->resource.'_builder_'.$type.$this->_cacheSuffix;
  738.     }
  739.  
  740. }
  741.  
  742. /**
  743.  * base class for simple file selector
  744.  * @package    jelix
  745.  * @subpackage core_selector
  746.  */
  747. class jSelectorSimpleFile implements jISelector {
  748.     protected $type = 'simplefile';
  749.     public $file = '';
  750.     protected $_path;
  751.     protected $_basePath='';
  752.  
  753.     function __construct($sel){
  754.         if(preg_match("/^([\w\.\/]+)$/"$sel$m)){
  755.             $this->file = $m[1];
  756.             $this->_path = $this->_basePath.$m[1];
  757.         }else{
  758.             throw new jExceptionSelector('jelix~errors.selector.invalid.syntax'array($sel,$this->type));
  759.         }
  760.     }
  761.  
  762.     public function getPath (){
  763.         return $this->_path;
  764.     }
  765.  
  766.     public function toString($full=false){
  767.         if($full)
  768.             return $this->type.':'.$this->file;
  769.         else
  770.             return $this->file;
  771.     }
  772.     public function getCompiler()return null;}
  773.     public function useMultiSourceCompiler(return false;}
  774.     public function getCompiledFilePath ()return '';}
  775. }
  776.  
  777. /**
  778.  * Selector for files stored in the var directory
  779.  *
  780.  * @package    jelix
  781.  * @subpackage core_selector
  782.  */
  783. class jSelectorVar extends jSelectorSimpleFile {
  784.     protected $type = 'var';
  785.     function __construct($sel){
  786.         $this->_basePath = JELIX_APP_VAR_PATH;
  787.         parent::__construct($sel);
  788.     }
  789. }
  790.  
  791. /**
  792.  * Selector for files stored in the config directory
  793.  *
  794.  * @package    jelix
  795.  * @subpackage core_selector
  796.  */
  797. class jSelectorCfg extends jSelectorSimpleFile {
  798.     protected $type = 'cfg';
  799.     function __construct($sel){
  800.         $this->_basePath = JELIX_APP_CONFIG_PATH;
  801.         parent::__construct($sel);
  802.     }
  803. }
  804.  
  805. /**
  806.  * Selector for files stored in the temp directory
  807.  *
  808.  * @package    jelix
  809.  * @subpackage core_selector
  810.  */
  811. class jSelectorTmp extends jSelectorSimpleFile {
  812.     protected $type = 'tmp';
  813.     function __construct($sel){
  814.         $this->_basePath = JELIX_APP_TEMP_PATH;
  815.         parent::__construct($sel);
  816.     }
  817. }
  818.  
  819. /**
  820.  * Selector for files stored in the log directory
  821.  *
  822.  * @package    jelix
  823.  * @subpackage core_selector
  824.  */
  825. class jSelectorLog extends jSelectorSimpleFile {
  826.     protected $type = 'log';
  827.     function __construct($sel){
  828.         $this->_basePath = JELIX_APP_LOG_PATH;
  829.         parent::__construct($sel);
  830.     }
  831. }
  832.  
  833. /**
  834.  * Selector for files stored in the lib directory
  835.  *
  836.  * @package    jelix
  837.  * @subpackage core_selector
  838.  */
  839. class jSelectorLib extends jSelectorSimpleFile {
  840.     protected $type = 'lib';
  841.     function __construct($sel){
  842.         $this->_basePath = LIB_PATH;
  843.         parent::__construct($sel);
  844.     }
  845. }
  846.  
  847. ?>

Documentation generated on Wed, 07 Sep 2011 13:47:58 +0200 by phpDocumentor 1.4.3