2017 © Pedro Peláez
 

library handlers-container

Psr-15 request handler proxying a Psr-11 container entry

image

ellipse/handlers-container

Psr-15 request handler proxying a Psr-11 container entry

  • Thursday, March 22, 2018
  • by pmall
  • Repository
  • 1 Watchers
  • 0 Stars
  • 42 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 17 % Grown

The README.md

Request handler container

This package provides a Psr-15 request handler proxying a Psr-11 container entry., (*1)

Require php >= 7.0, (*2)

Installation composer require ellipse/handlers-container, (*3)

Run tests ./vendor/bin/kahlan, (*4)

Using container entries as request handlers

The class Ellipse\Handlers\ContainerRequestHandler takes an implementation of Psr\Container\ContainerInterface and a container id as parameters. Its ->handle() method retrieve a request handler from the container using this id and proxy its ->handle() method., (*5)

It can be useful in situations the container entry should be resolved at the time the request is handled., (*6)

An Ellipse\Handlers\Exceptions\ContainedRequestHandlerTypeException is thrown when the value retrieved from the container is not an object implementing Psr\Http\Server\RequestHandlerInterface., (*7)

<?php

namespace App;

use SomePsr11Container;

use Ellipse\Handlers\ContainerRequestHandler;

// Get some Psr-11 container.
$container = new SomePsr11Container;

// Add a request handler in the container.
$container->set('some.request.handler', function () {

    return new SomeRequestHandler;

});

// Create a container request handler with the Psr-11 container and the entry id.
$handler = new ContainerRequestHandler($container, 'some.request.handler');

// The handler ->handle() method retrieve the request handler from the container and proxy it.
$response = $handler->handle($request);

Example using auto wiring

It can be cumbersome to register every request handler classes in the container. Here is how to auto wire request handler instances using the Ellipse\Container\ReflectionContainer class from the ellipse/container-reflection package., (*8)

<?php

namespace App;

use Psr\Http\Server\RequestHandlerInterface;

use SomePsr11Container;

use Ellipse\Container\ReflectionContainer;
use Ellipse\Handlers\ContainerRequestHandler;

// Get some Psr-11 container.
$container = new SomePsr11Container;

// Decorate the container with a reflection container.
// Specify the request handler implementations can be auto wired.
$reflection = new ReflectionContainer($container, [
    RequestHandlerInterface::class,
]);

// Create a container request handler with the reflection container and a request handler class name.
$handler = new ContainerRequestHandler($reflection, SomeRequestHandler::class);

// An instance of SomeRequestHandler is built and its ->handle() method is proxied.
$response = $handler->handle($request);

The Versions

22/03 2018

dev-master

9999999-dev https://github.com/ellipsephp/handlers-container

Psr-15 request handler proxying a Psr-11 container entry

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

psr-7 container request resolver factory psr-11 psr-15 request-handler

19/03 2018

1.0.3

1.0.3.0 https://github.com/ellipsephp/handlers-container

Psr-15 request handler proxying a Psr-11 container entry

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

container psr-11 psr-15 request-handler

18/03 2018

1.0.2

1.0.2.0 https://github.com/ellipsephp/handlers-container

Psr-15 request handler proxying a Psr-11 container entry

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

container psr-11 psr-15 request-handler

13/03 2018

1.0.1

1.0.1.0 https://github.com/ellipsephp/handlers-container

Psr-15 request handler proxying a Psr-11 container entry

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

container psr-11 psr-15 request-handler

13/03 2018

1.0.0

1.0.0.0 https://github.com/ellipsephp/handlers-container

Psr-15 handler proxying a Psr-11 container entry

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

container psr-11 psr-15 request-handler