Changeset 163 for trunk/trax/vendor/trax/action_controller.php
- Timestamp:
- 03/07/06 09:44:21 (6 years ago)
- Files:
-
- 1 modified
-
trunk/trax/vendor/trax/action_controller.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/action_controller.php
r162 r163 186 186 187 187 /** 188 * @todo Document this attribute 188 * Name of the controller (without the _controller.php) 189 * 190 * Set by {@link recognize_route()} 191 * @var string 189 192 */ 190 193 private $controller; 191 194 192 195 /** 193 * @todo Document this attribute 196 * Name of the action method in the controller class 197 * 198 * Set by {@link recognize_route()} 199 * @var string 194 200 */ 195 201 private $action; … … 201 207 202 208 /** 203 * @todo Document this attribute 209 * Filesystem path to ../app/controllers/ directory 210 * 211 * Set by {@link recognize_route()} 212 * @var string 204 213 */ 205 214 private $controllers_path; 206 215 207 216 /** 208 * @todo Document this attribute 217 * Filesystem path to ../app/helpers/ directory 218 * 219 * Set by {@link recognize_route()} 220 * @var string 209 221 */ 210 222 private $helpers_path; … … 216 228 217 229 /** 218 * @todo Document this attribute 230 * Filesystem path to ../app/layouts/ directory 231 * 232 * Set by {@link recognize_route()} 233 * @todo <b>FIXME:</> declare $layouts_base_path 234 * @var string 219 235 */ 220 236 private $layouts_path; 221 237 222 238 /** 223 * @todo Document this attribute 239 * User's URL in components 240 * 241 * Contains user's URL stripped of TRAX_URL_PREFIX and leading 242 * and trailing slashes, then exploded into an array on slash 243 * boundaries. 244 * @var string[] 224 245 */ 225 246 private $url_path; 226 247 227 248 /** 228 * @todo Document this attribute 249 * Filesystem path to the default layouts file application.phtml 250 * 251 * Set by {@link recognize_route()} 252 * @var string 229 253 */ 230 254 private $default_layout_file; … … 236 260 237 261 /** 238 * @todo Document this attribute 262 * Filesystem path to application.php file 263 * 264 * Set by {@link recognize_route()} 265 * @var string 239 266 */ 240 267 private $application_controller_file; 241 268 242 269 /** 243 * @todo Document this attribute 270 * Filesystem path to application_helper.php file 271 * 272 * Set by {@link recognize_route()} 273 * @var string 244 274 */ 245 275 private $application_helper_file; 246 276 247 277 /** 248 * @todo Document this attribute 278 * URL recognized, paths resoved, controller file found 279 * 280 * Set by {@link recognize_route()} 281 * @var boolean 249 282 */ 250 283 private $loaded = false; … … 258 291 * <li>false => no Router object exists</li> 259 292 * </ul> 293 * @todo <b>FIXME:</b> No declaration of $router so no place to hang 294 * its documentation. 260 295 */ 261 296 private $router_loaded = false; … … 297 332 298 333 /** 299 * @todo Document this attribute 334 * Filesystem path to the ../app/views/ directory 335 * 336 * Set by {@link recognize_route()} 337 * @var string 300 338 */ 301 339 public $views_path; … … 322 360 323 361 /** 362 * Build a Router object and load routes from config/route.php 363 * @uses load_router() 364 */ 365 function __construct() { 366 if(!isset($this->router) || !is_object($this->router)) { 367 $this->load_router(); 368 } 369 } 370 371 /** 324 372 * @todo Document this method 325 */ 326 function __construct() { 327 if(!isset($this->router) || !is_object($this->router)) { 328 $this->load_router(); 329 } 330 } 331 332 /** 333 * @todo Document this method 373 * @uses add_after_filter() 374 * @uses add_before_filter() 375 * @uses add_helper() 334 376 */ 335 377 function __set($key, $value) { 336 #echo "setting: $key = $value<br>";337 378 if($key == "before_filter") { 338 379 $this->add_before_filter($value); … … 348 389 /** 349 390 * @todo Document this method 391 * Implement before_filter(), after_filter(), helper() 350 392 */ 351 393 function __call($method_name, $parameters) { … … 366 408 367 409 /** 368 * Load routes from configuration file routes.php410 * Load routes from configuration file config/routes.php 369 411 * 370 412 * Routes are loaded by requiring {@link routes.php} from the 371 * configuration directory. 413 * configuration directory. The file routes.php contains 414 * statements of the form "$router->connect(path,params);" where 415 * (path,params) describes the route being added by the 416 * statement. Route syntax is described in 417 * {@tutorial PHPonTrax/Router.cls the Router class tutorial}. 418 * 372 419 * @uses Router 373 420 * @uses $router … … 377 424 $this->router_loaded = false; 378 425 $router = new Router(); 379 # Load the routes 380 require_once(TRAX_ROOT.$GLOBALS['TRAX_INCLUDES']['config']."/routes.php"); 426 427 // Load the routes. 428 require(TRAX_ROOT.$GLOBALS['TRAX_INCLUDES']['config']."/routes.php"); 381 429 $this->router = $router; 382 430 if(is_object($this->router)) { … … 386 434 387 435 /** 388 * @todo Document this method 436 * Convert URL to controller, action and id 437 * 438 * Parse the URL in $_SERVER['REDIRECT_URL'] into elements. 439 * Compute filesystem paths to the various components used by the 440 * URL and store the paths in object private variables. 441 * Verify that the controller exists. 442 * 389 443 * @uses load_router() 444 * @uses $action 445 * @uses $application_controller_file 446 * @uses $controller 447 * @uses $controller_class 448 * @uses $controller_file 449 * @uses $controllers_path 450 * @uses $default_layout_file 451 * @uses $helper_file 452 * @uses $helpers_path 453 * @uses $id 454 * @uses $layouts_path 455 * @uses $loaded 390 456 * @uses $router 391 457 * @uses $router_loaded 392 458 * @uses set_paths() 393 459 * @uses $url_path 460 * @uses $views_file_extention 461 * @uses $views_path 462 * @return boolean 463 * <ul> 464 * <li>true => route recognized, controller found.</li> 465 * <li>false => failed, route not recognized.</li> 466 * </ul> 394 467 */ 395 468 function recognize_route() { 396 397 469 if(!$this->router_loaded) { 398 470 $this->load_router(); … … 448 520 } 449 521 522 // FIXME: get a warning if ':id' not in $url_path 450 523 if(@in_array(":id",$route_path)) { 451 524 $this->id = strtolower($this->url_path[@array_search(":id", $route_path)]); … … 473 546 /** 474 547 * @todo Document this method 548 * @uses $action 549 * @uses $application_controller_file 550 * @uses $application_helper_file 551 * @uses $controller 552 * @uses $controller_class 553 * @uses $controller_file 554 * @uses $controller_object 555 * @uses determine_layout() 556 * @uses execute_after_filters() 557 * @uses $helpers 558 * @uses $helper_file 559 * @uses $helpers_base_path 560 * @uses $keep_flash 561 * @uses $loaded 562 * @uses recognize_route() 563 * @uses raise() 564 * @uses ScaffoldController 565 * @uses $view_file 566 * @uses $views_file_extention 567 * @uses $views_path 568 * @return boolean true 475 569 */ 476 570 function process_route() { 477 571 478 # First try to load the routes and setup the path es to everything572 # First try to load the routes and setup the paths to everything 479 573 if(!$this->loaded) { 480 574 if(!$this->recognize_route()) { … … 494 588 495 589 # Include the controller file and execute action 590 // FIXME: redundant, recognize_route() already test for file exists 496 591 if(file_exists($this->controller_file)) { 497 592 include_once($this->controller_file); … … 502 597 $this->controller_object->controller = $this->controller; 503 598 $this->controller_object->action = $this->action; 599 // FIXME: $added_path doesn't exist at this point 504 600 $this->controller_object->controller_path = "$this->added_path/$this->controller"; 505 601 $GLOBALS['current_controller_path'] = "$this->added_path/$this->controller"; … … 635 731 /** 636 732 * @todo Document this method 733 * @uses $added_path 734 * @uses $controllers_path 735 * @uses $helpers_path 736 * @uses $layous_path 737 * @uses $views_path 738 * @uses $url_path 637 739 */ 638 740 function set_paths() { … … 821 923 /** 822 924 * @todo Document this method 925 * @uses $controller_object 926 * @uses $layouts_base_path 927 * @uses $layouts_path 928 * @return mixed Layout file or null if none 929 * @todo <b>FIXME:</b> Should this method be private? 823 930 */ 824 931 function determine_layout() { 825 932 # I guess you don't want any layout 933 // FIXME: Do we really want to test for null here? 934 // It might make more sense to test isset(...layout) 826 935 if($this->controller_object->layout == "null") { 827 936 return null; … … 848 957 } 849 958 } 850 # No defined layout found so just use the default layout app/views/layouts/application.phtml 959 // No defined layout found so just use the default layout 960 // app/views/layouts/application.phtml 961 // FIXME: this file isn't in the distribution so 962 // this reference will fail 851 963 if(!$layout_file) { 852 964 $layout_file = $this->default_layout_file;
