Download the PHP package kambo/router without Composer
On this page you can find all versions of the php package kambo/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package router
Kambo PHP router
Just another PHP router with following highlights:
- Support of PSR-7 - HTTP message interfaces
- Two dispatchers with closure and controller/module support
- Can be used even without mod_rewrite
Install
Prefered way to install library is with composer:
Usage
URL rewrite
For rewrite support in Apache with enabled mod_rewrite create a .htaccess file in your root directory, with following settings:
For disabling support of mod_rewrite use method setUrlFormat:
Route definition
The routes are added by calling createRoute()
on the RouteCollection instance:
The $method
is HTTP method name represented by value from Kambo\Router\Enum\Method enum for which a certain route should match, eg.: Method::GET
By default the $routePattern
uses a syntax where {foo}
specifies a placeholder with name foo
and matching the regex [^/]+
. To adjust the pattern the placeholder matches, you can specify
a custom pattern by writing {bar:[0-9]+}
. Some examples:
A shortcut methods can be also used for all Method:
A closure as $handler
can be used:
PSR-7 - HTTP message interfaces
Kambo router is using a instance of PSR 7 compatible request object for abstraction over server variables. Any third party library that implements PSR-7 can be used, such as Kambo/HttpMessage
Router dispatcher
Router comes with following dispatcher:
- Closure dispatcher with automatic path <=> closure variable bind function.
- Opinionated class dispatcher which force you organize your code into module/controller class structure.
Using closure dispatcher
This example will define two routes:
http://{domain}/user/{string}/transaction/{integer number} http://{domain}/article/{integer number}
License
The MIT License (MIT), https://opensource.org/licenses/MIT