PHPackages                             hoa/router - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. hoa/router

AbandonedArchivedLibrary[HTTP &amp; Networking](/categories/http)

hoa/router
==========

The Hoa\\Router library.

3.17.01.14(9y ago)28170.3k↓31.1%10[6 issues](https://github.com/hoaproject/Router/issues)11BSD-3-ClausePHP

Since Sep 16Pushed 9y ago9 watchersCompare

[ Source](https://github.com/hoaproject/Router)[ Packagist](https://packagist.org/packages/hoa/router)[ Docs](https://hoa-project.net/)[ RSS](/packages/hoa-router/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (14)Used By (11)

 [![Hoa](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)

---

 [![Build status](https://camo.githubusercontent.com/7cc9e2f3816f3b3db061e438e9c241c3f23bb18a2db374cb6ef066472fc1eedd/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f686f6170726f6a6563742f726f757465722f6d61737465722e737667)](https://travis-ci.org/hoaproject/router) [![Code coverage](https://camo.githubusercontent.com/8ce9928338fa3af6220a88b9b3f1f569f34a165ac09514fbe2831f312edccd03/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f686f6170726f6a6563742f726f757465722f6d61737465722e737667)](https://coveralls.io/github/hoaproject/router?branch=master) [![Packagist](https://camo.githubusercontent.com/74cda77fa6d389fd8190a83981e1cbd88d17997aa8160f9fa3816d745f8a902e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f686f612f726f757465722e737667)](https://packagist.org/packages/hoa/router) [![License](https://camo.githubusercontent.com/3220cb6706f80b6cb918f5fbb4e37c5f801ef5a8b309b60d8eedc4a8c2987e67/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f686f612f726f757465722e737667)](https://hoa-project.net/LICENSE)

 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
===========

[](#hoarouter)

[![Help on IRC](https://camo.githubusercontent.com/4dbc9c9d28c30cf1ab591f4bb8212fe4dbddc734145df532a9bb86b09878d4c6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d253233686f6170726f6a6563742d6666303036362e737667)](https://webchat.freenode.net/?channels=#hoaproject)[![Help on Gitter](https://camo.githubusercontent.com/8c4c85951788ff606b1268cb3dd946be05e3054795455d0a7b9250711bc2ac05/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d6769747465722d6666303036362e737667)](https://gitter.im/hoaproject/central)[![Documentation](https://camo.githubusercontent.com/7059ad5f1a363f9098686c59d432f01d7330aed9d4b6c8111d985fd64cfc6c60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63756d656e746174696f6e2d6861636b5f626f6f6b2d6666303036362e737667)](https://central.hoa-project.net/Documentation/Library/Router)[![Board](https://camo.githubusercontent.com/fd81654ba14b3aca3a713e1b471bc3fc3ba7b5bb3761ccffd6eea2e2ed1fa5ca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6f7267616e69736174696f6e2d626f6172642d6666303036362e737667)](https://waffle.io/hoaproject/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).

[Learn more](https://central.hoa-project.net/Documentation/Library/Router).

Installation
------------

[](#installation)

With [Composer](https://getcomposer.org/), to include this library into your dependencies, you need to require [`hoa/router`](https://packagist.org/packages/hoa/router):

```
$ composer require hoa/router '~3.0'
```

For more installation procedures, please read [the Source page](https://hoa-project.net/Source.html).

Testing
-------

[](#testing)

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](https://hoa-project.net/Literature/Contributor/Guide.html).

Quick usage
-----------

[](#quick-usage)

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

### HTTP

[](#http)

We consider the following routes:

- `/hello`, only accessible with the `GET` and `POST` method;
- `/bye`, only accessible with the `GET` method;
- `/hello_` 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();
$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_(?\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();
$dispatcher->dispatch($router);
```

Now, we will use [cURL](http://curl.haxx.se/) to test our program that listens on `127.0.0.1:8888`:

```
$ curl 127.0.0.1:8888/hello
world!
$ curl -X POST -d a=3\&b=39 127.0.0.1:8888/hello
42
$ curl 127.0.0.1:8888/bye
ohh :-(
$ curl -X POST 127.0.0.1:8888/bye
// error
$ curl 127.0.0.1:8888/hello_gordon
Welcome Gordon!
$ curl 127.0.0.1:8888/hello_alyx
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"
```

### CLI

[](#cli)

We would like to recognize the following route `[:]? ` in the `Router.php` file:

```
$router = new Hoa\Router\Cli();
$router->get(
    'g',
    '(?\w+):(?\w+)(?.*?)'
    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:

```
$dispatcher = new Hoa\Dispatcher\Basic();
$dispatcher->dispatch($router);
```

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](https://central.hoa-project.net/Resource/Library/Console) would be a good idea to interprete the options and getting some comfortable services for the terminal.

Documentation
-------------

[](#documentation)

The [hack book of `Hoa\Router`](https://central.hoa-project.net/Documentation/Library/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: [hoa-project.net](https://hoa-project.net/).

Getting help
------------

[](#getting-help)

There are mainly two ways to get help:

- On the [`#hoaproject`](https://webchat.freenode.net/?channels=#hoaproject)IRC channel,
- On the forum at [users.hoa-project.net](https://users.hoa-project.net).

Contribution
------------

[](#contribution)

Do you want to contribute? Thanks! A detailed [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html) explains everything you need to know.

License
-------

[](#license)

Hoa is under the New BSD License (BSD-3-Clause). Please, see [`LICENSE`](https://hoa-project.net/LICENSE) for details.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community31

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 92.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~70 days

Recently: every ~132 days

Total

13

Last Release

3411d ago

Major Versions

1.14.09.16 → 2.14.09.172014-09-17

2.15.10.21 → 3.16.01.112016-01-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/a410060743cec0e0d8654661b726a7a25f5888f18059d4c942a8fd9a8128f0da?d=identicon)[Hoa](/maintainers/Hoa)

---

Top Contributors

[![Hywan](https://avatars.githubusercontent.com/u/946104?v=4)](https://github.com/Hywan "Hywan (171 commits)")[![vonglasow](https://avatars.githubusercontent.com/u/1275202?v=4)](https://github.com/vonglasow "vonglasow (4 commits)")[![jubianchi](https://avatars.githubusercontent.com/u/327237?v=4)](https://github.com/jubianchi "jubianchi (2 commits)")[![CircleCode](https://avatars.githubusercontent.com/u/668738?v=4)](https://github.com/CircleCode "CircleCode (1 commits)")[![orthographic-pedant](https://avatars.githubusercontent.com/u/14522744?v=4)](https://github.com/orthographic-pedant "orthographic-pedant (1 commits)")[![osaris](https://avatars.githubusercontent.com/u/125797?v=4)](https://github.com/osaris "osaris (1 commits)")[![shulard](https://avatars.githubusercontent.com/u/482993?v=4)](https://github.com/shulard "shulard (1 commits)")[![stephpy](https://avatars.githubusercontent.com/u/232744?v=4)](https://github.com/stephpy "stephpy (1 commits)")[![Metalaka](https://avatars.githubusercontent.com/u/5406767?v=4)](https://github.com/Metalaka "Metalaka (1 commits)")[![K-Phoen](https://avatars.githubusercontent.com/u/66958?v=4)](https://github.com/K-Phoen "K-Phoen (1 commits)")[![lalop](https://avatars.githubusercontent.com/u/313117?v=4)](https://github.com/lalop "lalop (1 commits)")

---

Tags

hoalibraryphprouterhttpclirouterlibrary

### Embed Badge

![Health badge](/badges/hoa-router/health.svg)

```
[![Health](https://phpackages.com/badges/hoa-router/health.svg)](https://phpackages.com/packages/hoa-router)
```

###  Alternatives

[jbzoo/utils

Collection of PHP functions, mini classes and snippets for everyday developer's routine life.

8321.5M36](/packages/jbzoo-utils)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
