\Nano4\PluginsDispatch

Dispatch to Controllers based on rules.

Most rules match specific URL patterns, and so one script can dispatch to many different controllers and methods, depending on the current URL.

NOTE: This is being deprecated in favour of the Routing Dispatcher. When all apps have moved to the new dispatches, this library will be removed entirely, as it's a horrid mess.

Summary

Methods
Properties
Constants
__construct()
registerExtensions()
remove_invisible_characters()
get_path()
get_routing()
url_prefix()
addRoute()
addRoutes()
addPrefixController()
addSingleController()
addNestedController()
addDynamicController()
addDefaultController()
addRootController()
addRootRedirect()
addLookupController()
dispatch()
$url_prefix
No constants found
No protected methods found
$controllers
$default_method
N/A
No private methods found
No private properties found
N/A

Properties

$url_prefix

$url_prefix : 

Type

$controllers

$controllers : 

Type

$default_method

$default_method : 

Type

Methods

__construct()

__construct(  $opts = array()) 

Parameters

$opts

registerExtensions()

registerExtensions() 

remove_invisible_characters()

remove_invisible_characters(  $str,   $url_encoded = TRUE) : string

Remove Invisible Characters (Function from CodeIgniter)

This prevents sandwiching null characters between ascii characters, like Java\0script.

Parameters

$str
$url_encoded

Returns

string

get_path()

get_path() 

Return the PATH information.

get_routing()

get_routing(String  $path = null) 

Return an array representing the individual elements of a path.

Parameters

String $path

The path to parse into an array.

url_prefix()

url_prefix(String  $dir = Null) 

Set the URL prefix.

Parameters

String $dir

URL Prefix.

addRoute()

addRoute(Array  $rules, Bool  $top = false) 

Add a dispatch rule to be processed.

The order rules are added is important. Catchall rules should be added last, and to the very bottom!

Parameters

Array $rules

The rule specification to add.

Bool $top

If set to True, add to the top.

addRoutes()

addRoutes(Array  $baserules, Array  $methods) 

Add rules that map multiple routes to a single controller.

Parameters

Array $baserules

The base rules used to build individual rules.

Array $methods

A list of methods the controller supports.

addPrefixController()

addPrefixController(String  $name, Array  $handles) 

Add a single controller that handles multiple routes with a given prefix. Very simplistic.

Parameters

String $name

The name of the controller, and URL prefix.

Array $handles

List of methods (see addRoutes() for details.)

addSingleController()

addSingleController(String  $name, Int  $offset = False) 

Add a single controller which uses the prefix as the controller name.

Parameters

String $name

The name of the controller and URL prefix.

Int $offset

If set to an integer, defines path offset.

addNestedController()

addNestedController(Mixed  $paths, String  $name, Int  $offset = False) 

Add a controller to a nested path specification.

Due to the way Dispatch matches rules, you must make sure deeper nested path specs are added first, so they match before their parent paths.

Parameters

Mixed $paths

The path to match. See below.

String $name

The controller name.

Int $offset

If set to an integer, defines path offset.

The $paths can be specified in two formats. One is a simple path string, with / characters separating the path segments. The other is to specify an array of path components. If using the array method, you must ensure the path components are valid and contain no / characters.

addDynamicController()

addDynamicController(Bool  $splice = true) 

Add CodeIgniter-style controller dispatching.

Adds a controller rule that will determine the controller name and method name based on the URL path. If you use this, it should be added after any explicit URL matching rules.

Parameters

Bool $splice

Remove the first two path entries? [True]

addDefaultController()

addDefaultController(String  $name) 

Add a default controller that will be used if no other rules match.

This should be done only after ALL other rules have been added, as this rule will always match, and therefore no rule after it will ever be matched.

Parameters

String $name

Name of the controller to dispatch to.

addRootController()

addRootController(String  $name) 

Add a controller which will be used at the "root" URL.

This matches the "base" or "root" URL only. There can be only one "root" controller, and the first one found will be dispatched to.

Parameters

String $name

Name of the controller to dispatch to.

addRootRedirect()

addRootRedirect(String  $url) 

Add a redirection rule as the "root" controller.

This is mutually exclusive with addRootController(). As with any "root" controller, there can be only one.

Parameters

String $url

The URL to redirect the "root" path to.

addLookupController()

addLookupController(String  $name, String  $method) 

Add a controller that see's if it can handle the path via a method.

The lookup method can return a few different values:

  • String: the method name that handles the path.
  • True: this path is handled, use the default method name.
  • False: this path is not handled, this rule thus fails.

Parameters

String $name

The name of the controller.

String $method

The name of the lookup method.

dispatch()

dispatch(Bool  $reverse = false) 

Dispatch to a controller based on the rules we have added.

Parameters

Bool $reverse

If set to True, process rules in reverse order.