ratatoeskr/sys/urlprocess.php

Providing functions / classes to handle URLs

License

This file is part of Ratatöskr.  Ratatöskr is licensed unter the MIT / X11 License.  See “ratatoeskr/licenses/ratatoeskr” for more information.

Summary
ratatoeskr/sys/urlprocess.phpProviding functions / classes to handle URLs
Functions
url_action_simpleGenerate an action in a more simple way.
url_action_subactionsGenerate an action that contains subactions.
url_action_aliasGenerate an action that is an alias for another one (i.e.
url_processChoose an appropiate action for the given URL.
RedirectException that can be thrown inside an url_action_simple.
NotFoundErrorAn Exception

Functions

url_action_simple

function url_action_simple($function)

Generate an action in a more simple way.

Parameters

$functionA callback that gets the $data var as an input and returns the new $data var.  Can throw an Redirect Exception.

Returns

A callback that can be used as an url action.

url_action_subactions

function url_action_subactions($actions)

Generate an action that contains subactions.  Subactions can redirect to “..” to go to the level above.

Parameters

$actionsAssociative array of actions.

Returns

A callback that can be used as an url action.

url_action_alias

function url_action_alias($for)

Generate an action that is an alias for another one (i.e. redirects).

Parameters

$forPath (array) of the action this one should be an alias of.

Returns

A callback that can be used as an url action.

url_process

function url_process($url,
$actions,
&$data)

Choose an appropiate action for the given URL.

Parameters

$urlEither an array containing the URL components or the URL (both relative).
$actionsAssociative array of actions.  Key is the name (anything alphanumeric, should usually not start with ‘_’, reserved for special URL names, see beneath).  Value is a callback of the form: function(&$data, $url_now, &$url_next).  $data can be used for shared data between subactions.  $url_next can be modified in order to redirect to another action / stop the routing.

Special actions

_indexIf name is empty, the index will be called.
_defaultIf nothing was found, this is the default.
_notfoundIf not even _default exists or NotFoundError was thrown.
_preludeIf existant, will be executed before everything else.
_epilogIf existant, will be executed after evrything else.

Redirect

Exception that can be thrown inside an url_action_simple. throw new Redirect(array(“..”, “foo”)); will redirect to “../foo” and won’t touch $data.

NotFoundError

An Exception

function url_action_simple($function)
Generate an action in a more simple way.
function url_action_subactions($actions)
Generate an action that contains subactions.
function url_action_alias($for)
Generate an action that is an alias for another one (i.e.
function url_process($url,
$actions,
&$data)
Choose an appropiate action for the given URL.
Exception that can be thrown inside an url_action_simple.
Close