Download the PHP package kenphp/router without Composer
On this page you can find all versions of the php package kenphp/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kenphp/router
More information about kenphp/router
Files in kenphp/router
Informations about the package router
Router 
A simple PHP Router for your web application. This library is part of KenPHP Project, but can be used independently.
Features
- Static Route Patterns
- Dynamic Route Patterns
- Named parameters
- Optional parameters
- Regex-based route patterns
- Subrouting
- Supports web application routing
- Before and After route middleware
- Custom handler when a route is not found
What it does ?
- Store route patterns, handlers, and middlewares information
- Resolve request to matching patterns
What it doesn't ?
- Parse route path from $_SERVER or any other means. You must provide the route path and method to
Router::resolve
method. - Execute middlewares and handlers. It only returns an array containing matched route handlers, middlewares, and parameters found in the request.
- Why isn't this library receives
Psr\Http\Message\RequestInterface
implementation and returnsPsr\Http\Message\ResponseInterface
?
This library aims to gives as much freedom as possible to the user. Not everyone are using PSR-7 implementation and we want to respect that.
Requirements
- PHP 7.0 or greater
Installation
The easiest way to install is using Composer
Methods
-
route($method, $route, $handler, $options = []) : void
Example :
-
get($route, $handler, $options = []) : void
Example :
-
head($route, $handler, $options = []) : void
Example :
-
post($route, $handler, $options = []) : void
Example :
-
put($route, $handler, $options = []) : void
Example :
-
delete($route, $handler, $options = []) : void
Example :
-
group($route, $fn, $options = []) : void
Example :
-
setNotFoundHandler(callable $handler) : void
Example :
-
resolve($requestRoute, $method) : null|array
This function would return an array containing the following keys :
handler
params
- Optional keys. This would be filled with any data from the
$options
parameter.
Example :
Examples
- Usage example for web application