Changeset 161 for trunk/trax/vendor/trax/router.php
- Timestamp:
- 03/02/06 17:20:34 (6 years ago)
- Files:
-
- 1 modified
-
trunk/trax/vendor/trax/router.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/router.php
r138 r161 30 30 31 31 /** 32 * 33 * @todo Document this class 34 * @package PHPonTrax 32 * Convert a URL to an action 33 * @tutorial PHPonTrax/Router.cls 35 34 */ 36 35 class Router { 37 36 37 /** 38 * Route table 39 * 40 * For a description of the structure, see 41 * {@tutorial PHPonTrax/Router.cls#table the Router tutorial}. 42 * Routes are added by calling {@link connect()} and looked up 43 * by calling {@link find_route()}. 44 * <b>FIXME:</b> Should we have a Route class to describe an 45 * entry in the route table? 46 * @var string[][] 47 */ 38 48 private $routes = array(); 49 50 /** 51 * Last route found by a call to find_route() 52 * @var string[] 53 */ 39 54 private $selected_route = null; 55 56 /** 57 * Default route path 58 * 59 * This route path is added to the route table if the table is 60 * empty when find_route() is called. 61 * @var string constant 62 */ 40 63 private $default_route_path = ":controller/:action/:id"; 64 65 /** 66 * Count of the number of elements in $routes 67 * @var integer 68 */ 41 69 public $routes_count = 0; 42 70 43 71 /** 44 * 45 * @todo Document this method 72 * Accessor method to return contents of $selected_route 73 * @return string[] Contents of $selected_route 74 * @uses $selected_route 46 75 */ 47 76 function get_selected_route() { … … 50 79 51 80 /** 81 * Accessor method to add a route to the route table 52 82 * 53 * @todo Document this method 83 * The route is added to the end of 84 * {@link $routes the route table}. If $params is not an array, 85 * NULL is stored in the route parameter area. 86 * @param string $path 87 * @param mixed[] $params 88 * @uses $routes 89 * @uses $routes_count 54 90 */ 55 91 function connect($path, $params = null) { … … 61 97 62 98 /** 99 * Find first route in route table with path that matches argument 63 100 * 64 * @todo Document this method 101 * First, assure that the route table {@link $routes} has at 102 * least one route by adding 103 * {@link $default_route_path the default route} if the table is 104 * empty. Then search the table to find the first route in the 105 * table whose path matches the argument $url. If $url is an 106 * empty string, it matches a path that is an empty string. 107 * Otherwise, try to match $url to the path part of the table 108 * entry according to {@link http://www.php.net/manual/en/ref.pcre.php Perl regular expression} 109 * rules. Return the first matching route to the caller, and 110 * also save a copy in {@link $selected_route}. 111 * @param string $url 112 * @uses build_route_regexp() 113 * @uses $default_route_path 114 * @uses $routes 115 * @uses $routes_count 116 * @uses $selected_route 117 * @return string[] Selected route. Path is in return['path'], 118 * params in return['params'], 65 119 */ 66 120 function find_route($url) { 67 68 121 // ensure at least one route (the default route) exists 69 122 if($this->routes_count == 0) { 70 $this->routes['path'] = $this->default_route_path; 71 $this->routes['params'] = null; 123 $this->connect($this->default_route_path); 72 124 } 73 125 … … 78 130 unset($reg_exp); 79 131 $route_regexp = $this->build_route_regexp($route['path']); 80 81 132 if($url == "" && $route_regexp == "") { 82 133 $this->selected_route = $route; … … 92 143 93 144 return $this->selected_route; 94 } 145 } // function find_route($url) 95 146 96 147 /** 148 * Build a regular expression that matches a route 97 149 * 98 * @todo Document this method 150 * <b>FIXME:</b> Should this method be private? 151 * @param string $route_path A route path. 152 * @return string Regular expression that matches the route in 153 * $route_path 99 154 */ 100 155 function build_route_regexp($route_path) { 156 // echo "entering build_route_regexp(), \$route_path is '$route_path'\n"; 101 157 102 158 $route_regexp = null; … … 105 161 $route_path = explode("/",$route_path); 106 162 } 107 163 // echo "route path:\n"; 164 // var_dump($route_path); 108 165 if(count($route_path) > 0) { 109 166 foreach($route_path as $path_element) { … … 124 181 } 125 182 183 // -- set Emacs parameters -- 184 // Local variables: 185 // tab-width: 4 186 // c-basic-offset: 4 187 // c-hanging-comment-ender-p: nil 188 // indent-tabs-mode: nil 189 // End: 126 190 ?>
