Changeset 2310

Show
Ignore:
Timestamp:
03/17/2008 04:40:35 AM (7 months ago)
Author:
Geert
Message:

Fixed #496 and some other small optimizations and cleanups.

Location:
trunk/system/libraries
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/Router.php

    r2250 r2310  
    2929        /** 
    3030         * Router setup routine. Automatically called during Kohana setup process. 
     31         * 
     32         * @return  void 
    3133         */ 
    3234        public static function setup() 
     
    3941 
    4042                // Use the default route when no segments exist 
    41                 if (self::$current_uri == '' OR self::$current_uri == '/') 
    42                 { 
    43                         self::$current_uri = self::$routes['_default']; 
     43                if (self::$current_uri === '') 
     44                { 
     45                        self::$current_uri = trim(self::$routes['_default'], '/'); 
    4446                        $default_route = TRUE; 
    4547                } 
     
    6264 
    6365                // Custom routing 
    64                 if ($default_route == FALSE AND count(self::$routes) > 1) 
     66                if ($default_route === FALSE AND count(self::$routes) > 1) 
    6567                { 
    6668                        if (isset(self::$routes[self::$current_uri])) 
     
    7577                                { 
    7678                                        if ($key === '_default') continue; 
     79 
     80                                        // Trim slashes 
     81                                        $key = trim($key, '/'); 
     82                                        $val = trim($val, '/'); 
    7783 
    7884                                        // Does this route match the current URI? 
     
    96102 
    97103                        // Check router one more time to do some magic 
    98                         self::$rsegments = isset(self::$routes[self::$rsegments]) ? self::$routes[self::$rsegments] : self::$rsegments; 
     104                        if (isset(self::$routes[self::$rsegments])) 
     105                        { 
     106                                self::$rsegments = self::$routes[self::$rsegments]; 
     107                        } 
    99108                } 
    100109 
    101110                // Explode the segments by slashes 
    102                 if ($default_route == TRUE OR self::$segments == '') 
     111                if ($default_route === TRUE OR self::$segments === '') 
    103112                { 
    104113                        self::$segments = array(); 
     
    108117                        self::$segments = explode('/', self::$segments); 
    109118                } 
     119 
    110120                // Routed segments will never be blank 
    111121                self::$rsegments = explode('/', self::$rsegments); 
     
    178188        /** 
    179189         * Attempts to determine the current URI using CLI, GET, PATH_INFO, ORIG_PATH_INFO, or PHP_SELF. 
     190         * 
     191         * @return  void 
    180192         */ 
    181193        public static function find_uri() 
     
    269281                $str = trim($str); 
    270282 
    271                 if ($str != '' AND ($allowed = Config::item('routes._allowed')) != '') 
     283                if ($str !== '' AND ($allowed = Config::item('routes._allowed')) != '') 
    272284                { 
    273285                        if ( ! preg_match('|^['.preg_quote($allowed).']++$|iuD', $str)) 
  • trunk/system/libraries/URI.php

    r2184 r2310  
    237237                return self::$rsegments[$end - 1]; 
    238238        } 
    239          
    240         /**  
    241          * Returns the path to the current controller (not including the actual  
    242          * controller), as a web path 
    243          *  
    244          * @param  bool    If a full url should be returned, or only the path specifically 
    245          */ 
    246         public function controller_path($full = TRUE) { 
    247                 return ((bool) $full)  
    248                         ? url::site(self::$controller_path) 
    249                         : self::$controller_path; 
    250         } 
    251          
    252         /**  
    253          * Returns the current controller, as a web path  
    254          *  
    255          * @param  bool    If a full url should be returned, or only the controller specifically 
    256          */ 
    257         public function controller($full = TRUE) { 
    258                 return ((bool) $full)  
    259                         ? url::site(self::$controller_path.self::$controller) 
    260                         : self::$controller; 
    261         } 
    262          
    263         /**  
    264          * Returns the current method, as a web path 
    265          *  
    266          * @param  bool    If a full url should be returned, or only the method specifically 
    267          */ 
    268         public function method($full = TRUE) { 
    269                 return ((bool) $full)  
    270                         ? url::site(self::$controller_path.self::$controller.'/'.self::$method)  
    271                         : self::$method; 
     239 
     240        /** 
     241         * Returns the path to the current controller (not including the actual 
     242         * controller), as a web path. 
     243         * 
     244         * @param   boolean  return a full url, or only the path specifically 
     245         * @return  string 
     246         */ 
     247        public function controller_path($full = TRUE) 
     248        { 
     249                return ($full) ? url::site(self::$controller_path) : self::$controller_path; 
     250        } 
     251 
     252        /** 
     253         * Returns the current controller, as a web path. 
     254         * 
     255         * @param   boolean  return a full url, or only the controller specifically 
     256         * @return  string 
     257         */ 
     258        public function controller($full = TRUE) 
     259        { 
     260                return ($full) ? url::site(self::$controller_path.self::$controller) : self::$controller; 
     261        } 
     262 
     263        /** 
     264         * Returns the current method, as a web path. 
     265         * 
     266         * @param   boolean  return a full url, or only the method specifically 
     267         * @return  string 
     268         */ 
     269        public function method($full = TRUE) 
     270        { 
     271                return ($full) ? url::site(self::$controller_path.self::$controller.'/'.self::$method) : self::$method; 
    272272        } 
    273273