Ignore:
Timestamp:
08/22/10 19:35:26 (21 months ago)
Author:
vain
Message:
  • fix bugs on subcontroller recognition and enabled subcontroller dispatching
  • added method dispatchable() to test the routing, before dispatching
  • added method reset() to set default values to the TargetRoute? object
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/router.core.php

    r4578 r4597  
    237237 
    238238        /** 
    239          * if there are no uri segments, loading routes and matching is pointless 
    240          * return the default route 
     239         * If there are no uri segments, loading routes and matching is pointless. 
     240         * Dispatch to the default route! 
    241241         */ 
    242242        if(empty($this->uri) or $this->uri === '/') 
     
    245245            Clansuite_TargetRoute::setAction('show'); 
    246246 
    247             return Clansuite_TargetRoute::getInstance(); 
     247            if(Clansuite_TargetRoute::dispatchable() === true) 
     248            { 
     249                return Clansuite_TargetRoute::getInstance(); 
     250            } 
    248251        } 
    249252 
     
    269272    public function mapMatchURI() 
    270273    { 
    271         Clansuite_Debug::firebug($this->uri); 
     274        #Clansuite_Debug::firebug($this->uri); 
    272275 
    273276        /** 
     
    287290                $uri = implode('/', $this->uri_segments); 
    288291 
    289                 Clansuite_Debug::firebug($route_values); 
     292                #Clansuite_Debug::firebug($route_values); 
    290293 
    291294                /** 
     
    296299                if (1 === preg_match('/^:([a-zA-Z_]+)$/', $uri, $match)) 
    297300                { 
    298                     Clansuite_Debug::firebug($match); 
     301                    #Clansuite_Debug::firebug($match); 
    299302                    $name = $match[1]; #setController($match[1]); 
    300303                    $found_route = $name; 
     
    304307                elseif(1 === preg_match( $route_values['regexp'], $uri, $matches)) 
    305308                { 
    306                     Clansuite_Debug::firebug($matches); 
     309                    #Clansuite_Debug::firebug($matches); 
    307310 
    308311                    # parameters found by regular expression have priority 
     
    312315                    } 
    313316 
     317                    if(isset($matches['subcontroller'])) 
     318                    { 
     319                        Clansuite_TargetRoute::setSubController($matches['subcontroller']); 
     320                    } 
     321 
    314322                    if(isset($matches['action'])) 
    315323                    { 
     
    323331                } 
    324332 
    325                 # route found 
    326                 break; 
     333                if(Clansuite_TargetRoute::dispatchable() === true) 
     334                { 
     335                    # route found 
     336                    break; 
     337                } 
     338                else 
     339                { 
     340                    Clansuite_TargetRoute::reset(); 
     341                } 
    327342            } 
    328343        } 
     
    639654            $this->addRoute('/:controller/:action/:id'); 
    640655            $this->addRoute('/:controller/:action/:id/:format'); 
    641             /* 
     656 
    642657            $this->addRoute('/:controller/:subcontroller'); 
    643658            $this->addRoute('/:controller/:subcontroller/:action'); 
    644659            $this->addRoute('/:controller/:subcontroller/:action/:id'); 
    645660            $this->addRoute('/:controller/:subcontroller/:action/:id/:format'); 
    646             */ 
    647661        } 
    648662    } 
     
    725739 
    726740        # subcontroller 
    727         if('admin' == $subcontroller) 
     741        if(isset($subcontroller) and 'admin' == $subcontroller) 
    728742        { 
    729743            $filename_postfix = '.admin.php'; 
    730744        } 
    731         else 
     745        elseif(isset($subcontroller) and $subcontroller != 'admin') # any subcontroller name as postfix 
     746        { 
     747            $filename_postifx = '.'.$subcontroller.'.php'; 
     748        } 
     749        else # apply standard postfix 
    732750        { 
    733751            $filename_postfix = '.module.php'; 
     
    789807            $action = $submodule . '_' . $action; 
    790808        } 
    791  
    792         #Clansuite_Debug::firebug($action); 
    793809 
    794810        # all clansuite actions are prefixed with 'action_' 
     
    844860    public static function getFilename() 
    845861    { 
    846         if(empty(self::$parameters['filename'])) 
    847         { 
     862        #if(empty(self::$parameters['filename'])) 
     863        #{ 
    848864            self::setFilename(self::mapControllerToFilename(self::getModulePath(), self::getController(), self::getSubController())); 
    849         } 
     865        #} 
    850866 
    851867        return self::$parameters['filename']; 
     
    954970            return self::$parameters['method']; 
    955971        } 
    956         else # add method prefix (action_) and subcontroller prefix (admin_) 
    957         { 
    958             #if(empty(self::$parameters['method'])) 
    959             #{ 
    960                 self::setMethod(self::mapActionToActioname(self::getAction(), self::getSubController())); 
    961             #} 
     972        # add method prefix (action_) and subcontroller prefix (admin_) 
     973        else 
     974        { 
     975            self::setMethod(self::mapActionToActioname(self::getAction(), self::getSubController())); 
     976 
    962977        } 
    963978 
     
    10191034        $string = (string) implode(",", self::$parameters); 
    10201035        Clansuite_Debug::firebug($string); 
     1036    } 
     1037 
     1038    public static function dispatchable() 
     1039    { 
     1040        $filename  = self::getFilename(); 
     1041        $classname = self::getClassname(); 
     1042        $method    = self::getMethod(); 
     1043 
     1044        /** 
     1045         * The file we want to call has to exists 
     1046         */ 
     1047        if(is_file($filename)) 
     1048        { 
     1049            include $filename; 
     1050 
     1051            /** 
     1052             * Inside this file, the correct class has to exist 
     1053             */ 
     1054            if(class_exists($classname, false)) 
     1055            { 
     1056                # WATCH IT! method_exists works on objects, is_callable on classes! ,) 
     1057                if(is_callable($classname, $method)) 
     1058                { 
     1059                      Clansuite_Debug::firebug('(OK) Route is dispatchable: '. $filename .' '. $classname .'->'. $method); 
     1060                      return true; 
     1061                } 
     1062                else 
     1063                { 
     1064                    return false; 
     1065                } 
     1066            } 
     1067            else 
     1068            { 
     1069                return false; 
     1070            } 
     1071        } 
     1072        else 
     1073        { 
     1074            Clansuite_Debug::firebug('(ERROR) Route not dispatchable: '. $filename .' '. $classname .'->'. $method); 
     1075            return false; 
     1076        } 
     1077    } 
     1078 
     1079    public static function reset() 
     1080    { 
     1081        $reset_params = array( 
     1082            # File 
     1083            'filename' => null, 
     1084            'classname' => null, 
     1085            # Call 
     1086            'controller' => null, 
     1087            'subcontroller' => null, 
     1088            'action' => 'show', 
     1089            'method' => null, 
     1090            'params' => null 
     1091        ); 
     1092 
     1093        self::$parameters = array_merge(self::$parameters, $reset_params); 
    10211094    } 
    10221095 
Note: See TracChangeset for help on using the changeset viewer.