Download the PHP package tuum/router without Composer
On this page you can find all versions of the php package tuum/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package router
Router
Yet-another small router component for PHP.
MIT Licence
Why another Routing component?
I was looking for a routing component that works as one-liner and have features like;
- match for method and route pattern represented by a string,
- match to parameterized token as well as beginning of path, and
- have a very small code base,
and I could not find one. It is possible to use just a regular expressions for the above purpose, but I found it too difficult to write a correct reg-ex everytime.
Matcher
Basic usage
If the $path matches with $pattern, the method returns array of matched information. Otherwise it returns an empty array.
Examples
matching to method , with integer parameter .
matching to any method, starting with .
The Matcher class has no dependencies, with less than 100 lines of code including comments.
Closure style
Available as a static method as well as a closure style.
Returned value
The method returns an array of matched parameters, or empty array if failed to match.
The returned values are preg-match result, and some more. Please do not use strings as parameters.
- method: matched method. this value maybe empty if no method is specified.
- matched: matched base path if is used.
- trailing: matched remaining path if is used.
Available Route Patterns
the route patterns.
route
Generally speaking, start route pattern with slash ('/'). In case the route contains a colon (':') but do not want to specify method, make sure the route start with slash.
parameter
syntax is .
Parameter name must be alphabet and underscore only ([_0-9a-zA-Z]+), and matches only to alphabets, hyphen, and underscore ([-_0-9a-zA-Z]+).
Currently, only type of 'i' for integer is supported, i.e. .
method
Method name must be consisted of only alphabets. (method name cannot contain colon.)
To ignore the method in the match, use asterisk as the method value, like;
trailing route (*)
To match any remaining route, use *,
- for any path: , which just matches with any route.
- for matching trailing route: , which returns the matched route as , and remaining route as , if matched.
Router Class
Anything below are implemented to make this looks like a package.
Router class takes an array of patterns and its , and matches against a path. A method adds a pattern and one by one.
If matched, the router returns an array of the whatever the handler and matched parameter.
Handler can be anything. It just returns whatever it is set.
RouteCollection and Handler Class
use RouteCollection and Handler objects for creating patterns with ease.
Currently, the $router returns matched result as an array like any other. But it maybe easier to just return Handle object (if handle is the Handle object)...
Route Class
The method will return class if RouteCollection is used (i.e. Handler class is the $handler).
Handler and Route API list
The (RouteCollector) uses object to setup route information.
Handler has following methods.
Route class has following methods for reading matched information.
Grouping Routes
Use method to assigning same properties and/or matching pattern to a group of routes, as follows.
ReverseRoute
To-be-altered.
usage: