Download the PHP package kento-oka/roust without Composer
On this page you can find all versions of the php package kento-oka/roust. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package roust
Roust
CAUTION:
This library has moved to fratily/router. From now on plz use that.
Roust is the fastest (wishful) URI router.
NOTE:
I cant speak engilish. so I used GoogleTranslate.
The exact REDME is in README_origin.
Install
Before using Roust in your project, execute it command in your project:
Usage
First of all, create an instance of router.
Basic usage
Defining route
Routing rules are defined by Router::addRoute()
.
The first argument is an HTTP method to allow.
The second argument is a URI that matches.
And you can specify additional parameters for the third argument.
You can omit the leading slash in the second argument.
Methods such as Router::get()
, Router::post()
, Router::put()
, and
Router::delete()
are defined to omit specification of the HTTP method.
Use regex
Use the {id:regex}
syntax to embed regular expression.
id specifies the parameter name, regex specifies the regular expression
to be used in PHP's preg_match().
Even if the same parameter name is specified with the third argument, the value of second argument takes precedence.
Use short regex
For example, if you add a routing rule that matches IP address,
there would no one to write that regex in Router::addRoute()
.
Furthermore, if it is IPv4-mapped IPv6 address,
it is useful if it can be converted to IPv4 at the routing stage.
Short regex that makes it possible.
It is short regex that matches only natural numbers and convert to int type:
Short regex can be registered with Router::addShortRegex()
.
The first argument is an qualified name.
The second argument will pass an instance of the class implementing
Roust\ShortRegexInterface
.
Group
In the example so far, there were parts common to some rules.
Taking the rule related to the user as an example, the head of URI is neccessarily '/users/' and the value of 'controller' is 'user'.
It is not hard to write common parts with the previous example. But Actually more rules are needed.
In Roust you can summarize the grouping of rules in this way:
Router::makePathGroup()
adds value of the first argument to the
beginning of the URI of the rule added with Router::addRoute()
only while
the second argument callback is executed.
In Router::makeParamsGroup()
, add parameters.
This added parameters can be overwriten with Router::addRoute()
.
Note
String > Short Regex > Regex