A very simple routing library.
Ariadne usually handles all your routing by mapping URL's to objects in the store. But in some cases you need to handle URL's that do not match with existing objects.
The normal approach is to use either the
user.notfound.html template or the
onnotfound event. This library helps you write the code in that case.
$result = ar::call('router:route', array(
'routes' => array(
A route consists of a regular expression and an action. The action can either be a template name or a closure. If you enter a template name, you can add extra arguments like this:
'route/(?<name>.*?)/?' => 'template.html?extraArg=1'
The routes are checked in order. The first route that matches is called. If that action returns
false (and only exactly that), the router continues on with the next matching route, otherwise
it stops. The router returns the value of the last action called.
Each route is a regular expression and is checked to match the whole path, case insensitive. Here are some examples:
prefix/.*matches any path that starts with 'prefix/'
prefix/(?<splat>.*)matches the same, but the remainder of the path is available in the template as 'splat'.
prefix/(?<name>[^/]*)/matches any path that starts with 'prefix/' and has exactly one extra word after that.