hoa/dispatcher

This package is abandoned and no longer maintained. No replacement package was suggested.

The Hoa\Dispatcher library.

1.17.05.02 2017-05-02 12:27 UTC

README

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\Dispatcher

Help on IRC Help on Gitter Documentation Board

This library dispatches a task defined by some data on a callable, or with the appropriated vocabulary, on a controller and an action. It is often used in conjunction with the Hoa\Router library and the Hoa\View library.

The link between libraries and the application is represented by a kit which aggregates all important data, such as the dispatcher, the router, the view and data associated to the view.

Learn more.

Installation

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

$ composer require hoa/dispatcher '~1.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 the basic dispatcher represented by the class Hoa\Dispatcher\Basic which is able to dispatch a task on three kinds of callables:

  • lambda function (as a controller, no action);
  • function (as a controller, no action);
  • class and method (respectively as a controller and an action).

We will focus on the last kind with this following example:

$router = new Hoa\Router\Http();
$router->get('w', '/(?<controller>[^/]+)/(?<action>\w+)\.html');

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

By default, the controller will be Application\Controller\<Controller> and the action will be <Action>Action. Thus, for the request /Foo/Bar.html, we will call Application\Controller\Foo::BarAction.

It is possible to specify a different controller and action names if the request is asynchronous. By default, only the action name is different with the value <Action>ActionAsync.

With all kinds of callables, the basic dispatcher will distribute captured data (with the (?<name>…) PCRE syntax) on callable arguments where the name matches the argument name. For example, with a rule such as '/hello_(?<nick>\w+)', if the callable has an argument named $nick, it will receive the value gordon for the request /hello_gordon.

The kit is reachable through the $_this argument or $this variable if the controller is a class that extends Hoa\Dispatcher\Kit. The kit propose four elementary attributes, which are: router, dispatcher, view and data.

Documentation

The hack book of Hoa\Dispatcher 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.