Download the PHP package ellipse/handlers-controller without Composer
On this page you can find all versions of the php package ellipse/handlers-controller. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ellipse/handlers-controller
More information about ellipse/handlers-controller
Files in ellipse/handlers-controller
Package handlers-controller
Short Description Psr-15 request handler proxying a class method using a Psr-11 container entry
License MIT
Homepage https://github.com/ellipsephp/handlers-controller
Informations about the package handlers-controller
Request handler controller
This package provides a Psr-15 request handler proxying a class method using a Psr-11 container.
Require php >= 7.0
Installation composer require ellipse/handlers-controller
Run tests ./vendor/bin/kahlan
- Using controllers as request handlers
- Example using auto wiring
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.
Example using auto wiring
It can be cumbersome to register every controller classes in the container. Here is how to auto wire controller instances using the Ellipse\Container\ReflectionContainer
class from the ellipse/container-reflection package.
All versions of handlers-controller with dependencies
psr/http-message Version ^1.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0
psr/container Version ^1.0
ellipse/container-overridden Version ^1.0
ellipse/resolvable-callable Version ^1.0
ellipse/type-errors Version ^1.0