Download the PHP package hoa/router without Composer
On this page you can find all versions of the php package hoa/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package router
Hoa is a modular, extensible and
structured set of PHP libraries.
Moreover, Hoa aims at being a bridge between industrial and research worlds.
Hoa\Router
This library allows to find an appropriated route and extracts data from a request. Conversely, given a route and data, this library is able to build a request.
For now, we have two routers: HTTP (routes understand URI and subdomains) and CLI (routes understand a full command-line).
Installation
With Composer, to include this library into
your dependencies, you need to
require hoa/router
:
For more installation procedures, please read the Source page.
Testing
Before running the test suites, the development dependencies must be installed:
Then, to run all the test suites:
For more information, please read the contributor guide.
Quick usage
We propose a quick overview of two usages: in a HTTP context and in a CLI context.
HTTP
We consider the following routes:
/hello
, only accessible with theGET
andPOST
method;/bye
, only accessible with theGET
method;/hello_<nick>
only accessible with theGET
method.
There are different ways to declare routes but the more usual is as follows:
We can use a basic dispatcher to call automatically the associated callable of the appropriated rule:
Now, we will use cURL to test our program that listens
on 127.0.0.1:8888
:
This simple API hides a modular mechanism that can be foreseen by typing
print_r($router->getTheRule())
.
To unroute, i.e. make the opposite operation, we can do this:
CLI
We would like to recognize the following route `[