PHPackages                             aura/dispatcher - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. aura/dispatcher

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

aura/dispatcher
===============

Creates objects from a factory and invokes methods using named parameters; also provides a trait for invoking closures and object methods with named parameters.

2.0.4(9y ago)3695.0k↓30.2%83BSD-2-ClausePHPPHP &gt;=5.4.0

Since Jan 6Pushed 9y ago13 watchersCompare

[ Source](https://github.com/auraphp/Aura.Dispatcher)[ Packagist](https://packagist.org/packages/aura/dispatcher)[ Docs](https://github.com/auraphp/Aura.Dispatcher)[ RSS](/packages/aura-dispatcher/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (6)DependenciesVersions (7)Used By (3)

Aura.Dispatcher
===============

[](#auradispatcher)

Provides tools to map arbitrary names to dispatchable objects, then to dispatch to those objects using named parameters. This is useful for invoking controller and command objects based on path-info parameters or command line arguments, for dispatching to closure-based controllers, and for building dispatchable objects from factories.

Foreword
--------

[](#foreword)

### Installation

[](#installation)

This library requires PHP 5.4 or later; we recommend using the latest available version of PHP as a matter of principle. It has no userland dependencies.

It is installable and autoloadable via Composer as [aura/dispatcher](https://packagist.org/packages/aura/dispatcher).

Alternatively, [download a release](https://github.com/auraphp/Aura.Dispatcher/releases) or clone this repository, then require or include its *autoload.php* file.

### Quality

[](#quality)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4717ddd79b69e45eaaa06d3d3089792ff6511d170f045cca3ba02dab4b2ac80c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f617572617068702f417572612e446973706174636865722f6261646765732f7175616c6974792d73636f72652e706e673f623d646576656c6f702d32)](https://scrutinizer-ci.com/g/auraphp/Aura.Dispatcher/)[![Code Coverage](https://camo.githubusercontent.com/5660471acab86d8da85e7e1ed00e07ed4f8f0b7e5ac89ca302787a75a189ef0e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f617572617068702f417572612e446973706174636865722f6261646765732f636f7665726167652e706e673f623d646576656c6f702d32)](https://scrutinizer-ci.com/g/auraphp/Aura.Dispatcher/)[![Build Status](https://camo.githubusercontent.com/b88e1fc219e3a67487b500fb8294918b3ef757853d00897f9315220f8ab0af81/68747470733a2f2f7472617669732d63692e6f72672f617572617068702f417572612e446973706174636865722e706e673f6272616e63683d646576656c6f702d32)](https://travis-ci.org/auraphp/Aura.Dispatcher)

To run the unit tests at the command line, issue `phpunit` at the package root. (This requires [PHPUnit](http://phpunit.de/manual/) to be available as `phpunit`.)

This library attempts to comply with [PSR-1](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md), [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md), and [PSR-4](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md). If you notice compliance oversights, please send a patch via pull request.

### Community

[](#community)

To ask questions, provide feedback, or otherwise communicate with the Aura community, please join our [Google Group](http://groups.google.com/group/auraphp), follow [@auraphp on Twitter](http://twitter.com/auraphp), or chat with us on #auraphp on Freenode.

Getting Started
---------------

[](#getting-started)

### Overview

[](#overview)

First, an external routing mechanism such as [Aura.Router](https://github.com/auraphp/Aura.Router) or a micro-framework router creates an array of parameters. (Alternatively, the parameters may be an object that implements [ArrayAccess](http://php.net/ArrayAccess)).

The parameters are then passed to the *Dispatcher*. It examines them and picks an object to invoke with those parameters, optionally with a method determined by the parameters.

The *Dispatcher* then examines the returned result from that first invocation. If the result is itself a dispatchable object, the *Dispatcher* will recursively dispatch the result until something other than a dispatchable object is returned.

When a non-dispatchable result is returned, the *Dispatcher* stops recursion and returns the non-dispatchable result.

### Closures and Invokable Objects

[](#closures-and-invokable-objects)

First, we tell the *Dispatcher* to examine the `controller` parameter to find the name of the object to dispatch to:

```
