Hoa central

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


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


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

```json { "require": { "hoa/router": "~2.0" } } ```

Please, read the website to get more informations about how to install.

Quick usage

We propose a quick overview of two usages: in a HTTP context and in a CLI context.


We consider the following routes:

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

```php $router = new Hoa(); $router ->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>+)', function ($nick) { echo 'Welcome ', ucfirst($nick), '!', "\n"; }); ```

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

```php $dispatcher = new Hoa(); $dispatcher->dispatch($router); ```

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

```sh $ curl world! $ curl -X POST -d a=3&b=39 42 $ 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:

```php 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:

```php $router = new Hoa(); $router->get( 'g', '(?<group>+):(?<subcommand>+)(?<options>.*?)' function ($group, $subcommand, $options) { echo 'Group : ', $group, "\n", 'Subcommand: ', $subcommand, "\n", 'Options : ', trim($options), "\n"; } ); ```

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

```php $dispatcher = new Hoa(); $dispatcher->dispatch($router); ```

And now, testing time:

```sh $ php Router.php foo:bar –some options Group : foo Subcommand: bar Options : –some options ```

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


Different documentations can be found on the website: http://hoa-project.net/.


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