| 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 |
| 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 |