Advertisement
Guest User

Untitled

a guest
Mar 7th, 2011
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. class Route implements IRoute,IRouter {
  2.     private $class = 'Index';
  3.     private $method = 'defaultAction';
  4.    
  5.     function getControllerId() {
  6.         return $this->getMapClass();
  7.     }
  8.    
  9.     function getActionId() {
  10.         return $this->getMapMethod();
  11.     }
  12.    
  13.     function getMapClass() {
  14.         if ( $this->class === null ) {
  15.             throw new Exception('Class not defined');
  16.         }
  17.         return $this->class;
  18.     }
  19.    
  20.     function getMapMethod() {
  21.         return $this->method;
  22.     }
  23.    
  24.     function matchMap($path) {
  25.         $this->class = 'Index';
  26.         $this->method = 'defaultAction';
  27.        
  28.         list($path) = explode('?', $path);
  29.         $path = preg_replace('#^/+#', '', $path);
  30.         $path = preg_replace('#/+$#', '', $path);
  31.         $toks = explode('/', $path);
  32.         if ( $toks[0] ) {
  33.             $this->class = $toks[0];
  34.         }
  35.         if ( sizeof($toks) > 1 && $toks[1] ) {
  36.             $this->method = $toks[1];
  37.         }
  38.         return true;
  39.     }
  40.    
  41.     function getRoute($request) {
  42.         $route = new self();
  43.         $route->matchMap($request);
  44.         return $route;
  45.     }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement