You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ivan Enderlin 8f09a2ed67
3 years ago
Documentation Consistency: Use `Hoa\Consistency`. 4 years ago
Exception Quality: Happy new year! 3 years ago
Http Quality: Happy new year! 3 years ago
.State Add the state of the library. 6 years ago
.gitignore Add a `.gitignore` file. 5 years ago Prepare 3 years ago
Cli.php Quality: Happy new year! 3 years ago
Generic.php Quality: Happy new year! 3 years ago Documentation: Use TLS if possible. 3 years ago
Router.php Quality: Happy new year! 3 years ago
composer.json Documentation: Update `support` properties. 3 years ago


Build status Code coverage Packagist License

Hoa is a modular, extensible and structured set of PHP libraries.
Moreover, Hoa aims at being a bridge between industrial and research worlds.


Help on IRC Help on Gitter Documentation Board

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).

Learn more.


With Composer, to include this library into your dependencies, you need to require hoa/router:

$ composer require hoa/router '~3.0'

For more installation procedures, please read the Source page.


Before running the test suites, the development dependencies must be installed:

$ composer install

Then, to run all the test suites:

$ vendor/bin/hoa test:run

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.


We consider the following routes:

  • /hello, only accessible with the GET and POST method;
  • /bye, only accessible with the GET method;
  • /hello_<nick> only accessible with the GET method.

There are different ways to declare routes but the more usual is as follows:

$router = new Hoa\Router\Http();
    ->get('u', '/hello', function () {
        echo 'world!', "\n";
    ->post('v', '/hello', function (Array $_request) {
        echo $_request['a'] + $_request['b'], "\n";
    ->get('w', '/bye', function () {
        echo 'ohh :-(', "\n";
    ->get('x', '/hello_(?<nick>\w+)', function ($nick) {
        echo 'Welcome ', ucfirst($nick), '!', "\n";

We can use a basic dispatcher to call automatically the associated callable of the appropriated rule:

$dispatcher = new Hoa\Dispatcher\Basic();

Now, we will use cURL to test our program that listens on

$ curl
$ curl -X POST -d a=3\&b=39
$ curl
ohh :-(
$ curl -X POST
// error
$ curl
Welcome Gordon!
$ curl
Welcome Alyx!

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:

var_dump($router->unroute('x', array('nick' => 'gordon')));
// string(13) "/hello_gordon"


We would like to recognize the following route [<group>:]?<subcommand> <options> in the Router.php file:

$router = new Hoa\Router\Cli();
    function ($group, $subcommand, $options) {
            'Group     : ', $group, "\n",
            'Subcommand: ', $subcommand, "\n",
            'Options   : ', trim($options), "\n";

We can use a basic dispatcher to call automatically the associated callable:

$dispatcher = new Hoa\Dispatcher\Basic();

And now, testing time:

$ php Router.php foo:bar --some options
Group     : foo
Subcommand: bar
Options   : --some options

The use of the Hoa\Console library would be a good idea to interprete the options and getting some comfortable services for the terminal.


The hack book of Hoa\Router contains detailed information about how to use this library and how it works.

To generate the documentation locally, execute the following commands:

$ composer require --dev hoa/devtools
$ vendor/bin/hoa devtools:documentation --open

More documentation can be found on the project’s website:

Getting help

There are mainly two ways to get help:


Do you want to contribute? Thanks! A detailed contributor guide explains everything you need to know.


Hoa is under the New BSD License (BSD-3-Clause). Please, see LICENSE for details.