Changeset 427

Show
Ignore:
Timestamp:
04/27/07 11:55:14 (2 years ago)
Author:
laurentj
Message:

little optimization on jCoordinator

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix/core/jCoordinator.class.php

    r426 r427  
    165165        } 
    166166 
    167  
    168167        // verification du module 
    169168        if(!in_array($this->moduleName,$gJConfig->_trustedModules)){ 
     
    173172        jContext::push ($this->moduleName); 
    174173        try{ 
    175             $this->action = new jSelectorAct($this->actionName); 
     174            $this->action = new jSelectorActFast($this->request->type, $this->moduleName, $this->actionName); 
    176175        }catch(jExceptionSelector $e){ 
    177176            if($e->getCode() == 12){ 
  • trunk/lib/jelix/core/jSelector.class.php

    r425 r427  
    173173} 
    174174 
    175  
    176 /** 
    177  * Action selector 
    178  * 
    179  * main syntax: "module~action@requestType". module should be a valid module name or # (#=says to get 
    180  * the module of the current request). action should be an action name (controller_method). 
    181  * all part are optional, but it should have one part at least. 
    182  * @package    jelix 
    183  * @subpackage core_selector 
    184  */ 
    185 class jSelectorAct extends jSelectorModule { 
     175/** 
     176 * Special Action selector for jcoordinator 
     177 * Don't use it ! Only for internal purpose. 
     178 * @internal 
     179 * @package    jelix 
     180 * @subpackage core_selector 
     181 */ 
     182class jSelectorActFast extends jSelectorModule { 
    186183    protected $type = 'act'; 
    187184    public $request = ''; 
     
    189186    public $method=''; 
    190187    protected $_dirname='actions/'; 
     188 
     189    /** 
     190     */ 
     191    function __construct($request, $module, $action){ 
     192        $this->module = $module; 
     193        $r = explode('_',$action); 
     194        if(count($r) == 1){ 
     195            $this->controller = 'default'; 
     196            $this->method = $r[0]==''?'index':$r[0]; 
     197        }else{ 
     198            $this->controller = $r[0]=='' ? 'default':$r[0]; 
     199            $this->method = $r[1]==''?'index':$r[1]; 
     200        } 
     201        $this->resource = $this->controller.'_'.$this->method; 
     202 
     203        $this->request = $request; 
     204        $this->_createPath(); 
     205    } 
     206 
     207    protected function _createPath(){ 
     208        global $gJConfig; 
     209        if(!isset($gJConfig->_modulesPathList[$this->module])){ 
     210            throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString()); 
     211        }else{ 
     212            $this->_path = $gJConfig->_modulesPathList[$this->module].'controllers/'.$this->controller.'.'.$this->request.'.php'; 
     213        } 
     214    } 
     215 
     216    protected function _createCachePath(){ 
     217        $this->_cachePath = ''; 
     218    } 
     219 
     220    public function toString($full=false){ 
     221        if($full) 
     222            return $this->type.':'.$this->module.'~'.$this->resource.'@'.$this->request; 
     223        else 
     224            return $this->module.'~'.$this->resource.'@'.$this->request; 
     225    } 
     226 
     227    public function getClass(){ 
     228#if ENABLE_OLD_CLASS_NAMING 
     229        $className = $this->controller.'Ctrl'; 
     230        if($GLOBALS['gJConfig']->enableOldClassNaming && !class_exists($className,false)){ 
     231            if(class_exists('CT'.$this->controller,false)) 
     232                $className = 'CT'.$this->controller; 
     233        } 
     234#else 
     235        $className = $this->controller.'Ctrl'; 
     236#endif 
     237        return $className; 
     238    } 
     239 
     240} 
     241 
     242 
     243/** 
     244 * Generic Action selector 
     245 * 
     246 * main syntax: "module~action@requestType". module should be a valid module name or # (#=says to get 
     247 * the module of the current request). action should be an action name (controller_method). 
     248 * all part are optional, but it should have one part at least. 
     249 * @package    jelix 
     250 * @subpackage core_selector 
     251 */ 
     252class jSelectorAct extends jSelectorActFast { 
    191253 
    192254    /** 
     
    244306        } 
    245307    } 
    246  
    247     protected function _createPath(){ 
    248         global $gJConfig; 
    249         if(!isset($gJConfig->_modulesPathList[$this->module])){ 
    250             throw new jExceptionSelector('jelix~errors.selector.module.unknow', $this->toString()); 
    251         }else{ 
    252             $this->_path = $gJConfig->_modulesPathList[$this->module].'controllers/'.$this->controller.'.'.$this->request.'.php'; 
    253         } 
    254     } 
    255  
    256     protected function _createCachePath(){ 
    257         $this->_cachePath = ''; 
    258     } 
    259  
    260     public function toString($full=false){ 
    261         if($full) 
    262             return $this->type.':'.$this->module.'~'.$this->resource.'@'.$this->request; 
    263         else 
    264             return $this->module.'~'.$this->resource.'@'.$this->request; 
    265     } 
    266  
    267     public function getClass(){ 
    268 #if ENABLE_OLD_CLASS_NAMING 
    269         $className = $this->controller.'Ctrl'; 
    270         if($GLOBALS['gJConfig']->enableOldClassNaming && !class_exists($className,false)){ 
    271             if(class_exists('CT'.$this->controller,false)) 
    272                 $className = 'CT'.$this->controller; 
    273         } 
    274 #else 
    275         $className = $this->controller.'Ctrl'; 
    276 #endif 
    277         return $className; 
    278     } 
    279  
    280308} 
    281309 
  • trunk/testapp/modules/unittest/classes/utselectoract.class.php

    r390 r427  
    127127 
    128128    } 
     129 
     130 
     131    function testFastSel() { 
     132        $list=array( 
     133 
     134                array( 
     135                        array('truc', 'testapp', 'ctrl_meth'), 
     136                        array('testapp','ctrl','meth','truc'), 
     137                ), 
     138                array( 
     139                        array('truc', 'testapp', '_meth'), 
     140                        array('testapp','default','meth','truc'), 
     141                ), 
     142                array( 
     143                        array('truc', 'testapp', 'meth'), 
     144                        array('testapp','default','meth','truc'), 
     145                ), 
     146                array( 
     147                        array('truc', 'testapp', 'ctrl_'), 
     148                        array('testapp','ctrl','index','truc'), 
     149                ), 
     150                array( 
     151                        array('truc', 'testapp', 'ctrl_'), 
     152                        array('testapp','ctrl','index','truc'), 
     153                ), 
     154        ); 
     155        foreach($list as $test){ 
     156            list($sel, $res) = $test; 
     157            $valid=true; 
     158            try{ 
     159                $s = new jSelectorActFast($sel[0], $sel[1], $sel[2]); 
     160            }catch(jExceptionSelector $e){ 
     161                $valid=false; 
     162            } 
     163            $msg=''; 
     164            if($valid){ 
     165                $valid = $valid  
     166                && $s->module == $res[0] 
     167                && $s->controller == $res[1] 
     168                && $s->method == $res[2] 
     169                && $s->request == $res[3]; 
     170                if(!$valid) 
     171                    $msg=' contient ces données inattendues ('.$s->module.', '.$s->controller.', '.$s->method.', '.$s->request.')'; 
     172            } 
     173 
     174            $this->assertTrue($valid , ' test de '.$sel. ' (devrait être '.($res === false ? 'invalide':'valide').')'); 
     175            if($msg) 
     176                $this->sendMessage($msg); 
     177        } 
     178 
     179    } 
     180 
     181 
    129182} 
    130183 
Download in other formats: Unified Diff Zip Archive