hoa / dispatcher
The Hoa\Dispatcher library.
Installs: 155 171
Dependents: 8
Suggesters: 1
Security: 0
Stars: 8
Watchers: 11
Forks: 8
Open Issues: 11
Requires
- hoa/consistency: ~1.0
- hoa/exception: ~1.0
- hoa/zformat: ~1.0
Requires (Dev)
- hoa/router: ~3.0
- hoa/test: ~2.0
- hoa/view: ~3.0
Suggests
- hoa/router: Provide routers.
- hoa/view: Provide view interface.
This package is auto-updated.
Last update: 2021-09-20 08:30:44 UTC
README
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
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.
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:
- On the
#hoaproject
IRC channel, - On the forum at users.hoa-project.net.
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.