Changeset 414

Show
Ignore:
Timestamp:
08/26/2007 05:54:16 PM (15 months ago)
Author:
Shadowhand
Message:

This should fix the problem with Router not being able to find the default route when there is an index page enabled.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/devel/system/libraries/Router.php

    r399 r414  
    1616        public static function setup() 
    1717        { 
    18                 try 
    19                 { 
    20                         self::$segments = ''; 
    21                         self::$routes   = array(); 
    22  
    23                         // Load all of the route configurations 
    24                         foreach(Kohana::find_file('config', 'routes', TRUE) as $filename) 
    25                         { 
    26                                 include $filename; 
    27  
    28                                 // Merge in new routes 
    29                                 if (isset($config) AND is_array($config)) 
    30                                 { 
    31                                         self::$routes = array_merge(self::$routes, $config); 
    32                                 } 
    33                         } 
    34                 } 
    35                 catch (file_not_found $execption) 
    36                 { 
    37                         /** 
    38                          * @todo this needs to be handled better 
    39                          */ 
    40                         exit('Your <kbd>config/routes'.EXT.'</kbd> file could not be loaded.'); 
    41                 } 
    42  
    43                 /** 
    44                  * The follow block of if/else attempts to retrieve the URI segments automagically 
    45                  * 
    46                  * Supported methods: CLI, GET, PATH_INFO, ORIG_PATH_INFO, REQUEST_URI 
    47                  */ 
     18                self::$segments = ''; 
     19                self::$routes   = Config::item('routes'); 
     20 
     21                // The follow block of if/else attempts to retrieve the URI segments automagically 
     22                // Supported methods: CLI, GET, PATH_INFO, ORIG_PATH_INFO, REQUEST_URI 
    4823                if (PHP_SAPI == 'cli') 
    4924                { 
     
    7247                        self::$segments = current(array_keys($_GET)); 
    7348                } 
     49                /* 
    7450                elseif (isset($_SERVER['PATH_INFO'])) 
    7551                { 
     
    8056                        self::$segments = $_SERVER['ORIG_PATH_INFO']; 
    8157                } 
     58                */ 
    8259                elseif (isset($_SERVER['REQUEST_URI']) AND $_SERVER['REQUEST_URI']) 
    8360                { 
     
    8562                         * @todo this needs a lot more work, and tests need to be made on IIS5/6/7 
    8663                         */ 
    87                         $ruri = urldecode(trim($_SERVER['REQUEST_URI'], '/')); 
    88                         $path = trim(preg_replace('!^'.preg_quote(getcwd(), '-').'!u', '', DOCROOT), '/'); 
    89  
    90                         $ruri = explode('/', $ruri); 
    91                         $path = explode('/', $path); 
    92  
    93                         $i = 0; 
    94                         while($dir = array_shift($path)) 
    95                         { 
    96                                 if ( ! $ruri[$i] == $dir) 
    97                                         break; 
    98  
    99                                 array_shift($ruri); 
    100                                 $i += 1; 
    101                         } 
    102  
    103                         self::$segments = implode('/', $ruri); 
    104                 } 
    105                  
    106                 /** 
    107                  * Use the default route when no segments exist 
    108                  */ 
     64                        self::$segments = urldecode($_SERVER['REQUEST_URI']); 
     65 
     66                        if (($offset = strpos(self::$segments, 'index'.EXT)) !== FALSE) 
     67                        { 
     68                                // Add the length of the index file to the offset 
     69                                $offset += strlen('index'.EXT); 
     70 
     71                                // Segments have been located 
     72                                self::$segments = substr(self::$segments, $offset); 
     73                                self::$segments = trim(self::$segments, '/'); 
     74                        } 
     75                        else 
     76                        { 
     77                                self::$segments = ''; 
     78                        } 
     79                } 
     80 
     81                // Use the default route when no segments exist 
    10982                if (self::$segments == '' OR self::$segments == '/') 
    11083                { 
     
    11588                } 
    11689 
    117                 /** 
    118                  * Remove the URL suffix 
    119                  */ 
     90                // Remove the URL suffix 
    12091                if ($suffix = Config::item('core.url_suffix')) 
    12192                { 
     
    12394                } 
    12495 
    125                 /** 
    126                  * Remove extra slashes from the segments that could cause fucked up routing. 
    127                  */ 
     96                // Remove extra slashes from the segments that could cause fucked up routing. 
    12897                self::$segments = preg_replace('!//+!u', '/', self::$segments); 
    12998                self::$segments = self::$rsegments = self::$current_uri = trim(self::$segments, '/'); 
    13099 
    131                 /** 
    132                  * Custom routing 
    133                  */ 
     100                // Custom routing 
    134101                if (count(self::$routes) > 1); 
    135102                {