PHPonTrax
[ class tree: PHPonTrax ] [ index: PHPonTrax ] [ all elements ]

Class: Router

Source Location: /vendor/trax/router.php

Class Overview


Convert a URL to an action


Author(s):

Variables

Methods



Class Details

[line 35]
Convert a URL to an action



Tags:

usedby:  ActionController::load_router()
tutorial:  Router


[ Top ]


Class Variables

$default_route_path =  ":controller/:action/:id"

[line 63]

Default route path

This route path is added to the route table if the table is empty when find_route() is called.




Tags:

var:  constant
usedby:  Router::find_route()
access:  private

Type:   string


[ Top ]

$routes = array()

[line 48]

Route table

For a description of the structure, see the Router tutorial. Routes are added by calling connect() and looked up by calling find_route(). FIXME: Should we have a Route class to describe an entry in the route table?




Tags:

usedby:  Router::find_route()
usedby:  Router::connect()
access:  private

Type:   string[][]


[ Top ]

$routes_count =  0

[line 69]

Count of the number of elements in $routes



Tags:

usedby:  Router::find_route()
usedby:  Router::connect()
access:  public

Type:   integer


[ Top ]

$selected_route =  null

[line 54]

Last route found by a call to find_route()



Tags:

usedby:  Router::find_route()
usedby:  Router::get_selected_route()
access:  private

Type:   string[]


[ Top ]



Class Methods


method build_route_regexp [line 164]

string build_route_regexp( string $route_path)

Build a regular expression that matches a route



Tags:

return:  Regular expression that matches the route in $route_path
usedby:  Router::find_route()
todo:  FIXME: Should this method be private?
todo:  FIXME: Shouldn't the regexp match be the same as for a PHP variable name? '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'


Parameters:

string   $route_path   A route path.

[ Top ]

method connect [line 91]

void connect( string $path, [mixed[] $params = null])

Accessor method to add a route to the route table

The route is added to the end of the route table. If $params is not an array, NULL is stored in the route parameter area.




Tags:



Parameters:

string   $path  
mixed[]   $params  

[ Top ]

method find_route [line 122]

mixed find_route( string $url)

Find first route in route table with path that matches argument

First, assure that the route table $routes has at least one route by adding the default route if the table is empty. Then search the table to find the first route in the table whose path matches the argument $url. If $url is an empty string, it matches a path that is an empty string. Otherwise, try to match $url to the path part of the table entry according to Perl regular expression rules. If a matching route is found, return it any to the caller, and also save a copy in $selected_route; if no matching route is found return null.




Tags:

return:  Matching route or null. Path is in return['path'], params in return['params'],
uses:  Router::$selected_route
uses:  Router::$routes_count
uses:  Router::$routes
uses:  Router::$default_route_path
uses:  Router::build_route_regexp()


Parameters:

string   $url  

[ Top ]

method get_selected_route [line 76]

string[] get_selected_route( )

Accessor method to return contents of $selected_route



Tags:

return:  Contents of $selected_route
uses:  Router::$selected_route


[ Top ]


Documentation generated on Thu, 04 May 2006 19:47:52 -0600 by phpDocumentor 1.3.0RC4