MultiURLDispatcher Class Reference

Dispatches url requests to different URLDispatcher classes, based on the prefix of the url dispatched. More...

List of all members.

Public Member Functions

 MultiURLDispatcher ()
 Constructor for a new MultiURLDispatcher.
 add_prefix ($prefix, $module_name=null, $class_name)
 Add a prefix to the list of prefix mappings.
 dispatch ($url=null)
 Dispatch an URL to the correct handlers.
 setup_mappings ()
 Set up the url mappings.
 load_module ($module_name)
 Load a module specified in a prefix mapping.

Private Attributes

 $prefix_to_dispatcher_mapping
 URL maps.


Detailed Description

Dispatches url requests to different URLDispatcher classes, based on the prefix of the url dispatched.

This class is useful for larger sites composed of different 'modules', all running in a different url prefix ('url namespace'). An example: You run several news pages (view item, archive, ...) at urls starting with '/news'. You want to have all news-related dispatchin code into a separate dispatcher class, located in a file of its own.

To use this class, you should override this class and implement setup_mappings() and optionally load_module().

Your setup_mappings() method should set the 'default-class' property to the name of the default dispatcher class to use. You may also set the 'default-module' property (see below). Additionally, this methods should contain calls to add_prefix to define which module/class name should be used for the supplied url prefix.

Override and implement the load_module() method if the dispatcher class names used in your add_prefix() calls are not yet available when the dispatcher is invoked. A common and simple implementation of the load_module() should make sure the class name is loaded, e.g. by including the right file. (Hint: use a foo_include() function; see create_include_function() for details.)

Note that the dispatchers will have the url prefix stripped off when called! Coming back to the news example, this means that the url maps of your news UrlDispatcher class should not include the '/news' part in the urlmaps.

See also:
URLDispatcher

create_include_function

Definition at line 56 of file multi.lib.php.


Member Function Documentation

MultiURLDispatcher::add_prefix ( prefix,
module_name = null,
class_name 
)

Add a prefix to the list of prefix mappings.

Call this method from your setup_mappings() method.

Parameters:
$prefix The url prefix to match
$module_name The module name passed to load_module() (optional, specify null if you don't need it)
$class_name The class name of the dispatcher to instantiate and invoke.
See also:
MultiURLDispatcher::setup_mappings

MultiURLDispatcher::load_module

Definition at line 85 of file multi.lib.php.

MultiURLDispatcher::dispatch ( url = null  ) 

Dispatch an URL to the correct handlers.

See the documentation on URLDispatcher::dispatch() for more information on the parameters.

Parameters:
$url The url to dispatch (optional, defaults to null).
See also:
URLDispatcher::dispatch

Definition at line 107 of file multi.lib.php.

MultiURLDispatcher::setup_mappings (  ) 

Set up the url mappings.

You must override this method.

See also:
MultiURLDispatcher

Definition at line 154 of file multi.lib.php.

MultiURLDispatcher::load_module ( module_name  ) 

Load a module specified in a prefix mapping.

Override this method to load needed dispatcher classes on demand.

Parameters:
$module_name Name of the module to load (string)
See also:
MultiURLDispatcher

Definition at line 167 of file multi.lib.php.


The documentation for this class was generated from the following file:

Generated on Sun Aug 2 22:54:38 2009 for Anewt by  doxygen 1.5.9