Changeset 3408
- Timestamp:
- 08/31/2008 06:56:54 AM (3 months ago)
- Location:
- trunk/system
- Files:
-
- 2 modified
-
classes/router.php (modified) (14 diffs)
-
config/routes.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/classes/router.php
r3405 r3408 26 26 /** 27 27 * Router setup routine. Called during the [system.routing][ref-esr] 28 * Event by default. 28 * Event by default. 29 29 * 30 30 * [ref-esr]: http://docs.kohanaphp.com/events/system.routing … … 34 34 public static function setup() 35 35 { 36 // Remove all dot-paths from the URI, they are not valid37 self::$current_uri = trim(preg_replace('#\.[\s./]*/#', '', self::$current_uri), '/');38 39 36 // Set the complete URI 40 37 self::$complete_uri = self::$current_uri.self::$query_string; … … 48 45 ( 49 46 'Routing API Changed!', 50 'Routing has been significantly changed, and your configuration '. 51 'files are not up to date. Please check http://dev.kohanaphp.com/changeset/3366 '. 52 'for more details.' 47 'Routing has been significantly changed, and your configuration files are not up to date. '. 48 'Please check http://dev.kohanaphp.com/changeset/3366 for more details.' 53 49 ); 54 50 } … … 204 200 if (($strpos_fc = strpos(self::$current_uri, $fc)) !== FALSE) 205 201 { 206 // Remove the front controller from the current uri202 // Remove the front controller from the current URI 207 203 self::$current_uri = substr(self::$current_uri, $strpos_fc + strlen($fc)); 208 204 } … … 215 211 // Reduce multiple slashes into single slashes 216 212 self::$current_uri = preg_replace('#//+#', '/', self::$current_uri); 213 214 // Remove all dot-paths from the URI, they are not valid 215 self::$current_uri = preg_replace('#\.[\s./]*/#', '', self::$current_uri); 217 216 218 217 // Make sure the URL is not tainted with HTML characters … … 264 263 265 264 // Remove trailing parts from the URI 266 $uri = preg_replace('#/? \:.+$#', '', $uri);265 $uri = preg_replace('#/?:.+$#', '', $uri); 267 266 268 267 return $uri; … … 281 280 282 281 // Find all keys that start with a colon 283 preg_match_all('# :([a-z]+)#', $uri, $keys);284 285 return $keys[ 1];286 } 287 288 /** 289 * Creates a [regular expression][ref-reg] that can be used to match a 282 preg_match_all('#(?<=:)[a-z]+#', $uri, $keys); 283 284 return $keys[0]; 285 } 286 287 /** 288 * Creates a [regular expression][ref-reg] that can be used to match a 290 289 * route against a URI with [preg_match][ref-prm]. 291 290 * … … 302 301 303 302 // Regular expression end 304 $end = array();303 $end = ''; 305 304 306 305 // Nothing is optional yet … … 309 308 foreach ($uri as $i => $segment) 310 309 { 311 // Regular expression312 $exp = array();313 314 310 if ($segment[0] === ':') 315 311 { 316 312 // Find the actual segment key and any trailing garbage 317 preg_match('#^:([a-z]+ )(.*)$#', $segment, $matches);313 preg_match('#^:([a-z]++)(.*)$#', $segment, $matches); 318 314 319 315 // Segment key 320 316 $key = $matches[1]; 317 318 // Regular expression 319 $exp = ''; 321 320 322 321 if ($optional === FALSE AND isset($route[$key])) … … 329 328 if ($optional === TRUE) 330 329 { 331 // Start the expression as an optional match 332 $exp[] = '(?:'; 330 // Start the expression as non-capturing group 331 $exp .= '(?:'; 332 333 // End the expression as an optional match 334 $end .= ')?'; 333 335 } 334 336 … … 336 338 { 337 339 // Add the slash from the previous segment 338 $exp []= '/';340 $exp .= '/'; 339 341 } 340 342 … … 342 344 { 343 345 // Matches specified regex for the segment 344 $exp []= '('.$route['regex'][$key].')';346 $exp .= '('.$route['regex'][$key].')'; 345 347 } 346 348 else 347 349 { 348 // Default regex matches all characters 349 $exp [] = '([^/]+)';350 // Default regex matches all characters except slashes 351 $exp .= '([^/]++)'; 350 352 } 351 353 … … 353 355 { 354 356 // Add trailing segment junk 355 $exp[] = preg_quote($matches[2], '#'); 356 } 357 358 if ($optional === TRUE) 359 { 360 // End the expression 361 $end[] = ')?'; 357 $exp .= preg_quote($matches[2], '#'); 362 358 } 363 359 364 360 // Replace the segment with the segment expression 365 $uri[$i] = implode('', $exp);361 $uri[$i] = $exp; 366 362 } 367 363 else … … 378 374 } 379 375 380 return implode('', $uri). implode('', $end);376 return implode('', $uri).$end; 381 377 } 382 378 -
trunk/system/config/routes.php
r3407 r3408 17 17 * The converted regex for this route is: 18 18 * 19 * (?:([^/]+ )(?:/([^/]+)(?:/([^/]+))?)?)?19 * (?:([^/]++)(?:/([^/]++)(?:/([^/]++))?)?)? 20 20 * 21 21 * To define a specific pattern for a key, you can use the special "regex" key:
