All Projects → hoaproject → Router

hoaproject / Router

Licence: other
The Hoa\Router library.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to Router

organiser
An organic web framework for organized web servers.
Stars: ✭ 58 (+100%)
Mutual labels:  router
bs-director
[UNMAINTAINED] BuckleScript bindings to the Director router
Stars: ✭ 22 (-24.14%)
Mutual labels:  router
amber-router
A URL Routing shard.
Stars: ✭ 16 (-44.83%)
Mutual labels:  router
Computer-Networks
GBN and SR simulation, Distance Vector Algorithm Simulation
Stars: ✭ 21 (-27.59%)
Mutual labels:  router
router
Bidirectional Ring router. REST oriented. Rails inspired.
Stars: ✭ 78 (+168.97%)
Mutual labels:  router
YAWAC
Yet Another Wifi Auto Connect (YAWAC) is a shell script to connect to a dataset of wireless connection and free hotspot like FreeWifi. It's works on OpenWrt.
Stars: ✭ 22 (-24.14%)
Mutual labels:  router
use-router-machine
Router state-machine hook, powered by XState (DEPRECATED).
Stars: ✭ 11 (-62.07%)
Mutual labels:  router
shim
HTTP Handler shim for Go projects running on AWS Lambda
Stars: ✭ 64 (+120.69%)
Mutual labels:  router
boring-router
A type-safe MobX router with parallel routing support.
Stars: ✭ 74 (+155.17%)
Mutual labels:  router
ultra-router
Router for component-based web apps. Pair with React or <BYOF />.
Stars: ✭ 35 (+20.69%)
Mutual labels:  router
ruuter
A zero-dependency HTTP router
Stars: ✭ 57 (+96.55%)
Mutual labels:  router
STCRouter
基于标准URL的iOS路由系统,可实现业务模块组件化,控制器之间零耦合,可实现黑白名单控制,可进行native降级到hybrid。
Stars: ✭ 19 (-34.48%)
Mutual labels:  router
framework
Lite & fast micro PHP framework that is **easy to learn**.
Stars: ✭ 110 (+279.31%)
Mutual labels:  router
openwrt
OpenWrt Stable 1907 with lean's package
Stars: ✭ 55 (+89.66%)
Mutual labels:  router
Dns
The Hoa\Dns library.
Stars: ✭ 22 (-24.14%)
Mutual labels:  hoa
middle-router
Route urls on both client and server through middleware
Stars: ✭ 33 (+13.79%)
Mutual labels:  router
CRRouter
A simple and powerful router
Stars: ✭ 54 (+86.21%)
Mutual labels:  router
OpenBSDFirewall
Simple OpenBSD Home Firewall Config for ALIX Board
Stars: ✭ 41 (+41.38%)
Mutual labels:  router
retil
The React Utility Library
Stars: ✭ 46 (+58.62%)
Mutual labels:  router
UserDeviceTracker
快速定位一个IP或MAC在你的网络中的位置,是网络工程师提高工作效率的利器,也可以为CMDB提供基础网络数据。
Stars: ✭ 36 (+24.14%)
Mutual labels:  router

Hoa


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.

Hoa\Router

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.

Installation

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.

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.

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 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();
$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>\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 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

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

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

$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 would be a good idea to interprete the options and getting some comfortable services for the terminal.

Documentation

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: hoa-project.net.

Getting help

There are mainly two ways to get help:

Contribution

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

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].