cribz/router

A PHP5 url routing/mapping library.

v1.0.3 2013-06-26 23:05 UTC

This package is not auto-updated.

Last update: 2020-02-16 16:14:20 UTC


README

PHP 5 routing library.

This library can be used to define routes/uri's and assign a callback function that is executed when the route is hit.

This library works for both CLI(Command Line) and in web applications.

Examples

There is an example cli file in the examples directory (examples/cli.php). Try it by using the following command $php examples/cli.php /hello GET

API

Router::any(array $methods, string $uri, callback $function) Set a route for multiple HTTP request methods.

Router::delete(string $uri, callback $function) Set a route for a HTTP Delete request.

Router::exists(string $method, string $uri) Check if a route exists.

Router::get(string $uri, callback $function) Set a route for a HTTP Get request.

Router::head(string $uri, callback $function) Set a route for a HTTP Head request.

Router::options(string $uri, callback $function) Set a route for a HTTP Options request.

Router::middleware(string $when[before|after], callback $function) Add a before or after middleware function. These are run in the order added.

Router::post(string $uri, callback $function) Set a route for a HTTP Post request.

Router::put(string $uri, callback $function) Set a route for a HTTP Put request

Router::run() Run the routes. Wraps both runCli() & runHttp()

Router::runCli() Run routes from the Command Line.

Router::runHttp() Run routes from a HTTP request.

Test

To run the test run $phpunit

License

See LICENSE