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-2012 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.         if (!isset(jApp::config()->_modulesPathList[$this->module])) {
  61.             throw new jExceptionSelector('jelix~errors.selector.module.unknown'$this->toString());
  62.         }
  63.         $this->_path = jApp::config()->_modulesPathList[$this->module].$this->_dirname.$this->subpath.$this->className.$this->_suffix;
  64.  
  65.         if (!file_exists($this->_path|| strpos($this->subpath,'..'!== false // second test for security issues
  66.             throw new jExceptionSelector('jelix~errors.selector.invalid.target'array($this->toString()$this->type));
  67.         }
  68.     }
  69.  
  70.     protected function _createCachePath(){
  71.         $this->_cachePath = '';
  72.     }
  73.  
  74.     public function toString($full=false){
  75.         if($full)
  76.             return $this->type.':'.$this->module.'~'.$this->subpath.$this->className;
  77.         else
  78.             return $this->module.'~'.$this->subpath.$this->className;
  79.     }
  80. }

Documentation generated on Mon, 26 Oct 2015 21:56:05 +0100 by phpDocumentor 1.4.3