PHPackages                             ellipse/handlers-controller - 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-controller

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

ellipse/handlers-controller
===========================

Psr-15 request handler proxying a class method using a Psr-11 container entry

1.0.2(8y ago)07111MITPHPPHP &gt;=7.0

Since Mar 13Pushed 8y ago1 watchersCompare

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

READMEChangelogDependencies (9)Versions (4)Used By (1)

Request handler controller
==========================

[](#request-handler-controller)

This package provides a [Psr-15](https://www.php-fig.org/psr/psr-15/) request handler proxying a class method using a [Psr-11](https://www.php-fig.org/psr/psr-11/) container.

**Require** php &gt;= 7.0

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

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

- [Using controllers as request handlers](#using-controllers-as-request-handlers)
- [Example using auto wiring](#example-using-auto-wiring)

Using controllers as request handlers
-------------------------------------

[](#using-controllers-as-request-handlers)

The class `Ellipse\Handlers\ControllerRequestHandler` takes an implementation of `Psr\Container\ContainerInterface`, a container id, a method name and an optional array of request attribute names as parameters. Its `->handle()` method retrieve an instance of the controller class from the container and call its method with the given name in order to return a response.

The controller method is executed by using the container to retrieve values for its type hinted parameters. Request attribute values matching the given request attribute names are used for the non-type hinted parameters, in the order they are listed.

Also when the controller method has a parameter type hinted as `Psr\Http\Message\ServerRequestInterface`, the actual Psr-7 request received by the request handler is used. It means when a middleware create a new request (since Psr-7 requests are immutable) the controller method receive this new request.

An `Ellipse\Handlers\Exceptions\ContainedControllerTypeException` is thrown when the controller retrieved from the container is not an object.

```
