PHPackages                             ellipse/handlers-adr - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. ellipse/handlers-adr

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

ellipse/handlers-adr
====================

Psr-15 request handler implementing the ADR pattern

0.2.0(7y ago)139MITPHPPHP &gt;=7.0

Since Mar 21Pushed 7y ago1 watchersCompare

[ Source](https://github.com/ellipsephp/handlers-adr)[ Packagist](https://packagist.org/packages/ellipse/handlers-adr)[ Docs](https://github.com/ellipsephp/handlers-adr)[ RSS](/packages/ellipse-handlers-adr/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (8)Versions (3)Used By (0)

Request handler ADR
===================

[](#request-handler-adr)

This package provides a [Psr-15](https://www.php-fig.org/psr/psr-15/) request handler implementing the [Action-Domain-Responder](https://github.com/pmjones/adr) pattern.

**Require** php &gt;= 7.0

**Installation** `composer require ellipse/handlers-adr`

**Run tests** `./vendor/bin/kahlan`

- [Request handler using ADR pattern](#request-handler-using-adr-pattern)
- [Usage with a Psr-11 container](#usage-with-a-psr-11-container)

Request handler using ADR pattern
---------------------------------

[](#request-handler-using-adr-pattern)

The [Action-Domain-Responder](https://github.com/pmjones/adr) (ADR) pattern is used to separate domain and presentation logic of an application. It can be summed up as having *Action* objects gluing together pairs of *Domain* and *Responder* objects in order to produce a response from an incoming request. An *Action* can therefore be considered as a Psr-15 request handler and the goal of this package is to provide an ADR implementation usable with any Psr-15 dispatching system.

The `Ellipse\Handlers\ActionRequestHandler` represents a generic *Action* implementing `Psr\Http\Server\RequestHandlerInterface`. Its first constructor parameter is a *Domain* object implementing `Ellipse\ADR\DomainInterface` and the second one is a *Responder* object implementing `Ellipse\Handler\ResponderInterface`. Here is what's going on when the `->handle()` method of an `ActionRequestHandler` instance is called with a Psr-7 request:

- An input array is extracted from the Psr-7 request
- A payload is produced by calling the `->payload()` method of the *Domain* with the input array
- A Psr-7 response is produced by calling the `->response()` method of the *Responder* with the Psr-7 request and the payload
- The Psr-7 response is returned

By default the input array is obtained by merging the request attributes, query parameters, parsed body parameters and uploaded files. They are merged in this order, meaning request attributes are overridden by query parameters having the same keys, which in turn are overridden by parsed body parameters, and finally by uploaded files. An *Action* specific request parsing logic can be specified by passing a callable as `ActionRequestHandler` third constructor parameter. This request parser callable is executed with the request as parameter and must return an array. An `Ellipse\Handlers\Exceptions\InputTypeException` is thrown when anything else than an array is returned.

`DomainInterface` defines a `->payload()` method taking an input array as parameter and returning an implementation of `Ellipse\ADR\PayloadInterface`.

`PayloadInterface` defines two methods: `->status()` returning the payload status as a string and `->data()` returning the payload data as an array. The `Ellipse\ADR\Payload` class can be used as a default implementation of `PayloadInterface`. It takes the status string and the data array as constructor parameters.

Finally, `ResponseInterface` defines a `->response()` method taking a request and an implementation of `PayloadInterface` as parameter and returning a response.

```
