Source for file jSelectorClass.class.php

Documentation is available at jSelectorClass.class.php

  1. <?php
  2. /**
  3. * see jISelector.iface.php for documentation about selectors.
  4. @package     jelix
  5. @subpackage  core_selector
  6. @author      Laurent Jouanneau
  7. @copyright   2005-2007 Laurent Jouanneau
  8. @link        http://www.jelix.org
  9. @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  10. */
  11.  
  12. /**
  13.  * selector for business class
  14.  *
  15.  * business class is a class stored in classname.class.php file in the classes/ module directory
  16.  * or one of its subdirectory.
  17.  * syntax : "module~classname" or "module~classname.
  18.  * @package    jelix
  19.  * @subpackage core_selector
  20.  */
  21. class jSelectorClass extends jSelectorModule {
  22.     protected $type = 'class';
  23.     protected $_dirname = 'classes/';
  24.     protected $_suffix = '.class.php';
  25.  
  26.     /**
  27.     * subpath part in the resource content
  28.     * @since 1.0b2
  29.     */
  30.     public $subpath ='';
  31.     /**
  32.     * the class name specified in the selector
  33.     * @since 1.0b2
  34.     */
  35.     public $className = '';
  36.  
  37.     function __construct($sel){
  38.         if(preg_match("/^(([a-zA-Z0-9_\.]+)~)?([a-zA-Z0-9_\.\\/]+)$/"$sel$m)){
  39.             if($m[1]!='' && $m[2]!=''){
  40.                 $this->module = $m[2];
  41.             }else{
  42.                 $this->module = jContext::get ();
  43.             }
  44.             $this->resource = $m[3];
  45.             if( ($p=strrpos($m[3]'/')) !== false){
  46.                 $this->className = substr($m[3],$p+1);
  47.                 $this->subpath = substr($m[3],0,$p+1);
  48.             }else{
  49.                 $this->className = $m[3];
  50.                 $this->subpath ='';
  51.             }
  52.             $this->_createPath();
  53.             $this->_createCachePath();
  54.         }else{
  55.             throw new jExceptionSelector('jelix~errors.selector.invalid.syntax'array($sel,$this->type));
  56.         }
  57.     }
  58.  
  59.     protected function _createPath(){
  60.         global $gJConfig;
  61.         if (!isset($gJConfig->_modulesPathList[$this->module])) {
  62.             throw new jExceptionSelector('jelix~errors.selector.module.unknown'$this->toString());
  63.         }
  64.         $this->_path = $gJConfig->_modulesPathList[$this->module].$this->_dirname.$this->subpath.$this->className.$this->_suffix;
  65.  
  66.         if (!file_exists($this->_path|| strpos($this->subpath,'..'!== false // second test for security issues
  67.             throw new jExceptionSelector('jelix~errors.selector.invalid.target'array($this->toString()$this->type));
  68.         }
  69.     }
  70.  
  71.     protected function _createCachePath(){
  72.         $this->_cachePath = '';
  73.     }
  74.  
  75.     public function toString($full=false){
  76.         if($full)
  77.             return $this->type.':'.$this->module.'~'.$this->subpath.$this->className;
  78.         else
  79.             return $this->module.'~'.$this->subpath.$this->className;
  80.     }
  81. }

Documentation generated on Wed, 24 Sep 2014 22:01:55 +0200 by phpDocumentor 1.4.3